mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 22:19:29 +08:00
修复OAuth2 服务错误
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
## 拓展接口
|
||||
|
||||
### 行级权限控制器
|
||||
### 数据级权限控制器
|
||||
|
||||
控制逻辑简述:
|
||||
|
||||
@@ -33,3 +33,4 @@
|
||||
|
||||
|
||||
注意: 控制需满足的条件请查看控制器源代码查看注释获取
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
/*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
@@ -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,3 +1,3 @@
|
||||
# Auto Configure
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.hswebframework.web.oauth2.server.simple.OAuth2GranterAutoConfiguration
|
||||
org.hswebframework.web.oauth2.OAuth2GranterAutoConfiguration
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user