Skip to content

Commit 15e0514

Browse files
committed
优化授权信息参数自动注入
1 parent d2eba56 commit 15e0514

File tree

6 files changed

+24
-52
lines changed

6 files changed

+24
-52
lines changed

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authorization.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
*
3535
* @author zhouhao
3636
* @see AuthorizationHolder
37-
* @see org.hswebframework.web.authorization.annotation.AuthInfo
3837
* @since 3.0
3938
*/
4039
public interface Authorization extends Serializable {

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/annotation/AuthInfo.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

hsweb-examples/hsweb-examples-simple/src/main/java/org/hswebframework/web/example/simple/TestController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.hswebframework.web.authorization.Authorization;
66
import org.hswebframework.web.authorization.AuthorizationHolder;
77
import org.hswebframework.web.authorization.Permission;
8-
import org.hswebframework.web.authorization.annotation.AuthInfo;
98
import org.hswebframework.web.authorization.annotation.Authorize;
109
import org.hswebframework.web.authorization.annotation.RequiresDataAccess;
1110
import org.hswebframework.web.authorization.annotation.RequiresFieldAccess;
@@ -19,7 +18,6 @@
1918
import org.hswebframework.web.entity.authorization.UserEntity;
2019
import org.hswebframework.web.service.QueryByEntityService;
2120
import org.hswebframework.web.service.QueryService;
22-
import org.hswebframwork.utils.ClassUtils;
2321
import org.springframework.web.bind.annotation.*;
2422

2523
import java.util.List;
@@ -36,13 +34,13 @@ public class TestController implements QueryController<UserEntity, String, Query
3634

3735
@GetMapping("/test1")
3836
@Authorize(action = "query", message = "${'表达式方式'}")
39-
public ResponseMessage testSimple(@AuthInfo Authorization authorization) {
37+
public ResponseMessage testSimple(Authorization authorization) {
4038
return ResponseMessage.ok(authorization);
4139
}
4240

4341
@GetMapping("/test")
4442
@RequiresPermissions("test:*")
45-
public ResponseMessage testShiro(@AuthInfo Authorization authorization) {
43+
public ResponseMessage testShiro(Authorization authorization) {
4644
return ResponseMessage.ok(authorization);
4745
}
4846

hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/resolver/AuthorizationArgumentResolver.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,41 @@
1717

1818
package org.hswebframework.web.starter.resolver;
1919

20+
import org.hswebframework.web.authorization.Authorization;
2021
import org.hswebframework.web.authorization.AuthorizationSupplier;
21-
import org.hswebframework.web.authorization.annotation.AuthInfo;
2222
import org.springframework.core.MethodParameter;
23+
import org.springframework.util.Assert;
2324
import org.springframework.web.bind.support.WebDataBinderFactory;
2425
import org.springframework.web.context.request.NativeWebRequest;
2526
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
2627
import org.springframework.web.method.support.ModelAndViewContainer;
2728

2829
/**
29-
* TODO 完成注释
30+
* 权限参数转换器,自动将{@link Authorization}注入controller
31+
* 例如:
32+
* <pre>
33+
* &#064;RequestMapping("/example")
34+
* public ResponseMessage foo(Authorization auth){
35+
* return ok();
36+
* }
37+
* </pre>
3038
*
3139
* @author zhouhao
40+
* @see Authorization
41+
* @since 3.0
3242
*/
3343
public class AuthorizationArgumentResolver implements HandlerMethodArgumentResolver {
3444

3545
AuthorizationSupplier authorizationSupplier;
3646

3747
public AuthorizationArgumentResolver(AuthorizationSupplier authorizationSupplier) {
48+
Assert.notNull(authorizationSupplier);
3849
this.authorizationSupplier = authorizationSupplier;
3950
}
4051

4152
@Override
4253
public boolean supportsParameter(MethodParameter parameter) {
43-
return parameter.hasParameterAnnotation(AuthInfo.class);
54+
return parameter.getParameterType() == Authorization.class;
4455
}
4556

4657
@Override

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/AuthorizationController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public void getVerifyCode(HttpServletResponse response, HttpSession session) thr
9595
verifyCode.write(response.getOutputStream());
9696
}
9797

98+
@RequestMapping("/login-out")
99+
@AccessLogger("退出登录")
100+
public ResponseMessage loginOut() {
101+
102+
return ok();
103+
}
104+
98105
@PostMapping(value = "/login")
99106
@AccessLogger("授权")
100107
public ResponseMessage authorize(@RequestParam String username,

hsweb-system/hsweb-system-authorization/hsweb-system-authorization-controller/src/main/java/org/hswebframework/web/controller/authorization/UserController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.hswebframework.web.controller.authorization;
1919

20-
import org.hswebframework.web.authorization.Permission;
21-
import org.hswebframework.web.authorization.annotation.AuthInfo;
2220
import org.hswebframework.web.authorization.Authorization;
2321
import org.hswebframework.web.authorization.annotation.Authorize;
2422
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
@@ -77,7 +75,7 @@ public ResponseMessage updateByPrimaryKey(@PathVariable String id, @RequestBody
7775
@Authorize(merge = false)
7876
@PutMapping(path = "/password")
7977
@AccessLogger("{update_password_login_user}")
80-
public ResponseMessage updateLoginUserPassword(@AuthInfo Authorization authorization,
78+
public ResponseMessage updateLoginUserPassword(Authorization authorization,
8179
@RequestParam String password,
8280
@RequestParam String oldPassword) {
8381
getService().updatePassword(authorization.getUser().getId(), oldPassword, password);

0 commit comments

Comments
 (0)