Pārlūkot izejas kodu

feat: use sa-token

张延森 3 gadus atpakaļ
vecāks
revīzija
84f65b53a6
41 mainītis faili ar 160 papildinājumiem un 676 dzēšanām
  1. 8
    10
      pom.xml
  2. 2
    13
      src/main/java/com/yunzhi/nanyang/common/BaseController.java
  3. 44
    0
      src/main/java/com/yunzhi/nanyang/config/SaTokenConfigure.java
  4. 4
    9
      src/main/java/com/yunzhi/nanyang/controller/LoginController.java
  5. 3
    5
      src/main/java/com/yunzhi/nanyang/controller/MobileController.java
  6. 1
    1
      src/main/java/com/yunzhi/nanyang/controller/SysMenuController.java
  7. 5
    5
      src/main/java/com/yunzhi/nanyang/controller/SysRoleController.java
  8. 3
    7
      src/main/java/com/yunzhi/nanyang/controller/SysRolePermissionController.java
  9. 2
    2
      src/main/java/com/yunzhi/nanyang/controller/SysSettingController.java
  10. 6
    6
      src/main/java/com/yunzhi/nanyang/controller/SysUserController.java
  11. 3
    3
      src/main/java/com/yunzhi/nanyang/controller/SysUserRoleController.java
  12. 2
    2
      src/main/java/com/yunzhi/nanyang/controller/TaAccountLogController.java
  13. 4
    4
      src/main/java/com/yunzhi/nanyang/controller/TaBannerController.java
  14. 3
    3
      src/main/java/com/yunzhi/nanyang/controller/TaDispatchController.java
  15. 2
    2
      src/main/java/com/yunzhi/nanyang/controller/TaFeedbackController.java
  16. 4
    4
      src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java
  17. 4
    4
      src/main/java/com/yunzhi/nanyang/controller/TaNewsController.java
  18. 4
    4
      src/main/java/com/yunzhi/nanyang/controller/TaNewsTypeController.java
  19. 6
    6
      src/main/java/com/yunzhi/nanyang/controller/TaOrgController.java
  20. 4
    5
      src/main/java/com/yunzhi/nanyang/controller/TaPersonController.java
  21. 6
    6
      src/main/java/com/yunzhi/nanyang/controller/TaRegionController.java
  22. 2
    2
      src/main/java/com/yunzhi/nanyang/controller/TaUserMachineryController.java
  23. 4
    4
      src/main/java/com/yunzhi/nanyang/controller/TdMachineryTypeController.java
  24. 3
    5
      src/main/java/com/yunzhi/nanyang/controller/WxMaController.java
  25. 2
    2
      src/main/java/com/yunzhi/nanyang/exception/GlobalExceptionHandler.java
  26. 2
    2
      src/main/java/com/yunzhi/nanyang/mapper/SysRoleMapper.java
  27. 1
    2
      src/main/java/com/yunzhi/nanyang/mapper/SysRolePermissionMapper.java
  28. 1
    2
      src/main/java/com/yunzhi/nanyang/mapper/SysUserRoleMapper.java
  29. 7
    16
      src/main/java/com/yunzhi/nanyang/service/impl/ManagerServiceImpl.java
  30. 0
    106
      src/main/java/com/yunzhi/nanyang/shiro/ShiroConfig.java
  31. 0
    84
      src/main/java/com/yunzhi/nanyang/shiro/filters/JWTFilter.java
  32. 0
    29
      src/main/java/com/yunzhi/nanyang/shiro/filters/ManagerFilter.java
  33. 0
    24
      src/main/java/com/yunzhi/nanyang/shiro/filters/MiniappFilter.java
  34. 0
    16
      src/main/java/com/yunzhi/nanyang/shiro/matcher/JWTCredentialsMatcher.java
  35. 0
    31
      src/main/java/com/yunzhi/nanyang/shiro/realms/manager/IManagerService.java
  36. 0
    77
      src/main/java/com/yunzhi/nanyang/shiro/realms/manager/ManagerRealm.java
  37. 0
    44
      src/main/java/com/yunzhi/nanyang/shiro/realms/miniapp/MiniappRealm.java
  38. 0
    23
      src/main/java/com/yunzhi/nanyang/shiro/utils/JWTToken.java
  39. 0
    66
      src/main/java/com/yunzhi/nanyang/shiro/utils/JWTUtil.java
  40. 0
    23
      src/main/java/com/yunzhi/nanyang/shiro/utils/MiniappToken.java
  41. 18
    17
      src/main/resources/application.yml

+ 8
- 10
pom.xml Parādīt failu

122
 		<!--swagger end-->
122
 		<!--swagger end-->
123
 
123
 
124
 
124
 
125
-		<!-- shiro start-->
125
+		<!-- Sa-Token 权限认证, 在线文档:http://sa-token.dev33.cn/ -->
126
 		<dependency>
126
 		<dependency>
127
-			<groupId>org.apache.shiro</groupId>
128
-			<artifactId>shiro-spring-boot-web-starter</artifactId>
129
-			<version>1.8.0</version>
127
+			<groupId>cn.dev33</groupId>
128
+			<artifactId>sa-token-spring-boot-starter</artifactId>
129
+			<version>1.29.0</version>
130
 		</dependency>
130
 		</dependency>
131
-		<!-- shiro end-->
132
 
131
 
133
-		<!-- jwt start -->
132
+		<!-- Sa-Token 整合 jwt -->
134
 		<dependency>
133
 		<dependency>
135
-			<groupId>com.auth0</groupId>
136
-			<artifactId>java-jwt</artifactId>
137
-			<version>3.18.3</version>
134
+			<groupId>cn.dev33</groupId>
135
+			<artifactId>sa-token-jwt</artifactId>
136
+			<version>1.29.0</version>
138
 		</dependency>
137
 		</dependency>
139
-		<!-- end start -->
140
 	</dependencies>
138
 	</dependencies>
141
 
139
 
142
 	<profiles>
140
 	<profiles>

+ 2
- 13
src/main/java/com/yunzhi/nanyang/common/BaseController.java Parādīt failu

1
 package com.yunzhi.nanyang.common;
1
 package com.yunzhi.nanyang.common;
2
 
2
 
3
+import cn.dev33.satoken.stp.StpUtil;
3
 import com.yunzhi.nanyang.entity.SysUser;
4
 import com.yunzhi.nanyang.entity.SysUser;
4
 import com.yunzhi.nanyang.entity.TaPerson;
5
 import com.yunzhi.nanyang.entity.TaPerson;
5
 import com.yunzhi.nanyang.service.ISysUserDataScopeService;
6
 import com.yunzhi.nanyang.service.ISysUserDataScopeService;
6
 import com.yunzhi.nanyang.service.ISysUserService;
7
 import com.yunzhi.nanyang.service.ISysUserService;
7
 import com.yunzhi.nanyang.service.ITaPersonService;
8
 import com.yunzhi.nanyang.service.ITaPersonService;
8
-import com.yunzhi.nanyang.shiro.realms.manager.ManagerRealm;
9
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
10
-import org.apache.shiro.SecurityUtils;
11
-import org.apache.shiro.subject.Subject;
12
 import org.springframework.beans.factory.annotation.Autowired;
9
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.stereotype.Component;
10
 import org.springframework.stereotype.Component;
14
 
11
 
15
-import java.util.Arrays;
16
-import java.util.Collection;
17
 import java.util.List;
12
 import java.util.List;
18
 
13
 
19
 @Component
14
 @Component
29
     ISysUserDataScopeService iSysUserDataScopeService;
24
     ISysUserDataScopeService iSysUserDataScopeService;
30
 
25
 
31
     public String getLoginId() {
26
     public String getLoginId() {
32
-        Subject subject = SecurityUtils.getSubject();
33
-        String token = subject.getPrincipal().toString();
34
-
35
-//        List<Object> list = Arrays.asList(subject.getPrincipals().fromRealm("managerRealm").toArray());
36
-//        String token = list.get(0).toString();
37
-
38
-        return JWTUtil.getLoginId(token);
27
+        return StpUtil.getLoginIdAsString();
39
     }
28
     }
40
 
29
 
41
     public SysUser currentUser() throws Exception {
30
     public SysUser currentUser() throws Exception {

+ 44
- 0
src/main/java/com/yunzhi/nanyang/config/SaTokenConfigure.java Parādīt failu

1
+package com.yunzhi.nanyang.config;
2
+
3
+import cn.dev33.satoken.interceptor.SaRouteInterceptor;
4
+import cn.dev33.satoken.jwt.StpLogicJwtForStateless;
5
+import cn.dev33.satoken.stp.StpLogic;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.Configuration;
8
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
9
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10
+
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+
14
+@Configuration
15
+public class SaTokenConfigure implements WebMvcConfigurer {
16
+    // 注册拦截器
17
+    @Override
18
+    public void addInterceptors(InterceptorRegistry registry) {
19
+
20
+        List<String> anonList = new ArrayList<>();
21
+        anonList.add("/swagger-ui/**");
22
+        anonList.add("/swagger-resources/**");
23
+        anonList.add("/v2/**");
24
+        anonList.add("/wxpay/notify/**");
25
+        anonList.add("/**/sms-captcha");
26
+        anonList.add("/**/**/sms-captcha");
27
+        anonList.add("/**/preload");
28
+        anonList.add("/**/login");
29
+        anonList.add("/**/**/login");
30
+
31
+        // 注册Sa-Token的路由拦截器
32
+        registry.addInterceptor(new SaRouteInterceptor())
33
+                .addPathPatterns("/**")
34
+                .excludePathPatterns(anonList.toArray(new String[0]));
35
+    }
36
+
37
+
38
+
39
+    // Sa-Token 整合 jwt (Style模式)
40
+    @Bean
41
+    public StpLogic getStpLogicJwt() {
42
+        return new StpLogicJwtForStateless();
43
+    }
44
+}

+ 4
- 9
src/main/java/com/yunzhi/nanyang/controller/LoginController.java Parādīt failu

1
 package com.yunzhi.nanyang.controller;
1
 package com.yunzhi.nanyang.controller;
2
 
2
 
3
+import cn.dev33.satoken.stp.StpUtil;
3
 import com.yunzhi.nanyang.common.*;
4
 import com.yunzhi.nanyang.common.*;
4
 import com.yunzhi.nanyang.entity.SysLogin;
5
 import com.yunzhi.nanyang.entity.SysLogin;
5
 import com.yunzhi.nanyang.entity.SysUser;
6
 import com.yunzhi.nanyang.entity.SysUser;
6
 import com.yunzhi.nanyang.service.ISysLoginService;
7
 import com.yunzhi.nanyang.service.ISysLoginService;
7
 import com.yunzhi.nanyang.service.ISysUserService;
8
 import com.yunzhi.nanyang.service.ISysUserService;
8
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
9
 import com.yunzhi.nanyang.vo.LoginParam;
9
 import com.yunzhi.nanyang.vo.LoginParam;
10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
12
 import io.swagger.annotations.ApiParam;
13
-import org.apache.shiro.SecurityUtils;
14
-import org.apache.shiro.subject.Subject;
15
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.web.bind.annotation.*;
14
 import org.springframework.web.bind.annotation.*;
17
 
15
 
18
-import java.util.HashMap;
19
 import java.util.Map;
16
 import java.util.Map;
20
 
17
 
21
 
18
 
64
 
61
 
65
         Map<String, Object> res = iSysUserService.getUerProfile(sysUser.getUserId(), sysUser);
62
         Map<String, Object> res = iSysUserService.getUerProfile(sysUser.getUserId(), sysUser);
66
 
63
 
67
-        // 生成 token
68
-        String token = JWTUtil.sign(sysLogin.getLoginId().toString(), sysLogin.getPassword());
69
-        res.put("token", token);
64
+        StpUtil.login(sysLogin.getLoginId(), "admin");
65
+        res.put("token", StpUtil.getTokenValue());
70
 
66
 
71
         return ResponseBean.success(res);
67
         return ResponseBean.success(res);
72
     }
68
     }
83
     @PostMapping("/admin/logout")
79
     @PostMapping("/admin/logout")
84
     @ApiOperation(value="登出", notes = "登出", httpMethod = "POST", response = ResponseBean.class)
80
     @ApiOperation(value="登出", notes = "登出", httpMethod = "POST", response = ResponseBean.class)
85
     public ResponseBean logout() throws Exception {
81
     public ResponseBean logout() throws Exception {
86
-        Subject subject = SecurityUtils.getSubject();
87
-        subject.logout();
82
+        StpUtil.logout();
88
         return ResponseBean.success("success");
83
         return ResponseBean.success("success");
89
     }
84
     }
90
 
85
 

+ 3
- 5
src/main/java/com/yunzhi/nanyang/controller/MobileController.java Parādīt failu

1
 package com.yunzhi.nanyang.controller;
1
 package com.yunzhi.nanyang.controller;
2
 
2
 
3
+import cn.dev33.satoken.stp.StpUtil;
3
 import com.yunzhi.nanyang.common.*;
4
 import com.yunzhi.nanyang.common.*;
4
 import com.yunzhi.nanyang.entity.SysUser;
5
 import com.yunzhi.nanyang.entity.SysUser;
5
 import com.yunzhi.nanyang.entity.TaPerson;
6
 import com.yunzhi.nanyang.entity.TaPerson;
6
 import com.yunzhi.nanyang.service.ISysUserService;
7
 import com.yunzhi.nanyang.service.ISysUserService;
7
 import com.yunzhi.nanyang.service.ITaPersonService;
8
 import com.yunzhi.nanyang.service.ITaPersonService;
8
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
9
 import com.yunzhi.nanyang.vo.LoginParam;
9
 import com.yunzhi.nanyang.vo.LoginParam;
10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
75
             iTaPersonService.tryBindUser(taPerson);
75
             iTaPersonService.tryBindUser(taPerson);
76
         }
76
         }
77
 
77
 
78
-        // 生成 token
79
-        String token = JWTUtil.sign(taPerson.getPersonId(), taPerson.getPersonId());
80
-
78
+        StpUtil.login(taPerson.getPersonId(), clientId);
81
         Map<String, Object> res = new HashMap<>();
79
         Map<String, Object> res = new HashMap<>();
82
         res.put("person", taPerson);
80
         res.put("person", taPerson);
83
-        res.put("token", token);
81
+        res.put("token", StpUtil.getTokenValue());
84
 
82
 
85
         return ResponseBean.success(res);
83
         return ResponseBean.success(res);
86
     }
84
     }

+ 1
- 1
src/main/java/com/yunzhi/nanyang/controller/SysMenuController.java Parādīt failu

10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
12
 import io.swagger.annotations.ApiParam;
13
-import org.apache.shiro.authz.annotation.RequiresPermissions;
13
+import cn.dev33.satoken.annotation.SaCheckPermission;
14
 import org.slf4j.Logger;
14
 import org.slf4j.Logger;
15
 import org.slf4j.LoggerFactory;
15
 import org.slf4j.LoggerFactory;
16
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;

+ 5
- 5
src/main/java/com/yunzhi/nanyang/controller/SysRoleController.java Parādīt failu

11
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
14
-import org.apache.shiro.authz.annotation.RequiresPermissions;
14
+import cn.dev33.satoken.annotation.SaCheckPermission;
15
 import org.slf4j.Logger;
15
 import org.slf4j.Logger;
16
 import org.slf4j.LoggerFactory;
16
 import org.slf4j.LoggerFactory;
17
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
79
      */
79
      */
80
     @RequestMapping(value="/admin/role",method= RequestMethod.POST)
80
     @RequestMapping(value="/admin/role",method= RequestMethod.POST)
81
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
81
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
82
-    @RequiresPermissions("role:add")
82
+    @SaCheckPermission("role:add")
83
     public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
83
     public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
84
         sysRole.setRoleId(null);
84
         sysRole.setRoleId(null);
85
 
85
 
105
      */
105
      */
106
     @RequestMapping(value="/admin/role/{id}", method= RequestMethod.DELETE)
106
     @RequestMapping(value="/admin/role/{id}", method= RequestMethod.DELETE)
107
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
107
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
108
-    @RequiresPermissions("role:delete")
108
+    @SaCheckPermission("role:delete")
109
     public ResponseBean sysRoleDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
109
     public ResponseBean sysRoleDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
110
 
110
 
111
         int cnt = iSysUserRoleService.countBy("role_id", id, false);
111
         int cnt = iSysUserRoleService.countBy("role_id", id, false);
131
      */
131
      */
132
     @RequestMapping(value="/admin/role/{id}",method= RequestMethod.PUT)
132
     @RequestMapping(value="/admin/role/{id}",method= RequestMethod.PUT)
133
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
133
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
134
-    @RequiresPermissions("role:update")
134
+    @SaCheckPermission("role:update")
135
     public ResponseBean sysRoleUpdate(@ApiParam("对象ID") @PathVariable String id,
135
     public ResponseBean sysRoleUpdate(@ApiParam("对象ID") @PathVariable String id,
136
                                         @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
136
                                         @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
137
 
137
 
159
      */
159
      */
160
     @RequestMapping(value="/admin/role/{id}",method= RequestMethod.GET)
160
     @RequestMapping(value="/admin/role/{id}",method= RequestMethod.GET)
161
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
161
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
162
-    @RequiresPermissions("role:view")
162
+    @SaCheckPermission("role:view")
163
     public ResponseBean sysRoleGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
163
     public ResponseBean sysRoleGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
164
         return ResponseBean.success(iSysRoleService.getById(id));
164
         return ResponseBean.success(iSysRoleService.getById(id));
165
     }
165
     }

+ 3
- 7
src/main/java/com/yunzhi/nanyang/controller/SysRolePermissionController.java Parādīt failu

1
 package com.yunzhi.nanyang.controller;
1
 package com.yunzhi.nanyang.controller;
2
 
2
 
3
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
-import com.baomidou.mybatisplus.core.metadata.IPage;
5
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3
+import cn.dev33.satoken.annotation.SaCheckPermission;
6
 import com.yunzhi.nanyang.common.BaseController;
4
 import com.yunzhi.nanyang.common.BaseController;
7
 import com.yunzhi.nanyang.common.Constants;
5
 import com.yunzhi.nanyang.common.Constants;
8
 import com.yunzhi.nanyang.common.ResponseBean;
6
 import com.yunzhi.nanyang.common.ResponseBean;
10
 import io.swagger.annotations.Api;
8
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
9
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
10
 import io.swagger.annotations.ApiParam;
13
-import org.apache.shiro.authz.annotation.RequiresPermissions;
14
 import org.slf4j.Logger;
11
 import org.slf4j.Logger;
15
 import org.slf4j.LoggerFactory;
12
 import org.slf4j.LoggerFactory;
16
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.beans.factory.annotation.Autowired;
23
 import com.yunzhi.nanyang.entity.SysRolePermission;
20
 import com.yunzhi.nanyang.entity.SysRolePermission;
24
 import org.springframework.web.bind.annotation.RestController;
21
 import org.springframework.web.bind.annotation.RestController;
25
 
22
 
26
-import java.util.Collection;
27
 import java.util.HashMap;
23
 import java.util.HashMap;
28
 import java.util.List;
24
 import java.util.List;
29
 import java.util.Map;
25
 import java.util.Map;
71
      */
67
      */
72
     @RequestMapping(value="/admin/role/{roleId}/permission",method= RequestMethod.POST)
68
     @RequestMapping(value="/admin/role/{roleId}/permission",method= RequestMethod.POST)
73
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
74
-    @RequiresPermissions("role:add")
70
+    @SaCheckPermission("role:add")
75
     public ResponseBean sysRolePermissionAdd(@ApiParam("角色ID") @PathVariable String roleId,
71
     public ResponseBean sysRolePermissionAdd(@ApiParam("角色ID") @PathVariable String roleId,
76
                                              @ApiParam("保存内容") @RequestBody List<SysRolePermission> sysRolePermissionList) throws Exception{
72
                                              @ApiParam("保存内容") @RequestBody List<SysRolePermission> sysRolePermissionList) throws Exception{
77
 
73
 
110
      */
106
      */
111
     @RequestMapping(value="/admin/role-permission/{id}", method= RequestMethod.DELETE)
107
     @RequestMapping(value="/admin/role-permission/{id}", method= RequestMethod.DELETE)
112
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
108
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
113
-    @RequiresPermissions("role:delete")
109
+    @SaCheckPermission("role:delete")
114
     public ResponseBean sysRolePermissionDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
110
     public ResponseBean sysRolePermissionDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
115
 
111
 
116
         SysRolePermission rolePermission = iSysRolePermissionService.getById(id);
112
         SysRolePermission rolePermission = iSysRolePermissionService.getById(id);

+ 2
- 2
src/main/java/com/yunzhi/nanyang/controller/SysSettingController.java Parādīt failu

9
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
10
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiParam;
11
 import io.swagger.annotations.ApiParam;
12
-import org.apache.shiro.authz.annotation.RequiresPermissions;
12
+import cn.dev33.satoken.annotation.SaCheckPermission;
13
 import org.slf4j.Logger;
13
 import org.slf4j.Logger;
14
 import org.slf4j.LoggerFactory;
14
 import org.slf4j.LoggerFactory;
15
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.beans.factory.annotation.Autowired;
71
      */
71
      */
72
     @RequestMapping(value="/admin/setting/{id}",method= RequestMethod.PUT)
72
     @RequestMapping(value="/admin/setting/{id}",method= RequestMethod.PUT)
73
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
73
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
74
-    @RequiresPermissions("setting:update")
74
+    @SaCheckPermission("setting:update")
75
     public ResponseBean sysSettingUpdate(@ApiParam("对象ID") @PathVariable String id,
75
     public ResponseBean sysSettingUpdate(@ApiParam("对象ID") @PathVariable String id,
76
                                         @ApiParam("更新内容") @RequestBody SysSetting sysSetting) throws Exception{
76
                                         @ApiParam("更新内容") @RequestBody SysSetting sysSetting) throws Exception{
77
 
77
 

+ 6
- 6
src/main/java/com/yunzhi/nanyang/controller/SysUserController.java Parādīt failu

10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
12
 import io.swagger.annotations.ApiParam;
13
-import org.apache.shiro.authz.annotation.RequiresPermissions;
13
+import cn.dev33.satoken.annotation.SaCheckPermission;
14
 import org.slf4j.Logger;
14
 import org.slf4j.Logger;
15
 import org.slf4j.LoggerFactory;
15
 import org.slf4j.LoggerFactory;
16
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;
88
      */
88
      */
89
     @RequestMapping(value="/admin/user",method= RequestMethod.POST)
89
     @RequestMapping(value="/admin/user",method= RequestMethod.POST)
90
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
90
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
91
-    @RequiresPermissions("user:add")
91
+    @SaCheckPermission("user:add")
92
     public ResponseBean sysUserAdd(@ApiParam("保存内容") @RequestBody SysUser sysUser) throws Exception{
92
     public ResponseBean sysUserAdd(@ApiParam("保存内容") @RequestBody SysUser sysUser) throws Exception{
93
         String userId = currentUser().getUserId();
93
         String userId = currentUser().getUserId();
94
         sysUser.setUserId(null);
94
         sysUser.setUserId(null);
135
      */
135
      */
136
     @RequestMapping(value="/admin/user/{id}", method= RequestMethod.DELETE)
136
     @RequestMapping(value="/admin/user/{id}", method= RequestMethod.DELETE)
137
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
137
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
138
-    @RequiresPermissions("user:delete")
138
+    @SaCheckPermission("user:delete")
139
     public ResponseBean sysUserDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
139
     public ResponseBean sysUserDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
140
         SysUser sysUser = iSysUserService.getExistBy("user_id", id, false, true);
140
         SysUser sysUser = iSysUserService.getExistBy("user_id", id, false, true);
141
         if (sysUser == null) {
141
         if (sysUser == null) {
164
      */
164
      */
165
     @RequestMapping(value="/admin/user/{id}",method= RequestMethod.PUT)
165
     @RequestMapping(value="/admin/user/{id}",method= RequestMethod.PUT)
166
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
166
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
167
-    @RequiresPermissions("user:update")
167
+    @SaCheckPermission("user:update")
168
     public ResponseBean sysUserUpdate(@ApiParam("对象ID") @PathVariable String id,
168
     public ResponseBean sysUserUpdate(@ApiParam("对象ID") @PathVariable String id,
169
                                         @ApiParam("更新内容") @RequestBody SysUser sysUser) throws Exception{
169
                                         @ApiParam("更新内容") @RequestBody SysUser sysUser) throws Exception{
170
         String userId = currentUser().getUserId();
170
         String userId = currentUser().getUserId();
233
      */
233
      */
234
     @RequestMapping(value="/admin/user/{id}",method= RequestMethod.GET)
234
     @RequestMapping(value="/admin/user/{id}",method= RequestMethod.GET)
235
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
235
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
236
-    @RequiresPermissions("user:view")
236
+    @SaCheckPermission("user:view")
237
     public ResponseBean sysUserGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
237
     public ResponseBean sysUserGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
238
         SysUser sysUser = iSysUserService.getExistBy("user_id", id, false, true);
238
         SysUser sysUser = iSysUserService.getExistBy("user_id", id, false, true);
239
 
239
 
255
      */
255
      */
256
     @RequestMapping(value="/admin/user/default/password",method= RequestMethod.GET)
256
     @RequestMapping(value="/admin/user/default/password",method= RequestMethod.GET)
257
     @ApiOperation(value="查询用户默认密码", notes = "查询用户默认密码", httpMethod = "GET", response = ResponseBean.class)
257
     @ApiOperation(value="查询用户默认密码", notes = "查询用户默认密码", httpMethod = "GET", response = ResponseBean.class)
258
-    @RequiresPermissions("user:view")
258
+    @SaCheckPermission("user:view")
259
     public ResponseBean getDefaultPassword() throws Exception{
259
     public ResponseBean getDefaultPassword() throws Exception{
260
         return ResponseBean.success(defaultPassword);
260
         return ResponseBean.success(defaultPassword);
261
     }
261
     }

+ 3
- 3
src/main/java/com/yunzhi/nanyang/controller/SysUserRoleController.java Parādīt failu

14
 import io.swagger.annotations.Api;
14
 import io.swagger.annotations.Api;
15
 import io.swagger.annotations.ApiOperation;
15
 import io.swagger.annotations.ApiOperation;
16
 import io.swagger.annotations.ApiParam;
16
 import io.swagger.annotations.ApiParam;
17
-import org.apache.shiro.authz.annotation.RequiresPermissions;
17
+import cn.dev33.satoken.annotation.SaCheckPermission;
18
 import org.slf4j.Logger;
18
 import org.slf4j.Logger;
19
 import org.slf4j.LoggerFactory;
19
 import org.slf4j.LoggerFactory;
20
 import org.springframework.beans.factory.annotation.Autowired;
20
 import org.springframework.beans.factory.annotation.Autowired;
75
      */
75
      */
76
     @RequestMapping(value="/admin/user/{userId}/role",method= RequestMethod.POST)
76
     @RequestMapping(value="/admin/user/{userId}/role",method= RequestMethod.POST)
77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
78
-    @RequiresPermissions("user:add")
78
+    @SaCheckPermission("user:add")
79
     public ResponseBean sysUserRoleAdd(@ApiParam("用户ID") @PathVariable String userId,
79
     public ResponseBean sysUserRoleAdd(@ApiParam("用户ID") @PathVariable String userId,
80
                                        @ApiParam("保存内容") @RequestBody List<SysUserRole> sysUserRoleList) throws Exception{
80
                                        @ApiParam("保存内容") @RequestBody List<SysUserRole> sysUserRoleList) throws Exception{
81
         // 不能编辑管理员权限
81
         // 不能编辑管理员权限
133
      */
133
      */
134
     @RequestMapping(value="/admin/user/{userId}/role", method= RequestMethod.DELETE)
134
     @RequestMapping(value="/admin/user/{userId}/role", method= RequestMethod.DELETE)
135
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
135
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
136
-    @RequiresPermissions("user:delete")
136
+    @SaCheckPermission("user:delete")
137
     public ResponseBean sysUserRoleDelete(@ApiParam("对象ID") @PathVariable String userId) throws Exception{
137
     public ResponseBean sysUserRoleDelete(@ApiParam("对象ID") @PathVariable String userId) throws Exception{
138
         // 不能编辑管理员权限
138
         // 不能编辑管理员权限
139
         if (Constants.ADMIN_ID.equals(userId)) {
139
         if (Constants.ADMIN_ID.equals(userId)) {

+ 2
- 2
src/main/java/com/yunzhi/nanyang/controller/TaAccountLogController.java Parādīt failu

12
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiParam;
14
 import io.swagger.annotations.ApiParam;
15
-import org.apache.shiro.authz.annotation.RequiresPermissions;
15
+import cn.dev33.satoken.annotation.SaCheckPermission;
16
 import org.slf4j.Logger;
16
 import org.slf4j.Logger;
17
 import org.slf4j.LoggerFactory;
17
 import org.slf4j.LoggerFactory;
18
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.beans.factory.annotation.Autowired;
57
      */
57
      */
58
     @RequestMapping(value="/admin/account-log",method= RequestMethod.GET)
58
     @RequestMapping(value="/admin/account-log",method= RequestMethod.GET)
59
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
59
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
60
-    @RequiresPermissions("fi-system:view")
60
+    @SaCheckPermission("fi-system:view")
61
     public ResponseBean taAccountLogList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
61
     public ResponseBean taAccountLogList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
62
                                          @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
62
                                          @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
63
                                          @ApiParam(value = "合作社ID") @RequestParam(value ="orgId", required = false) String orgId,
63
                                          @ApiParam(value = "合作社ID") @RequestParam(value ="orgId", required = false) String orgId,

+ 4
- 4
src/main/java/com/yunzhi/nanyang/controller/TaBannerController.java Parādīt failu

10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
12
 import io.swagger.annotations.ApiParam;
13
-import org.apache.shiro.authz.annotation.RequiresPermissions;
13
+import cn.dev33.satoken.annotation.SaCheckPermission;
14
 import org.slf4j.Logger;
14
 import org.slf4j.Logger;
15
 import org.slf4j.LoggerFactory;
15
 import org.slf4j.LoggerFactory;
16
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;
98
      */
98
      */
99
     @RequestMapping(value="/admin/banner",method= RequestMethod.POST)
99
     @RequestMapping(value="/admin/banner",method= RequestMethod.POST)
100
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
100
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
101
-    @RequiresPermissions("banner:add")
101
+    @SaCheckPermission("banner:add")
102
     public ResponseBean taBannerAdd(@ApiParam("保存内容") @RequestBody TaBanner taBanner) throws Exception{
102
     public ResponseBean taBannerAdd(@ApiParam("保存内容") @RequestBody TaBanner taBanner) throws Exception{
103
         if (StringUtils.isEmpty(taBanner.getTitle())) {
103
         if (StringUtils.isEmpty(taBanner.getTitle())) {
104
             return ResponseBean.error("标题不能为空");
104
             return ResponseBean.error("标题不能为空");
125
      */
125
      */
126
     @RequestMapping(value="/admin/banner/{id}", method= RequestMethod.DELETE)
126
     @RequestMapping(value="/admin/banner/{id}", method= RequestMethod.DELETE)
127
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
127
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
128
-    @RequiresPermissions("banner:delete")
128
+    @SaCheckPermission("banner:delete")
129
     public ResponseBean taBannerDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
129
     public ResponseBean taBannerDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
130
         if(iTaBannerService.removeLogicById(id)){
130
         if(iTaBannerService.removeLogicById(id)){
131
             return ResponseBean.success("success");
131
             return ResponseBean.success("success");
142
      */
142
      */
143
     @RequestMapping(value="/admin/banner/{id}",method= RequestMethod.PUT)
143
     @RequestMapping(value="/admin/banner/{id}",method= RequestMethod.PUT)
144
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
144
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
145
-    @RequiresPermissions("banner:update")
145
+    @SaCheckPermission("banner:update")
146
     public ResponseBean taBannerUpdate(@ApiParam("对象ID") @PathVariable String id,
146
     public ResponseBean taBannerUpdate(@ApiParam("对象ID") @PathVariable String id,
147
                                         @ApiParam("更新内容") @RequestBody TaBanner taBanner) throws Exception{
147
                                         @ApiParam("更新内容") @RequestBody TaBanner taBanner) throws Exception{
148
         taBanner.setBannerId(id);
148
         taBanner.setBannerId(id);

+ 3
- 3
src/main/java/com/yunzhi/nanyang/controller/TaDispatchController.java Parādīt failu

12
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiParam;
14
 import io.swagger.annotations.ApiParam;
15
-import org.apache.shiro.authz.annotation.RequiresPermissions;
15
+import cn.dev33.satoken.annotation.SaCheckPermission;
16
 import org.slf4j.Logger;
16
 import org.slf4j.Logger;
17
 import org.slf4j.LoggerFactory;
17
 import org.slf4j.LoggerFactory;
18
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.beans.factory.annotation.Autowired;
105
      */
105
      */
106
     @RequestMapping(value="/admin/dispatch",method= RequestMethod.POST)
106
     @RequestMapping(value="/admin/dispatch",method= RequestMethod.POST)
107
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
107
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
108
-    @RequiresPermissions("orderjob:add")
108
+    @SaCheckPermission("orderjob:add")
109
     public ResponseBean taDispatchAdd(@ApiParam("保存内容") @RequestBody TaDispatch taDispatch) throws Exception{
109
     public ResponseBean taDispatchAdd(@ApiParam("保存内容") @RequestBody TaDispatch taDispatch) throws Exception{
110
         taDispatch.setDispatchId(null);
110
         taDispatch.setDispatchId(null);
111
 
111
 
151
      */
151
      */
152
     @RequestMapping(value="/admin/dispatch/{id}", method= RequestMethod.DELETE)
152
     @RequestMapping(value="/admin/dispatch/{id}", method= RequestMethod.DELETE)
153
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
153
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
154
-    @RequiresPermissions("orderjob:delete")
154
+    @SaCheckPermission("orderjob:delete")
155
     public ResponseBean taDispatchDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
155
     public ResponseBean taDispatchDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
156
         TaDispatch taDispatch = iTaDispatchService.getById(id);
156
         TaDispatch taDispatch = iTaDispatchService.getById(id);
157
 
157
 

+ 2
- 2
src/main/java/com/yunzhi/nanyang/controller/TaFeedbackController.java Parādīt failu

10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiParam;
12
 import io.swagger.annotations.ApiParam;
13
-import org.apache.shiro.authz.annotation.RequiresPermissions;
13
+import cn.dev33.satoken.annotation.SaCheckPermission;
14
 import org.slf4j.Logger;
14
 import org.slf4j.Logger;
15
 import org.slf4j.LoggerFactory;
15
 import org.slf4j.LoggerFactory;
16
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;
91
      */
91
      */
92
     @RequestMapping(value="/admin/feedback/{id}",method= RequestMethod.PUT)
92
     @RequestMapping(value="/admin/feedback/{id}",method= RequestMethod.PUT)
93
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
93
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
94
-    @RequiresPermissions("feedback:update")
94
+    @SaCheckPermission("feedback:update")
95
     public ResponseBean taFeedbackUpdate(@ApiParam("对象ID") @PathVariable String id,
95
     public ResponseBean taFeedbackUpdate(@ApiParam("对象ID") @PathVariable String id,
96
                                         @ApiParam("更新内容") @RequestBody TaFeedback taFeedback) throws Exception{
96
                                         @ApiParam("更新内容") @RequestBody TaFeedback taFeedback) throws Exception{
97
         if (iTaFeedbackService.updateById(taFeedback)){
97
         if (iTaFeedbackService.updateById(taFeedback)){

+ 4
- 4
src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java Parādīt failu

16
 import io.swagger.annotations.Api;
16
 import io.swagger.annotations.Api;
17
 import io.swagger.annotations.ApiOperation;
17
 import io.swagger.annotations.ApiOperation;
18
 import io.swagger.annotations.ApiParam;
18
 import io.swagger.annotations.ApiParam;
19
-import org.apache.shiro.authz.annotation.RequiresPermissions;
19
+import cn.dev33.satoken.annotation.SaCheckPermission;
20
 import org.slf4j.Logger;
20
 import org.slf4j.Logger;
21
 import org.slf4j.LoggerFactory;
21
 import org.slf4j.LoggerFactory;
22
 import org.springframework.beans.factory.annotation.Autowired;
22
 import org.springframework.beans.factory.annotation.Autowired;
124
      */
124
      */
125
     @RequestMapping(value="/admin/machinery",method= RequestMethod.POST)
125
     @RequestMapping(value="/admin/machinery",method= RequestMethod.POST)
126
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
126
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
127
-    @RequiresPermissions("machinery:add")
127
+    @SaCheckPermission("machinery:add")
128
     public ResponseBean taMachineryAdd(@ApiParam("保存内容") @RequestBody TaMachinery taMachinery) throws Exception{
128
     public ResponseBean taMachineryAdd(@ApiParam("保存内容") @RequestBody TaMachinery taMachinery) throws Exception{
129
         SysUser sysUser = currentUser();
129
         SysUser sysUser = currentUser();
130
 
130
 
150
      */
150
      */
151
     @RequestMapping(value="/admin/machinery/{id}", method= RequestMethod.DELETE)
151
     @RequestMapping(value="/admin/machinery/{id}", method= RequestMethod.DELETE)
152
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
152
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
153
-    @RequiresPermissions("machinery:delete")
153
+    @SaCheckPermission("machinery:delete")
154
     public ResponseBean taMachineryDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
154
     public ResponseBean taMachineryDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
155
         TaMachinery taMachinery = iTaMachineryService.getExistBy("machinery_id", id, false, true);
155
         TaMachinery taMachinery = iTaMachineryService.getExistBy("machinery_id", id, false, true);
156
         if (null == taMachinery) {
156
         if (null == taMachinery) {
174
      */
174
      */
175
     @RequestMapping(value="/admin/machinery/{id}",method= RequestMethod.PUT)
175
     @RequestMapping(value="/admin/machinery/{id}",method= RequestMethod.PUT)
176
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
176
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
177
-    @RequiresPermissions("machinery:update")
177
+    @SaCheckPermission("machinery:update")
178
     public ResponseBean taMachineryUpdate(@ApiParam("对象ID") @PathVariable String id,
178
     public ResponseBean taMachineryUpdate(@ApiParam("对象ID") @PathVariable String id,
179
                                         @ApiParam("更新内容") @RequestBody TaMachinery taMachinery) throws Exception{
179
                                         @ApiParam("更新内容") @RequestBody TaMachinery taMachinery) throws Exception{
180
         if (StringUtils.isEmpty(taMachinery.getOrgId())) {
180
         if (StringUtils.isEmpty(taMachinery.getOrgId())) {

+ 4
- 4
src/main/java/com/yunzhi/nanyang/controller/TaNewsController.java Parādīt failu

14
 import io.swagger.annotations.Api;
14
 import io.swagger.annotations.Api;
15
 import io.swagger.annotations.ApiOperation;
15
 import io.swagger.annotations.ApiOperation;
16
 import io.swagger.annotations.ApiParam;
16
 import io.swagger.annotations.ApiParam;
17
-import org.apache.shiro.authz.annotation.RequiresPermissions;
17
+import cn.dev33.satoken.annotation.SaCheckPermission;
18
 import org.slf4j.Logger;
18
 import org.slf4j.Logger;
19
 import org.slf4j.LoggerFactory;
19
 import org.slf4j.LoggerFactory;
20
 import org.springframework.beans.factory.annotation.Autowired;
20
 import org.springframework.beans.factory.annotation.Autowired;
119
      */
119
      */
120
     @RequestMapping(value="/admin/news",method= RequestMethod.POST)
120
     @RequestMapping(value="/admin/news",method= RequestMethod.POST)
121
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
121
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
122
-    @RequiresPermissions("news:add")
122
+    @SaCheckPermission("news:add")
123
     public ResponseBean taNewsAdd(@ApiParam("保存内容") @RequestBody TaNews taNews) throws Exception{
123
     public ResponseBean taNewsAdd(@ApiParam("保存内容") @RequestBody TaNews taNews) throws Exception{
124
         SysUser sysUser = currentUser();
124
         SysUser sysUser = currentUser();
125
 
125
 
143
      */
143
      */
144
     @RequestMapping(value="/admin/news/{id}", method= RequestMethod.DELETE)
144
     @RequestMapping(value="/admin/news/{id}", method= RequestMethod.DELETE)
145
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
145
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
146
-    @RequiresPermissions("news:delete")
146
+    @SaCheckPermission("news:delete")
147
     public ResponseBean taNewsDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
147
     public ResponseBean taNewsDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
148
         if(iTaNewsService.removeLogicById(id)){
148
         if(iTaNewsService.removeLogicById(id)){
149
             return ResponseBean.success("success");
149
             return ResponseBean.success("success");
160
      */
160
      */
161
     @RequestMapping(value="/admin/news/{id}",method= RequestMethod.PUT)
161
     @RequestMapping(value="/admin/news/{id}",method= RequestMethod.PUT)
162
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
162
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
163
-    @RequiresPermissions("news:update")
163
+    @SaCheckPermission("news:update")
164
     public ResponseBean taNewsUpdate(@ApiParam("对象ID") @PathVariable String id,
164
     public ResponseBean taNewsUpdate(@ApiParam("对象ID") @PathVariable String id,
165
                                         @ApiParam("更新内容") @RequestBody TaNews taNews) throws Exception{
165
                                         @ApiParam("更新内容") @RequestBody TaNews taNews) throws Exception{
166
         taNews.setNewsId(id);
166
         taNews.setNewsId(id);

+ 4
- 4
src/main/java/com/yunzhi/nanyang/controller/TaNewsTypeController.java Parādīt failu

11
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
14
-import org.apache.shiro.authz.annotation.RequiresPermissions;
14
+import cn.dev33.satoken.annotation.SaCheckPermission;
15
 import org.slf4j.Logger;
15
 import org.slf4j.Logger;
16
 import org.slf4j.LoggerFactory;
16
 import org.slf4j.LoggerFactory;
17
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
75
      */
75
      */
76
     @RequestMapping(value="/admin/news-type",method= RequestMethod.POST)
76
     @RequestMapping(value="/admin/news-type",method= RequestMethod.POST)
77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
78
-    @RequiresPermissions("news:add")
78
+    @SaCheckPermission("news:add")
79
     public ResponseBean taNewsTypeAdd(@ApiParam("保存内容") @RequestBody TaNewsType taNewsType) throws Exception{
79
     public ResponseBean taNewsTypeAdd(@ApiParam("保存内容") @RequestBody TaNewsType taNewsType) throws Exception{
80
         taNewsType.setTypeId(null);
80
         taNewsType.setTypeId(null);
81
 
81
 
102
      */
102
      */
103
     @RequestMapping(value="/admin/news-type/{id}", method= RequestMethod.DELETE)
103
     @RequestMapping(value="/admin/news-type/{id}", method= RequestMethod.DELETE)
104
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
104
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
105
-    @RequiresPermissions("news:delete")
105
+    @SaCheckPermission("news:delete")
106
     public ResponseBean taNewsTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
106
     public ResponseBean taNewsTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
107
         TaNewsType taNewsType = iTaNewsTypeService.getExistBy("type_id", id, false, true);
107
         TaNewsType taNewsType = iTaNewsTypeService.getExistBy("type_id", id, false, true);
108
         if (null == taNewsType) {
108
         if (null == taNewsType) {
129
      */
129
      */
130
     @RequestMapping(value="/admin/news-type/{id}",method= RequestMethod.PUT)
130
     @RequestMapping(value="/admin/news-type/{id}",method= RequestMethod.PUT)
131
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
131
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
132
-    @RequiresPermissions("news:update")
132
+    @SaCheckPermission("news:update")
133
     public ResponseBean taNewsTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
133
     public ResponseBean taNewsTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
134
                                         @ApiParam("更新内容") @RequestBody TaNewsType taNewsType) throws Exception{
134
                                         @ApiParam("更新内容") @RequestBody TaNewsType taNewsType) throws Exception{
135
         taNewsType.setTypeId(id);
135
         taNewsType.setTypeId(id);

+ 6
- 6
src/main/java/com/yunzhi/nanyang/controller/TaOrgController.java Parādīt failu

12
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.Api;
13
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiOperation;
14
 import io.swagger.annotations.ApiParam;
14
 import io.swagger.annotations.ApiParam;
15
-import org.apache.shiro.authz.annotation.RequiresPermissions;
15
+import cn.dev33.satoken.annotation.SaCheckPermission;
16
 import org.slf4j.Logger;
16
 import org.slf4j.Logger;
17
 import org.slf4j.LoggerFactory;
17
 import org.slf4j.LoggerFactory;
18
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.beans.factory.annotation.Autowired;
63
      */
63
      */
64
     @RequestMapping(value="/admin/org",method= RequestMethod.GET)
64
     @RequestMapping(value="/admin/org",method= RequestMethod.GET)
65
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
65
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
66
-    @RequiresPermissions("org:view")
66
+    @SaCheckPermission("org:view")
67
     public ResponseBean taOrgList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
67
     public ResponseBean taOrgList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
68
                                   @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
68
                                   @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
69
                                   @ApiParam("名称") @RequestParam(value ="name", required = false) String name) throws Exception{
69
                                   @ApiParam("名称") @RequestParam(value ="name", required = false) String name) throws Exception{
82
      */
82
      */
83
     @RequestMapping(value="/admin/org",method= RequestMethod.POST)
83
     @RequestMapping(value="/admin/org",method= RequestMethod.POST)
84
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
84
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
85
-    @RequiresPermissions("org:add")
85
+    @SaCheckPermission("org:add")
86
     public ResponseBean taOrgAdd(@ApiParam("保存内容") @RequestBody TaOrg taOrg) throws Exception{
86
     public ResponseBean taOrgAdd(@ApiParam("保存内容") @RequestBody TaOrg taOrg) throws Exception{
87
 
87
 
88
         SysUser sysUser = currentUser();
88
         SysUser sysUser = currentUser();
103
      */
103
      */
104
     @RequestMapping(value="/admin/org/{id}", method= RequestMethod.DELETE)
104
     @RequestMapping(value="/admin/org/{id}", method= RequestMethod.DELETE)
105
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
105
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
106
-    @RequiresPermissions("org:delete")
106
+    @SaCheckPermission("org:delete")
107
     public ResponseBean taOrgDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
107
     public ResponseBean taOrgDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
108
 
108
 
109
         int cnt = iSysUserService.countBy("org_id", id, true);
109
         int cnt = iSysUserService.countBy("org_id", id, true);
130
      */
130
      */
131
     @RequestMapping(value="/admin/org/{id}",method= RequestMethod.PUT)
131
     @RequestMapping(value="/admin/org/{id}",method= RequestMethod.PUT)
132
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
132
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
133
-    @RequiresPermissions("org:update")
133
+    @SaCheckPermission("org:update")
134
     public ResponseBean taOrgUpdate(@ApiParam("对象ID") @PathVariable String id,
134
     public ResponseBean taOrgUpdate(@ApiParam("对象ID") @PathVariable String id,
135
                                         @ApiParam("更新内容") @RequestBody TaOrg taOrg) throws Exception{
135
                                         @ApiParam("更新内容") @RequestBody TaOrg taOrg) throws Exception{
136
 
136
 
159
      */
159
      */
160
     @RequestMapping(value="/admin/org/{id}",method= RequestMethod.GET)
160
     @RequestMapping(value="/admin/org/{id}",method= RequestMethod.GET)
161
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
161
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
162
-    @RequiresPermissions("org:view")
162
+    @SaCheckPermission("org:view")
163
     public ResponseBean taOrgGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
163
     public ResponseBean taOrgGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
164
         if (!iTaOrgService.canAccessData(id, currentUser().getUserId())) {
164
         if (!iTaOrgService.canAccessData(id, currentUser().getUserId())) {
165
             return ResponseBean.error("无权限或者ID不正确");
165
             return ResponseBean.error("无权限或者ID不正确");

+ 4
- 5
src/main/java/com/yunzhi/nanyang/controller/TaPersonController.java Parādīt failu

1
 package com.yunzhi.nanyang.controller;
1
 package com.yunzhi.nanyang.controller;
2
 
2
 
3
+import cn.dev33.satoken.stp.StpUtil;
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.yunzhi.nanyang.common.*;
7
 import com.yunzhi.nanyang.common.*;
7
 import com.yunzhi.nanyang.entity.SysUser;
8
 import com.yunzhi.nanyang.entity.SysUser;
8
 import com.yunzhi.nanyang.service.ISysUserService;
9
 import com.yunzhi.nanyang.service.ISysUserService;
9
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
10
 import com.yunzhi.nanyang.vo.PhoneParam;
10
 import com.yunzhi.nanyang.vo.PhoneParam;
11
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
18
 import org.springframework.web.bind.annotation.RequestBody;
18
 import org.springframework.web.bind.annotation.RequestBody;
19
 import org.springframework.web.bind.annotation.RequestMapping;
19
 import org.springframework.web.bind.annotation.RequestMapping;
20
 import org.springframework.web.bind.annotation.RequestMethod;
20
 import org.springframework.web.bind.annotation.RequestMethod;
21
-import org.springframework.web.bind.annotation.RequestParam;
22
 import com.yunzhi.nanyang.service.ITaPersonService;
21
 import com.yunzhi.nanyang.service.ITaPersonService;
23
 import com.yunzhi.nanyang.entity.TaPerson;
22
 import com.yunzhi.nanyang.entity.TaPerson;
24
 import org.springframework.web.bind.annotation.RestController;
23
 import org.springframework.web.bind.annotation.RestController;
222
         }
221
         }
223
 
222
 
224
         if (iTaPersonService.updateById(taPerson)){
223
         if (iTaPersonService.updateById(taPerson)){
225
-            // 因为有可能修改 person 为 app 端的人员, 所以此处刷新一次 token
226
-            String token = JWTUtil.sign(taPerson.getPersonId(), taPerson.getPersonId());
224
+            StpUtil.logout();
225
+            StpUtil.login(taPerson.getPersonId(), clientId);
227
             Map<String, Object> res = new HashMap<>();
226
             Map<String, Object> res = new HashMap<>();
228
             res.put("person", taPerson);
227
             res.put("person", taPerson);
229
-            res.put("token", token);
228
+            res.put("token", StpUtil.getTokenValue());
230
             return ResponseBean.success(res);
229
             return ResponseBean.success(res);
231
         }else {
230
         }else {
232
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
231
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);

+ 6
- 6
src/main/java/com/yunzhi/nanyang/controller/TaRegionController.java Parādīt failu

9
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
10
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiParam;
11
 import io.swagger.annotations.ApiParam;
12
-import org.apache.shiro.authz.annotation.RequiresPermissions;
12
+import cn.dev33.satoken.annotation.SaCheckPermission;
13
 import org.slf4j.Logger;
13
 import org.slf4j.Logger;
14
 import org.slf4j.LoggerFactory;
14
 import org.slf4j.LoggerFactory;
15
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.beans.factory.annotation.Autowired;
53
      */
53
      */
54
     @RequestMapping(value="/admin/region",method= RequestMethod.GET)
54
     @RequestMapping(value="/admin/region",method= RequestMethod.GET)
55
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
55
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
56
-    @RequiresPermissions("region:view")
56
+    @SaCheckPermission("region:view")
57
     public ResponseBean taRegionList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
57
     public ResponseBean taRegionList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
58
 									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
58
 									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
59
                                      @ApiParam("名称") @RequestParam(value ="name", required = false) String name) throws Exception{
59
                                      @ApiParam("名称") @RequestParam(value ="name", required = false) String name) throws Exception{
71
      */
71
      */
72
     @RequestMapping(value="/admin/region",method= RequestMethod.POST)
72
     @RequestMapping(value="/admin/region",method= RequestMethod.POST)
73
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
73
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
74
-    @RequiresPermissions("region:add")
74
+    @SaCheckPermission("region:add")
75
     public ResponseBean taRegionAdd(@ApiParam("保存内容") @RequestBody TaRegion taRegion) throws Exception{
75
     public ResponseBean taRegionAdd(@ApiParam("保存内容") @RequestBody TaRegion taRegion) throws Exception{
76
 
76
 
77
         taRegion.setRegionId(null);
77
         taRegion.setRegionId(null);
98
      */
98
      */
99
     @RequestMapping(value="/admin/region/{id}", method= RequestMethod.DELETE)
99
     @RequestMapping(value="/admin/region/{id}", method= RequestMethod.DELETE)
100
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
100
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
101
-    @RequiresPermissions("region:delete")
101
+    @SaCheckPermission("region:delete")
102
     public ResponseBean taRegionDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
102
     public ResponseBean taRegionDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
103
         if(iTaRegionService.removeLogicById(id)){
103
         if(iTaRegionService.removeLogicById(id)){
104
             return ResponseBean.success("success");
104
             return ResponseBean.success("success");
115
      */
115
      */
116
     @RequestMapping(value="/admin/region/{id}",method= RequestMethod.PUT)
116
     @RequestMapping(value="/admin/region/{id}",method= RequestMethod.PUT)
117
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
117
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
118
-    @RequiresPermissions("region:update")
118
+    @SaCheckPermission("region:update")
119
     public ResponseBean taRegionUpdate(@ApiParam("对象ID") @PathVariable String id,
119
     public ResponseBean taRegionUpdate(@ApiParam("对象ID") @PathVariable String id,
120
                                         @ApiParam("更新内容") @RequestBody TaRegion taRegion) throws Exception {
120
                                         @ApiParam("更新内容") @RequestBody TaRegion taRegion) throws Exception {
121
 
121
 
144
      */
144
      */
145
     @RequestMapping(value="/admin/region/{id}",method= RequestMethod.GET)
145
     @RequestMapping(value="/admin/region/{id}",method= RequestMethod.GET)
146
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
146
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
147
-    @RequiresPermissions("region:view")
147
+    @SaCheckPermission("region:view")
148
     public ResponseBean taRegionGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
148
     public ResponseBean taRegionGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
149
         return ResponseBean.success(iTaRegionService.getExistBy("region_id", id, false, true));
149
         return ResponseBean.success(iTaRegionService.getExistBy("region_id", id, false, true));
150
     }
150
     }

+ 2
- 2
src/main/java/com/yunzhi/nanyang/controller/TaUserMachineryController.java Parādīt failu

11
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
14
-import org.apache.shiro.authz.annotation.RequiresPermissions;
14
+import cn.dev33.satoken.annotation.SaCheckPermission;
15
 import org.slf4j.Logger;
15
 import org.slf4j.Logger;
16
 import org.slf4j.LoggerFactory;
16
 import org.slf4j.LoggerFactory;
17
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
76
      */
76
      */
77
     @RequestMapping(value="/admin/user/{userId}/machinery",method= RequestMethod.POST)
77
     @RequestMapping(value="/admin/user/{userId}/machinery",method= RequestMethod.POST)
78
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
78
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
79
-    @RequiresPermissions("user:update")
79
+    @SaCheckPermission("user:update")
80
     public ResponseBean taUserMachineryAdd(@ApiParam("用户ID") @PathVariable String userId,
80
     public ResponseBean taUserMachineryAdd(@ApiParam("用户ID") @PathVariable String userId,
81
                                            @ApiParam("保存内容") @RequestBody List<TaUserMachinery> userMachineryList) throws Exception{
81
                                            @ApiParam("保存内容") @RequestBody List<TaUserMachinery> userMachineryList) throws Exception{
82
 
82
 

+ 4
- 4
src/main/java/com/yunzhi/nanyang/controller/TdMachineryTypeController.java Parādīt failu

11
 import io.swagger.annotations.Api;
11
 import io.swagger.annotations.Api;
12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
14
-import org.apache.shiro.authz.annotation.RequiresPermissions;
14
+import cn.dev33.satoken.annotation.SaCheckPermission;
15
 import org.slf4j.Logger;
15
 import org.slf4j.Logger;
16
 import org.slf4j.LoggerFactory;
16
 import org.slf4j.LoggerFactory;
17
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
101
      */
101
      */
102
     @RequestMapping(value="/admin/machinery-type",method= RequestMethod.POST)
102
     @RequestMapping(value="/admin/machinery-type",method= RequestMethod.POST)
103
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
103
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
104
-    @RequiresPermissions("machinetype:add")
104
+    @SaCheckPermission("machinetype:add")
105
     public ResponseBean tdMachineryTypeAdd(@ApiParam("保存内容") @RequestBody TdMachineryType tdMachineryType) throws Exception{
105
     public ResponseBean tdMachineryTypeAdd(@ApiParam("保存内容") @RequestBody TdMachineryType tdMachineryType) throws Exception{
106
 
106
 
107
         tdMachineryType.setTypeId(null);
107
         tdMachineryType.setTypeId(null);
128
      */
128
      */
129
     @RequestMapping(value="/admin/machinery-type/{id}", method= RequestMethod.DELETE)
129
     @RequestMapping(value="/admin/machinery-type/{id}", method= RequestMethod.DELETE)
130
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
130
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
131
-    @RequiresPermissions("machinetype:delete")
131
+    @SaCheckPermission("machinetype:delete")
132
     public ResponseBean tdMachineryTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
132
     public ResponseBean tdMachineryTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
133
 
133
 
134
         TdMachineryType tdMachineryType = iTdMachineryTypeService.getExistBy("type_id", id, false, true);
134
         TdMachineryType tdMachineryType = iTdMachineryTypeService.getExistBy("type_id", id, false, true);
157
      */
157
      */
158
     @RequestMapping(value="/admin/machinery-type/{id}",method= RequestMethod.PUT)
158
     @RequestMapping(value="/admin/machinery-type/{id}",method= RequestMethod.PUT)
159
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
159
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
160
-    @RequiresPermissions("machinetype:update")
160
+    @SaCheckPermission("machinetype:update")
161
     public ResponseBean tdMachineryTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
161
     public ResponseBean tdMachineryTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
162
                                         @ApiParam("更新内容") @RequestBody TdMachineryType tdMachineryType) throws Exception{
162
                                         @ApiParam("更新内容") @RequestBody TdMachineryType tdMachineryType) throws Exception{
163
         tdMachineryType.setTypeId(id);
163
         tdMachineryType.setTypeId(id);

+ 3
- 5
src/main/java/com/yunzhi/nanyang/controller/WxMaController.java Parādīt failu

4
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
4
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
5
 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
5
 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
6
 import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
6
 import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
7
+import cn.dev33.satoken.stp.StpUtil;
7
 import com.yunzhi.nanyang.common.*;
8
 import com.yunzhi.nanyang.common.*;
8
 import com.yunzhi.nanyang.entity.SysMiniapp;
9
 import com.yunzhi.nanyang.entity.SysMiniapp;
9
 import com.yunzhi.nanyang.entity.TaMessageTemplate;
10
 import com.yunzhi.nanyang.entity.TaMessageTemplate;
11
 import com.yunzhi.nanyang.service.ISysMiniappService;
12
 import com.yunzhi.nanyang.service.ISysMiniappService;
12
 import com.yunzhi.nanyang.service.ITaMessageTemplateService;
13
 import com.yunzhi.nanyang.service.ITaMessageTemplateService;
13
 import com.yunzhi.nanyang.service.ITaPersonService;
14
 import com.yunzhi.nanyang.service.ITaPersonService;
14
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
15
 import com.yunzhi.nanyang.vo.LoginParam;
15
 import com.yunzhi.nanyang.vo.LoginParam;
16
 import com.yunzhi.nanyang.vo.WxMaAuthParam;
16
 import com.yunzhi.nanyang.vo.WxMaAuthParam;
17
 import com.yunzhi.nanyang.vo.WxMaPreload;
17
 import com.yunzhi.nanyang.vo.WxMaPreload;
114
             iTaPersonService.tryBindUser(taPerson);
114
             iTaPersonService.tryBindUser(taPerson);
115
         }
115
         }
116
 
116
 
117
-        // 生成 token
118
-        String token = JWTUtil.sign(taPerson.getPersonId(), taPerson.getPersonId());
119
-
117
+        StpUtil.login(taPerson.getPersonId(), clientId);
120
         Map<String, Object> res = new HashMap<>();
118
         Map<String, Object> res = new HashMap<>();
121
         res.put("person", taPerson);
119
         res.put("person", taPerson);
122
-        res.put("token", token);
120
+        res.put("token", StpUtil.getTokenValue());
123
         res.put("sessionKey", sessionKey);
121
         res.put("sessionKey", sessionKey);
124
 
122
 
125
         return ResponseBean.success(res);
123
         return ResponseBean.success(res);

+ 2
- 2
src/main/java/com/yunzhi/nanyang/exception/GlobalExceptionHandler.java Parādīt failu

1
 package com.yunzhi.nanyang.exception;
1
 package com.yunzhi.nanyang.exception;
2
 
2
 
3
+import cn.dev33.satoken.exception.SaTokenException;
3
 import com.yunzhi.nanyang.common.ResponseBean;
4
 import com.yunzhi.nanyang.common.ResponseBean;
4
 import lombok.extern.slf4j.Slf4j;
5
 import lombok.extern.slf4j.Slf4j;
5
-import org.apache.shiro.authz.UnauthorizedException;
6
 import org.springframework.web.bind.annotation.ExceptionHandler;
6
 import org.springframework.web.bind.annotation.ExceptionHandler;
7
 import org.springframework.web.bind.annotation.ResponseBody;
7
 import org.springframework.web.bind.annotation.ResponseBody;
8
 import org.springframework.web.bind.annotation.RestControllerAdvice;
8
 import org.springframework.web.bind.annotation.RestControllerAdvice;
16
     public ResponseBean handleException(Exception e){
16
     public ResponseBean handleException(Exception e){
17
         e.printStackTrace();
17
         e.printStackTrace();
18
 
18
 
19
-        if (e instanceof UnauthorizedException) {
19
+        if (e instanceof SaTokenException) {
20
             return ResponseBean.error("暂无权限进行当前操作", ResponseBean.ERROR_UNAUTHORIZED);
20
             return ResponseBean.error("暂无权限进行当前操作", ResponseBean.ERROR_UNAUTHORIZED);
21
         }
21
         }
22
 
22
 

+ 2
- 2
src/main/java/com/yunzhi/nanyang/mapper/SysRoleMapper.java Parādīt failu

7
 import org.apache.ibatis.annotations.Param;
7
 import org.apache.ibatis.annotations.Param;
8
 import org.apache.ibatis.annotations.Select;
8
 import org.apache.ibatis.annotations.Select;
9
 
9
 
10
-import java.util.Set;
10
+import java.util.List;
11
 
11
 
12
 /**
12
 /**
13
  * <p>
13
  * <p>
21
 public interface SysRoleMapper extends BaseMapper<SysRole> {
21
 public interface SysRoleMapper extends BaseMapper<SysRole> {
22
 
22
 
23
     @Select("select role_id from sys_role")
23
     @Select("select role_id from sys_role")
24
-    Set<String> getAllRole();
24
+    List<String> getAllRole();
25
 
25
 
26
     IPage<SysRole> getPageBy(IPage<SysRole> pg,
26
     IPage<SysRole> getPageBy(IPage<SysRole> pg,
27
                              @Param("isAdmin") boolean isAdmin,
27
                              @Param("isAdmin") boolean isAdmin,

+ 1
- 2
src/main/java/com/yunzhi/nanyang/mapper/SysRolePermissionMapper.java Parādīt failu

6
 import org.apache.ibatis.annotations.Param;
6
 import org.apache.ibatis.annotations.Param;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.Set;
10
 
9
 
11
 /**
10
 /**
12
  * <p>
11
  * <p>
19
 @Mapper
18
 @Mapper
20
 public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> {
19
 public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> {
21
 
20
 
22
-    Set<String> getPermissionByUser(@Param("isAdmin") boolean isAdmin,
21
+    List<String> getPermissionByUser(@Param("isAdmin") boolean isAdmin,
23
                                     @Param("userId") String userId);
22
                                     @Param("userId") String userId);
24
 
23
 
25
     List<SysRolePermission> listBy(@Param("roleId") String roleId);
24
     List<SysRolePermission> listBy(@Param("roleId") String roleId);

+ 1
- 2
src/main/java/com/yunzhi/nanyang/mapper/SysUserRoleMapper.java Parādīt failu

6
 import org.apache.ibatis.annotations.Param;
6
 import org.apache.ibatis.annotations.Param;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.Set;
10
 
9
 
11
 /**
10
 /**
12
  * <p>
11
  * <p>
19
 @Mapper
18
 @Mapper
20
 public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
19
 public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
21
 
20
 
22
-    Set<String> getRoleByUser(@Param("userId") String userId);
21
+    List<String> getRoleByUser(@Param("userId") String userId);
23
 
22
 
24
     List<SysUserRole> listByUser(@Param("userId") String userId);
23
     List<SysUserRole> listByUser(@Param("userId") String userId);
25
 }
24
 }

+ 7
- 16
src/main/java/com/yunzhi/nanyang/service/impl/ManagerServiceImpl.java Parādīt failu

1
 package com.yunzhi.nanyang.service.impl;
1
 package com.yunzhi.nanyang.service.impl;
2
 
2
 
3
+import cn.dev33.satoken.stp.StpInterface;
3
 import com.yunzhi.nanyang.common.Constants;
4
 import com.yunzhi.nanyang.common.Constants;
4
 import com.yunzhi.nanyang.entity.*;
5
 import com.yunzhi.nanyang.entity.*;
5
 import com.yunzhi.nanyang.mapper.*;
6
 import com.yunzhi.nanyang.mapper.*;
6
-import com.yunzhi.nanyang.shiro.realms.manager.IManagerService;
7
 import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.stereotype.Service;
8
 import org.springframework.stereotype.Service;
9
 
9
 
10
+import java.util.List;
10
 import java.util.Set;
11
 import java.util.Set;
11
 
12
 
12
 @Service
13
 @Service
13
-public class ManagerServiceImpl implements IManagerService {
14
+public class ManagerServiceImpl implements StpInterface {
14
 
15
 
15
     @Autowired
16
     @Autowired
16
     SysLoginMapper sysLoginMapper;
17
     SysLoginMapper sysLoginMapper;
31
     SysPermissionMapper sysPermissionMapper;
32
     SysPermissionMapper sysPermissionMapper;
32
 
33
 
33
     @Override
34
     @Override
34
-    public Boolean verify(String id) {
35
-        SysLogin sysLogin = sysLoginMapper.selectById(id);
36
-        if (null == sysLogin || sysLogin.getStatus() != Constants.STATUS_NORMAL) {
37
-            return false;
38
-        }
39
-
40
-        return true;
41
-    }
42
-
43
-    @Override
44
-    public Set<String> getRolesByLoginId(String id) {
45
-        SysLogin sysLogin = sysLoginMapper.selectById(id);
35
+    public List<String> getRoleList(Object loginId, String loginType) {
36
+        SysLogin sysLogin = sysLoginMapper.selectById(loginId.toString());
46
 
37
 
47
         if (sysLogin.getUserId().equals(Constants.ADMIN_ID)) {
38
         if (sysLogin.getUserId().equals(Constants.ADMIN_ID)) {
48
             return sysRoleMapper.getAllRole();
39
             return sysRoleMapper.getAllRole();
52
     }
43
     }
53
 
44
 
54
     @Override
45
     @Override
55
-    public Set<String> getPermissionsLoginId(String id) {
56
-        SysLogin sysLogin = sysLoginMapper.selectById(id);
46
+    public List<String> getPermissionList(Object loginId, String loginType) {
47
+        SysLogin sysLogin = sysLoginMapper.selectById(loginId.toString());
57
         String userId = sysLogin.getUserId();
48
         String userId = sysLogin.getUserId();
58
         boolean isAdmin = userId.equals(Constants.ADMIN_ID);
49
         boolean isAdmin = userId.equals(Constants.ADMIN_ID);
59
 
50
 

+ 0
- 106
src/main/java/com/yunzhi/nanyang/shiro/ShiroConfig.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro;
2
-
3
-import com.yunzhi.nanyang.shiro.filters.JWTFilter;
4
-import com.yunzhi.nanyang.shiro.filters.ManagerFilter;
5
-import com.yunzhi.nanyang.shiro.filters.MiniappFilter;
6
-import com.yunzhi.nanyang.shiro.matcher.JWTCredentialsMatcher;
7
-import com.yunzhi.nanyang.shiro.realms.manager.IManagerService;
8
-import com.yunzhi.nanyang.shiro.realms.manager.ManagerRealm;
9
-import com.yunzhi.nanyang.shiro.realms.miniapp.MiniappRealm;
10
-import org.apache.shiro.authc.Authenticator;
11
-import org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy;
12
-import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
13
-import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
14
-import org.apache.shiro.authz.Authorizer;
15
-import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
16
-import org.apache.shiro.mgt.DefaultSubjectDAO;
17
-import org.apache.shiro.realm.Realm;
18
-import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
19
-import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
20
-import org.springframework.beans.factory.annotation.Autowired;
21
-import org.springframework.beans.factory.annotation.Value;
22
-import org.springframework.context.annotation.Bean;
23
-import org.springframework.context.annotation.Configuration;
24
-
25
-import javax.servlet.Filter;
26
-import java.util.ArrayList;
27
-import java.util.HashMap;
28
-import java.util.List;
29
-import java.util.Map;
30
-
31
-@Configuration
32
-public class ShiroConfig {
33
-
34
-    @Autowired
35
-    IManagerService iManagerService;
36
-
37
-    @Value("${shiro.unauthorizedUrl}")
38
-    private String unauthorizedUrl;
39
-
40
-    @Value("#{${shiro.filterRuleMap}}")
41
-    private Map<String, String> filterRuleMap;
42
-
43
-    @Bean
44
-    public ManagerRealm managerRealm() {
45
-        ManagerRealm realm = new ManagerRealm();
46
-        realm.setManagerService(iManagerService);
47
-        realm.setCredentialsMatcher(new JWTCredentialsMatcher());
48
-        return realm;
49
-    }
50
-
51
-    @Bean
52
-    public MiniappRealm miniappRealm() {
53
-        MiniappRealm realm = new MiniappRealm();
54
-        realm.setCredentialsMatcher(new JWTCredentialsMatcher());
55
-        return realm;
56
-    }
57
-
58
-    @Bean("shiroFilterFactoryBean")
59
-    public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) {
60
-        ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
61
-
62
-        // 手动加入 Filter
63
-        ManagerFilter managerFilter = new ManagerFilter();
64
-        managerFilter.setUnauthorizedUrl(unauthorizedUrl);
65
-        MiniappFilter miniappFilter = new MiniappFilter();
66
-        miniappFilter.setUnauthorizedUrl(unauthorizedUrl);
67
-
68
-        Map<String, Filter> filterMap = new HashMap<>();
69
-        filterMap.put("manager", managerFilter);
70
-        filterMap.put("miniapp", miniappFilter);
71
-        factoryBean.setFilters(filterMap);
72
-
73
-        factoryBean.setSecurityManager(securityManager);
74
-        factoryBean.setUnauthorizedUrl(unauthorizedUrl);
75
-
76
-        factoryBean.setFilterChainDefinitionMap(filterRuleMap);
77
-        return factoryBean;
78
-    }
79
-
80
-    @Bean("securityManager")
81
-    public DefaultWebSecurityManager securityManager() {
82
-        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
83
-        // 修改多 Realm 的处理逻辑
84
-        ModularRealmAuthenticator realmAuthenticator = (ModularRealmAuthenticator) manager.getAuthenticator();
85
-        // 主要有一个 Realm 成功, 就立即返回
86
-        realmAuthenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
87
-
88
-        //  Use your own realm
89
-        List<Realm> realmList = new ArrayList<Realm>() {{
90
-            add(managerRealm());
91
-            add(miniappRealm());
92
-        }};
93
-        manager.setRealms(realmList);
94
-
95
-        /*
96
-         * 禁用 session
97
-         */
98
-        DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
99
-        DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
100
-        defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
101
-        subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
102
-        manager.setSubjectDAO(subjectDAO);
103
-
104
-        return manager;
105
-    }
106
-}

+ 0
- 84
src/main/java/com/yunzhi/nanyang/shiro/filters/JWTFilter.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.filters;
2
-
3
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
4
-import org.apache.shiro.authc.AuthenticationToken;
5
-import org.apache.shiro.subject.Subject;
6
-import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
7
-import org.apache.shiro.web.util.WebUtils;
8
-import org.slf4j.Logger;
9
-import org.slf4j.LoggerFactory;
10
-
11
-import javax.servlet.ServletRequest;
12
-import javax.servlet.ServletResponse;
13
-import javax.servlet.http.HttpServletResponse;
14
-import java.io.IOException;
15
-import java.io.UnsupportedEncodingException;
16
-import java.net.URLEncoder;
17
-
18
-public abstract class JWTFilter extends AuthenticatingFilter {
19
-
20
-    private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
21
-
22
-    public final static String JWT_HEADER = "Authorization";
23
-
24
-    // token 刷新频率
25
-    private final static long REFRESH_MILLS = 99 * 24 * 60 * 1000;
26
-
27
-    private String unauthorizedUrl;
28
-    public void setUnauthorizedUrl(String unauthorizedUrl) {
29
-        this.unauthorizedUrl = unauthorizedUrl;
30
-    }
31
-
32
-    @Override
33
-    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
34
-        try {
35
-            return executeLogin(request, response);
36
-        } catch (Exception e) {
37
-            response401(request, response, e);
38
-        }
39
-
40
-        return false;
41
-    }
42
-
43
-    @Override
44
-    protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
45
-        return false;
46
-    }
47
-
48
-    @Override
49
-    protected abstract AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception;
50
-
51
-    // 主要用来刷新 token
52
-    @Override
53
-    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
54
-        String originToken = token.getPrincipal().toString();
55
-
56
-        long diff = System.currentTimeMillis() - JWTUtil.getExpDate(originToken).getTime();
57
-        if (diff >= REFRESH_MILLS) {
58
-            HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
59
-            httpServletResponse.setHeader(JWT_HEADER, JWTUtil.refresh(originToken));
60
-        }
61
-
62
-        return true;
63
-    }
64
-
65
-    /**
66
-     *Jump illegal request to / 401
67
-     */
68
-    protected void response401(ServletRequest request, ServletResponse response, Exception e) {
69
-        String message = "";
70
-        if (e != null) {
71
-            try {
72
-                message = URLEncoder.encode(e.getMessage(), "UTF-8");
73
-            } catch (UnsupportedEncodingException ex) {
74
-                //
75
-            }
76
-        }
77
-
78
-        try {
79
-            WebUtils.toHttp(response).sendRedirect(unauthorizedUrl + "?msg=" + message);
80
-        } catch (IOException e1) {
81
-            LOGGER.error(e1.getMessage());
82
-        }
83
-    }
84
-}

+ 0
- 29
src/main/java/com/yunzhi/nanyang/shiro/filters/ManagerFilter.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.filters;
2
-
3
-import com.yunzhi.nanyang.shiro.utils.JWTToken;
4
-import com.yunzhi.nanyang.shiro.utils.MiniappToken;
5
-import org.apache.shiro.authc.AuthenticationToken;
6
-import org.apache.shiro.web.util.WebUtils;
7
-
8
-import javax.servlet.ServletRequest;
9
-import javax.servlet.ServletResponse;
10
-import javax.servlet.http.HttpServletRequest;
11
-
12
-/**
13
- * ManagerFilter 与 MiniappFilter 实际上是一样的,只是返回的 token 类型不一致
14
- */
15
-public class ManagerFilter extends JWTFilter {
16
-
17
-    @Override
18
-    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
19
-        HttpServletRequest request = WebUtils.toHttp(servletRequest);
20
-        String authorization = request.getHeader(JWT_HEADER);
21
-        if (authorization == null || "".equals(authorization)) {
22
-            throw new Exception("请先登录系统");
23
-        }
24
-
25
-        return new JWTToken(authorization);
26
-    }
27
-
28
-
29
-}

+ 0
- 24
src/main/java/com/yunzhi/nanyang/shiro/filters/MiniappFilter.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.filters;
2
-
3
-import com.yunzhi.nanyang.shiro.utils.MiniappToken;
4
-import org.apache.shiro.authc.AuthenticationToken;
5
-import org.apache.shiro.web.util.WebUtils;
6
-
7
-import javax.servlet.ServletRequest;
8
-import javax.servlet.ServletResponse;
9
-import javax.servlet.http.HttpServletRequest;
10
-
11
-public class MiniappFilter  extends JWTFilter {
12
-
13
-    @Override
14
-    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
15
-        HttpServletRequest request = WebUtils.toHttp(servletRequest);
16
-        String authorization = request.getHeader(JWT_HEADER);
17
-        if (authorization == null || "".equals(authorization)) {
18
-            throw new Exception("请先登录系统");
19
-        }
20
-
21
-        return new MiniappToken(authorization);
22
-    }
23
-
24
-}

+ 0
- 16
src/main/java/com/yunzhi/nanyang/shiro/matcher/JWTCredentialsMatcher.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.matcher;
2
-
3
-import org.apache.shiro.authc.AuthenticationInfo;
4
-import org.apache.shiro.authc.AuthenticationToken;
5
-import org.apache.shiro.authc.credential.CredentialsMatcher;
6
-
7
-public class JWTCredentialsMatcher implements CredentialsMatcher {
8
-    @Override
9
-    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
10
-//        String token = authenticationToken.getCredentials().toString();
11
-//        return JWTUtil.verify(token);
12
-
13
-        // 校验在 realm 做过了
14
-        return true;
15
-    }
16
-}

+ 0
- 31
src/main/java/com/yunzhi/nanyang/shiro/realms/manager/IManagerService.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.realms.manager;
2
-
3
-import java.util.Set;
4
-
5
-/**
6
- *
7
- */
8
-public interface IManagerService {
9
-
10
-    /**
11
-     * 校验用户状态
12
-     * @param id
13
-     * @return
14
-     */
15
-    Boolean verify(String id);
16
-
17
-    /**
18
-     * 获取用户角色
19
-     * @param id
20
-     * @return
21
-     */
22
-    Set<String> getRolesByLoginId(String id);
23
-
24
-    /**
25
-     * 获取用户权限
26
-     * @param id
27
-     * @return
28
-     */
29
-    Set<String> getPermissionsLoginId(String id);
30
-
31
-}

+ 0
- 77
src/main/java/com/yunzhi/nanyang/shiro/realms/manager/ManagerRealm.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.realms.manager;
2
-
3
-import com.auth0.jwt.exceptions.JWTDecodeException;
4
-import com.auth0.jwt.exceptions.TokenExpiredException;
5
-import com.yunzhi.nanyang.shiro.utils.JWTToken;
6
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
7
-import lombok.extern.slf4j.Slf4j;
8
-import org.apache.shiro.authc.*;
9
-import org.apache.shiro.authz.AuthorizationInfo;
10
-import org.apache.shiro.authz.SimpleAuthorizationInfo;
11
-import org.apache.shiro.realm.AuthorizingRealm;
12
-import org.apache.shiro.subject.PrincipalCollection;
13
-
14
-import java.util.Set;
15
-
16
-@Slf4j
17
-public class ManagerRealm extends AuthorizingRealm {
18
-
19
-    IManagerService iManagerService;
20
-
21
-    @Override
22
-    public String getName() {
23
-        return "managerRealm";
24
-    }
25
-
26
-    public void setManagerService(IManagerService iManagerService) {
27
-        this.iManagerService = iManagerService;
28
-    }
29
-
30
-    @Override
31
-    public boolean supports(AuthenticationToken token) {
32
-        return token instanceof JWTToken;
33
-    }
34
-
35
-    @Override
36
-    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
37
-        // 获取用户角色,权限
38
-        String token = (String) principalCollection.getPrimaryPrincipal();
39
-        String loginId = JWTUtil.getLoginId(token);
40
-        Set<String> roles = iManagerService.getRolesByLoginId(loginId);
41
-        Set<String> permissions = iManagerService.getPermissionsLoginId(loginId);
42
-
43
-        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
44
-        simpleAuthorizationInfo.setStringPermissions(permissions);
45
-        simpleAuthorizationInfo.setRoles(roles);
46
-        return simpleAuthorizationInfo;
47
-    }
48
-
49
-    @Override
50
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
51
-        log.info("===========ManagerRealm===========");
52
-
53
-        String token = (String) authenticationToken.getPrincipal();
54
-
55
-        // 这里进行 token 验证, CredentialsMatcher 就不做了
56
-        try {
57
-            JWTUtil.verify(token);
58
-        } catch (JWTDecodeException e1) {
59
-            throw new AuthenticationException("非法的权限凭证");
60
-        } catch (TokenExpiredException e2) {
61
-            throw new ExpiredCredentialsException("授权过期, 请重新登录");
62
-        } catch (Exception e) {
63
-            e.printStackTrace();
64
-            throw new AuthenticationException("凭证校验失败, 请重新登录");
65
-        }
66
-
67
-
68
-        String loginId = JWTUtil.getLoginId(token);
69
-
70
-        if (!iManagerService.verify(loginId)) {
71
-            throw new LockedAccountException("用户不存在或者状态异常");
72
-        }
73
-
74
-        // 交给 AuthenticatingRealm 使用 CredentialsMatcher 行校验
75
-        return new SimpleAuthenticationInfo(token, token, getName());
76
-    }
77
-}

+ 0
- 44
src/main/java/com/yunzhi/nanyang/shiro/realms/miniapp/MiniappRealm.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.realms.miniapp;
2
-
3
-import com.auth0.jwt.exceptions.JWTDecodeException;
4
-import com.auth0.jwt.exceptions.TokenExpiredException;
5
-import com.yunzhi.nanyang.shiro.utils.JWTUtil;
6
-import com.yunzhi.nanyang.shiro.utils.MiniappToken;
7
-import lombok.extern.slf4j.Slf4j;
8
-import org.apache.shiro.authc.*;
9
-import org.apache.shiro.realm.AuthenticatingRealm;
10
-
11
-@Slf4j
12
-public class MiniappRealm extends AuthenticatingRealm {
13
-
14
-    @Override
15
-    public String getName() {
16
-        return "miniappRealm";
17
-    }
18
-
19
-    @Override
20
-    public boolean supports(AuthenticationToken token) {
21
-        return token instanceof MiniappToken;
22
-    }
23
-
24
-    @Override
25
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
26
-        log.info("===========MiniappRealm===========");
27
-
28
-        String token = (String) authenticationToken.getPrincipal();
29
-
30
-        // 这里进行 token 验证, CredentialsMatcher 就不做了
31
-        try {
32
-            JWTUtil.verify(token);
33
-        } catch (JWTDecodeException e1) {
34
-            throw new AuthenticationException("非法的权限凭证");
35
-        } catch (TokenExpiredException e2) {
36
-            throw new ExpiredCredentialsException("授权过期, 请重新登录");
37
-        } catch (Exception e) {
38
-            e.printStackTrace();
39
-            throw new AuthenticationException("凭证校验失败, 请重新登录");
40
-        }
41
-        // 交给 AuthenticatingRealm 使用 CredentialsMatcher 行校验
42
-        return new SimpleAuthenticationInfo(token, token, getName());
43
-    }
44
-}

+ 0
- 23
src/main/java/com/yunzhi/nanyang/shiro/utils/JWTToken.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.utils;
2
-
3
-import org.apache.shiro.authc.AuthenticationToken;
4
-
5
-public class JWTToken implements AuthenticationToken {
6
-
7
-    //Key
8
-    private String token;
9
-
10
-    public JWTToken(String token) {
11
-        this.token = token;
12
-    }
13
-
14
-    @Override
15
-    public Object getPrincipal() {
16
-        return token;
17
-    }
18
-
19
-    @Override
20
-    public Object getCredentials() {
21
-        return token;
22
-    }
23
-}

+ 0
- 66
src/main/java/com/yunzhi/nanyang/shiro/utils/JWTUtil.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.utils;
2
-
3
-import com.auth0.jwt.JWT;
4
-import com.auth0.jwt.algorithms.Algorithm;
5
-import com.auth0.jwt.exceptions.JWTDecodeException;
6
-import com.auth0.jwt.exceptions.JWTVerificationException;
7
-import com.auth0.jwt.interfaces.DecodedJWT;
8
-import com.auth0.jwt.interfaces.JWTVerifier;
9
-
10
-import java.util.Date;
11
-
12
-/**
13
- * 一个通用版本的 JWT
14
- */
15
-public class JWTUtil {
16
-
17
-    // token 生存周期
18
-    private static final long EXPIRE_TIME = 7 * 24 * 60 * 60 * 1000;
19
-
20
-    public static String getLoginId(String token) {
21
-        try {
22
-            DecodedJWT jwt = JWT.decode(token);
23
-            return jwt.getSubject();
24
-        } catch (JWTDecodeException e) {
25
-            return null;
26
-        }
27
-    }
28
-
29
-    public static Date getExpDate(String token) {
30
-        try {
31
-            DecodedJWT jwt = JWT.decode(token);
32
-            return jwt.getExpiresAt();
33
-        } catch (JWTDecodeException e) {
34
-            return null;
35
-        }
36
-    }
37
-
38
-    public static String sign(String loginId, String secret) {
39
-        Date date = new Date(System.currentTimeMillis()+EXPIRE_TIME);
40
-        Algorithm algorithm = Algorithm.HMAC256(secret);
41
-
42
-        return JWT.create()
43
-                .withSubject(loginId)
44
-                .withExpiresAt(date)
45
-                .withClaim("secret", secret)
46
-                .sign(algorithm);
47
-    }
48
-
49
-    public static String refresh(String token) throws Exception {
50
-        DecodedJWT jwt = JWT.decode(token);
51
-        String loginId = jwt.getSubject();
52
-        String secret = jwt.getClaim("secret").asString();
53
-
54
-        return sign(loginId, secret);
55
-    }
56
-
57
-    public static void verify(String token) throws JWTVerificationException {
58
-        DecodedJWT jwt = JWT.decode(token);
59
-        String loginId = jwt.getSubject();
60
-        String secret = jwt.getClaim("secret").asString();
61
-        Algorithm algorithm = Algorithm.HMAC256(secret);
62
-        JWTVerifier verifier = JWT.require(algorithm).withSubject(loginId).build();
63
-        verifier.verify(jwt);
64
-    }
65
-
66
-}

+ 0
- 23
src/main/java/com/yunzhi/nanyang/shiro/utils/MiniappToken.java Parādīt failu

1
-package com.yunzhi.nanyang.shiro.utils;
2
-
3
-import org.apache.shiro.authc.AuthenticationToken;
4
-
5
-public class MiniappToken implements AuthenticationToken {
6
-
7
-    //Key
8
-    private String token;
9
-
10
-    public MiniappToken(String token) {
11
-        this.token = token;
12
-    }
13
-
14
-    @Override
15
-    public Object getPrincipal() {
16
-        return token;
17
-    }
18
-
19
-    @Override
20
-    public Object getCredentials() {
21
-        return token;
22
-    }
23
-}

+ 18
- 17
src/main/resources/application.yml Parādīt failu

4
   servlet:
4
   servlet:
5
     context-path: /api
5
     context-path: /api
6
 
6
 
7
-###
8
-shiro:
9
-  enabled: true
10
-  unauthorizedUrl: /api/401
11
-  filterRuleMap: '{
12
-    "/wxpay/notify/**": "anon",
13
-    "/**/sms-captcha": "anon",
14
-    "/**/**/sms-captcha": "anon",
15
-    "/**/preload": "anon",
16
-    "/**/login": "anon",
17
-    "/**/**/login": "anon",
18
-    "/admin/**": "manager",
19
-    "/wx/**": "miniapp",
20
-    "/android/**": "miniapp",
21
-    "/ios/**": "miniapp",
22
-    "/**": "anon"
23
-  }'
7
+# Sa-Token配置
8
+sa-token:
9
+  # jwt秘钥
10
+  jwt-secret-key: Q920tdPkkDxnSv4dd6cqE6jNDT2OKT7L
11
+  # token名称 (同时也是cookie名称)
12
+  token-name: Authorization
13
+  # token有效期,单位s 默认30天, -1代表永不过期
14
+  timeout: 2592000
15
+  # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
16
+  activity-timeout: -1
17
+  # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
18
+  is-concurrent: true
19
+  # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
20
+  is-share: false
21
+  # token风格
22
+  token-style: uuid
23
+  # 是否输出操作日志
24
+  is-log: false
24
 
25
 
25
 ###
26
 ###
26
 mybatis-plus:
27
 mybatis-plus: