From 1e4da418f442e3b25d0c302bb9e833ac60a8df73 Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Thu, 30 Nov 2017 22:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorization/annotation/RequiresDataAccess.java | 2 ++ .../define/AuthorizeDefinitionInitializedEvent.java | 2 ++ hsweb-authorization/hsweb-authorization-basic/pom.xml | 5 +++++ .../basic/define/DefaultBasicAuthorizeDefinition.java | 9 +++++---- .../additional-spring-configuration-metadata.json | 10 ++++++++++ hsweb-examples/hsweb-examples-simple/pom.xml | 5 +++++ .../src/main/resources/application.yml | 3 ++- .../mybatis/mappers/authorization/PermissionMapper.xml | 3 ++- .../web/entity/authorization/ActionEntity.java | 9 +++++++++ .../hsweb-system-authorization-starter/pom.xml | 6 ++++++ .../additional-spring-configuration-metadata.json | 10 ++++++++++ .../controller/OAuth2ServerConfigController.java | 2 +- .../oauth2/controller/OAuth2UserTokenController.java | 2 +- .../controller/OAuth2ClientConfigController.java | 2 +- 14 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 hsweb-authorization/hsweb-authorization-basic/src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/annotation/RequiresDataAccess.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/annotation/RequiresDataAccess.java index 22f0a8f7e..d62ad822b 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/annotation/RequiresDataAccess.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/annotation/RequiresDataAccess.java @@ -53,6 +53,8 @@ public @interface RequiresDataAccess { */ String[] action() default {}; + String[] supportType() default {}; + /** * @return logical */ diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java index 778b4887e..5937c6bdf 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java @@ -6,6 +6,8 @@ import org.springframework.context.ApplicationEvent; import java.util.List; public class AuthorizeDefinitionInitializedEvent extends ApplicationEvent implements AuthorizationEvent { + private static final long serialVersionUID = -8185138454949381441L; + public AuthorizeDefinitionInitializedEvent(List all) { super(all); } diff --git a/hsweb-authorization/hsweb-authorization-basic/pom.xml b/hsweb-authorization/hsweb-authorization-basic/pom.xml index e66f5c657..40acc02b7 100644 --- a/hsweb-authorization/hsweb-authorization-basic/pom.xml +++ b/hsweb-authorization/hsweb-authorization-basic/pom.xml @@ -26,6 +26,11 @@ spring-boot-starter-aop + + org.springframework.boot + spring-boot-configuration-processor + true + org.springframework spring-webmvc diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java index c2209704d..e0c95f34d 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java @@ -13,6 +13,7 @@ import org.hswebframework.web.authorization.define.Script; import java.util.Arrays; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; /** @@ -33,13 +34,13 @@ public class DefaultBasicAuthorizeDefinition implements AuthorizeDefinition { private String[] actionDescription = {}; - private Set permissions = new HashSet<>(); + private Set permissions = new LinkedHashSet<>(); - private Set actions = new HashSet<>(); + private Set actions = new LinkedHashSet<>(); - private Set roles = new HashSet<>(); + private Set roles = new LinkedHashSet<>(); - private Set user = new HashSet<>(); + private Set user = new LinkedHashSet<>(); private Script script; diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/hsweb-authorization/hsweb-authorization-basic/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 000000000..8ff52ffec --- /dev/null +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,10 @@ +{ + "properties": [ + { + "name": "hsweb.authorize.auto-parse", + "type": "java.lang.Boolean", + "defaultValue": "false", + "description": "是否自动解析代码中的权限定义信息并触发AuthorizeDefinitionInitializedEvent事件." + } + ] +} \ No newline at end of file diff --git a/hsweb-examples/hsweb-examples-simple/pom.xml b/hsweb-examples/hsweb-examples-simple/pom.xml index 2c0ea90b2..470bc7f5c 100644 --- a/hsweb-examples/hsweb-examples-simple/pom.xml +++ b/hsweb-examples/hsweb-examples-simple/pom.xml @@ -155,6 +155,11 @@ hsweb-system-oauth2-server-starter ${project.version} + + org.springframework.boot + spring-boot-configuration-processor + true + io.springfox diff --git a/hsweb-examples/hsweb-examples-simple/src/main/resources/application.yml b/hsweb-examples/hsweb-examples-simple/src/main/resources/application.yml index c496acd28..d911fca91 100644 --- a/hsweb-examples/hsweb-examples-simple/src/main/resources/application.yml +++ b/hsweb-examples/hsweb-examples-simple/src/main/resources/application.yml @@ -21,7 +21,8 @@ hsweb: allowed-methods: "*" allowed-headers: "*" authorize: - auto-parse: true + auto-parse: true # 自动解析所有代码中到权限,并触发 ApplicationListener + sync: true # 自动同步权限信息到数据库 jwt: id: test secret: dGVzdA== diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml index fead9ee06..1f970d437 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml @@ -29,7 +29,8 @@ - + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java index ddf5ff98d..623678339 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java @@ -39,4 +39,13 @@ public class ActionEntity implements CloneableEntity { return Arrays.stream(actions).map(ActionEntity::new).collect(Collectors.toList()); } + @Override + public int hashCode() { + return getAction().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof ActionEntity && obj.hashCode() == hashCode(); + } } \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml index 342dc22a6..193a50db5 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml @@ -54,6 +54,12 @@ ${project.version} + + org.springframework.boot + spring-boot-configuration-processor + true + + com.h2database h2 diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 000000000..f4cdedd8a --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,10 @@ +{ + "properties": [ + { + "name": "hsweb.authorize.sync", + "type": "java.lang.Boolean", + "defaultValue": "false", + "description": "是否自动将解析的权限定义信息同步到数据库,需满足hsweb.authorize.auto-parse=true." + } + ] +} \ No newline at end of file diff --git a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ServerConfigController.java b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ServerConfigController.java index e7849df7c..26b9f6716 100644 --- a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ServerConfigController.java +++ b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ServerConfigController.java @@ -36,7 +36,7 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @RequestMapping("${hsweb.web.mappings.oauth2-server-config:oauth2-server-config}") -@Authorize(permission = "oauth2-server-config") +@Authorize(permission = "oauth2-server-config",description = "OAuth2.0-客户端-服务配置") @Api(tags = "OAuth2.0-客户端-服务配置",value = "OAuth2.0-客户端-服务配置") public class OAuth2ServerConfigController implements GenericEntityController { diff --git a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2UserTokenController.java b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2UserTokenController.java index 2212bc436..6cb1206ac 100644 --- a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2UserTokenController.java +++ b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2UserTokenController.java @@ -37,7 +37,7 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @RequestMapping("${hsweb.web.mappings.oauth2-user-token:oauth2-user-token}") -@Authorize(permission = "oauth2-user-token") +@Authorize(permission = "oauth2-user-token",description = "OAuth2.0-客户端-token管理") @Api(tags = "OAuth2.0-客户端-token",value = "OAuth2.0-客户端-token") public class OAuth2UserTokenController implements QueryController { diff --git a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java index 53db19cf4..075bed530 100644 --- a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java +++ b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-controller/src/main/java/org/hswebframework/web/authorization/oauth2/controller/OAuth2ClientConfigController.java @@ -18,7 +18,7 @@ import java.util.List; @RestController @RequestMapping("/oauth2/client/config") @Api(tags = "OAuth2.0-服务-客户端管理", value = "OAuth2.0-服务-客户端管理") -@Authorize(permission = "oauth2-client-config", description = "OAuth2.0客户端管理") +@Authorize(permission = "oauth2-client-config", description = "OAuth2.0-服务-客户端管理") public class OAuth2ClientConfigController { @Autowired