Ver código fonte

修复OAuth2 服务错误

zhouhao 8 anos atrás
pai
commit
00cfb22d09
10 arquivos alterados com 47 adições e 11 exclusões
  1. 2 1
      hsweb-authorization/hsweb-authorization-shiro/README.md
  2. 3 2
      hsweb-authorization/hsweb-authorization-shiro/src/main/java/org/hswebframework/web/authorization/shiro/boost/handler/FieldFilterDataAccessHandler.java
  3. 1 0
      hsweb-examples/hsweb-examples-simple/src/main/java/org/hswebframework/web/example/simple/TestController.java
  4. 3 0
      hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/SystemInitializeAutoConfiguration.java
  5. 1 1
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-dao/hsweb-system-oauth2-server-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/oauth2/OAuth2ClientMapper.xml
  6. 3 3
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-entity/src/main/java/org/hswebframework/web/authorization/oauth2/server/entity/SimpleOAuth2ClientEntity.java
  7. 8 1
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-simple/src/main/java/org/hswebframework/web/oauth2/server/simple/OAuth2GranterAutoConfiguration.java
  8. 23 0
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/java/org/hswebframework/web/oauth2/OAuth2ServerErrorControllerAdvice.java
  9. 1 1
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/resources/META-INF/spring.factories
  10. 2 2
      hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/resources/hsweb-starter.js

+ 2 - 1
hsweb-authorization/hsweb-authorization-shiro/README.md

@@ -13,7 +13,7 @@
 
 ## 拓展接口
 
-### 级权限控制器
+### 数据级权限控制器
 
 控制逻辑简述:
 
@@ -33,3 +33,4 @@
 
 
 注意: 控制需满足的条件请查看控制器源代码查看注释获取
+

+ 3 - 2
hsweb-authorization/hsweb-authorization-shiro/src/main/java/org/hswebframework/web/authorization/shiro/boost/handler/FieldFilterDataAccessHandler.java

@@ -13,7 +13,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * TODO 完成注释
+ * 数据权限字段过滤处理,目前仅支持deny. {@link DataAccessConfig.DefaultType#DENY_FIELDS}
  *
  * @author zhouhao
  */
@@ -22,12 +22,13 @@ public class FieldFilterDataAccessHandler implements DataAccessHandler {
 
     @Override
     public boolean isSupport(DataAccessConfig access) {
-        return access instanceof FieldFilterDataAccessConfig;
+        return access instanceof FieldFilterDataAccessConfig && DataAccessConfig.DefaultType.DENY_FIELDS.equals(access.getType());
     }
 
     @Override
     public boolean handle(DataAccessConfig access, MethodInterceptorParamContext context) {
         FieldFilterDataAccessConfig filterDataAccessConfig = ((FieldFilterDataAccessConfig) access);
+
         switch (access.getAction()) {
             case Permission.ACTION_QUERY:
                 return doQueryAccess(filterDataAccessConfig, context);

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

@@ -49,6 +49,7 @@ public class TestController implements QueryController<UserEntity, String, Query
     @Authorize
     @RequiresDataAccess(permission = "test", action = Permission.ACTION_QUERY)
     @ApiOperation("测试查询")
+    @AccessLogger("查询")
     public ResponseMessage<QueryParamEntity> testQuery(QueryParamEntity entity) {
 
         /*

+ 3 - 0
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/SystemInitializeAutoConfiguration.java

@@ -35,6 +35,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
 
 import javax.annotation.PostConstruct;
 import javax.sql.DataSource;
@@ -45,6 +47,7 @@ import java.sql.Connection;
  */
 @Configuration
 @EnableConfigurationProperties(AppProperties.class)
+@Order(Ordered.HIGHEST_PRECEDENCE)
 public class SystemInitializeAutoConfiguration implements CommandLineRunner {
 
     @Autowired

+ 1 - 1
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-dao/hsweb-system-oauth2-server-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/oauth2/OAuth2ClientMapper.xml

@@ -32,7 +32,7 @@
         <result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
         <result property="redirectUri" column="redirect_uri" javaType="String" jdbcType="VARCHAR"/>
         <result property="createTime" column="create_time" javaType="Long" jdbcType="NUMERIC"/>
-        <result property="supportGrantType" column="support_grant_type" javaType="java.util.Set" jdbcType="VARCHAR"/>
+        <result property="supportGrantTypes" column="support_grant_types" javaType="java.util.Set" jdbcType="VARCHAR"/>
         <result property="defaultGrantScope" column="default_grant_scope" javaType="java.util.Set" jdbcType="VARCHAR"/>
         <result property="status" column="status" javaType="Byte" jdbcType="NUMERIC"/>
     </resultMap>

+ 3 - 3
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-entity/src/main/java/org/hswebframework/web/authorization/oauth2/server/entity/SimpleOAuth2ClientEntity.java

@@ -42,7 +42,7 @@ public class SimpleOAuth2ClientEntity extends SimpleGenericEntity<String> implem
 
     private String describe;
 
-    private Set<String> supportGrantType;
+    private Set<String> supportGrantTypes;
 
     private Set<String> defaultGrantScope;
 
@@ -122,12 +122,12 @@ public class SimpleOAuth2ClientEntity extends SimpleGenericEntity<String> implem
 
     @Override
     public Set<String> getSupportGrantTypes() {
-        return supportGrantType;
+        return supportGrantTypes;
     }
 
     @Override
     public void setSupportGrantTypes(Set<String> supportGrantType) {
-        this.supportGrantType = supportGrantType;
+        this.supportGrantTypes = supportGrantType;
     }
 
     @Override

+ 8 - 1
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-simple/src/main/java/org/hswebframework/web/oauth2/server/simple/OAuth2GranterAutoConfiguration.java

@@ -16,7 +16,7 @@
  *
  */
 
-package org.hswebframework.web.oauth2.server.simple;
+package org.hswebframework.web.oauth2;
 
 import org.hswebframework.web.authorization.oauth2.server.client.OAuth2ClientService;
 import org.hswebframework.web.authorization.oauth2.server.support.AbstractAuthorizationService;
@@ -36,6 +36,7 @@ import org.hswebframework.web.commons.entity.factory.EntityFactory;
 import org.hswebframework.web.dao.oauth2.AuthorizationCodeDao;
 import org.hswebframework.web.dao.oauth2.OAuth2AccessDao;
 import org.hswebframework.web.dao.oauth2.OAuth2ClientDao;
+import org.hswebframework.web.oauth2.server.simple.*;
 import org.hswebframework.web.service.authorization.UserService;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -60,6 +61,12 @@ public class OAuth2GranterAutoConfiguration {
     @Autowired(required = false)
     private TokenGenerator tokenGenerator;
 
+    @Bean
+    public OAuth2ServerErrorControllerAdvice oAuth2ServerErrorControllerAdvice() {
+        return new OAuth2ServerErrorControllerAdvice();
+    }
+
+
     @ConditionalOnMissingBean(AuthorizationCodeService.class)
     @Bean
     public SimpleAuthorizationCodeService simpleAuthorizationCodeService(AuthorizationCodeDao authorizationCodeDao,

+ 23 - 0
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/java/org/hswebframework/web/oauth2/OAuth2ServerErrorControllerAdvice.java

@@ -0,0 +1,23 @@
+package org.hswebframework.web.oauth2;
+
+import org.hswebframework.web.authorization.oauth2.server.exception.GrantTokenException;
+import org.hswebframework.web.controller.message.ResponseMessage;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+/**
+ * TODO 完成注释
+ *
+ * @author zhouhao
+ */
+@RestControllerAdvice
+public class OAuth2ServerErrorControllerAdvice {
+
+    @ExceptionHandler(GrantTokenException.class)
+    @ResponseStatus(HttpStatus.OK)
+    public ResponseMessage<String> error(GrantTokenException e) {
+        return ResponseMessage.error(e.getErrorType().code(), e.getErrorType().message());
+    }
+}

+ 1 - 1
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/resources/META-INF/spring.factories

@@ -1,3 +1,3 @@
 # Auto Configure
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.hswebframework.web.oauth2.server.simple.OAuth2GranterAutoConfiguration
+org.hswebframework.web.oauth2.OAuth2GranterAutoConfiguration

+ 2 - 2
hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/src/main/resources/hsweb-starter.js

@@ -47,7 +47,7 @@ function install(context) {
         .addColumn().name("creator_id").varchar(32).notNull().comment("创建者ID").commit()
         .addColumn().name("redirect_uri").varchar(1024).notNull().comment("redirect_uri").commit()
         .addColumn().name("create_time").number(32).notNull().comment("创建时间").commit()
-        .addColumn().name("support_grant_type").clob().notNull().comment("支持的授权列表").commit()
+        .addColumn().name("support_grant_types").varchar(2048).comment("支持的授权列表").commit()
         .addColumn().name("default_expires_in").number(16).comment("默认认证过期时间").commit()
         .addColumn().name("default_grant_scope").clob().comment("默认认证范围").commit()
         .addColumn().name("status").number(4).comment("状态").commit()
@@ -61,7 +61,7 @@ function install(context) {
         .addColumn().name("refresh_token").varchar(32).notNull().comment("用于更新授权的token").commit()
         .addColumn().name("create_time").number(32).notNull().comment("创建时间").commit()
         .addColumn().name("update_time").number(32).comment("更新时间").commit()
-        .addColumn().name("scope").clob().notNull().comment("授权范围").commit()
+        .addColumn().name("scope").clob().comment("授权范围").commit()
         .comment("OAuth2授权认证信息").commit();
 
     database.createOrAlter("s_oauth2_auth_code")