Commit 7bef1cf6 by yuwei

项目初始化

parent d3cbdf30
......@@ -118,10 +118,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
return (accessToken, authentication) -> {
final Map<String, Object> additionalInfo = new HashMap<>();
DataUser user = (DataUser) authentication.getUserAuthentication().getPrincipal();
additionalInfo.put(DataConstant.DETAILS_SECURITY_LICENSE, "datax");
additionalInfo.put(DataConstant.DETAILS_SECURITY_USER_ID, user.getId());
additionalInfo.put(DataConstant.DETAILS_SECURITY_USERNAME, user.getUsername());
additionalInfo.put(DataConstant.DETAILS_SECURITY_NICKNAME, user.getNickname());
additionalInfo.put(DataConstant.UserAdditionalInfo.LICENSE.getKey(), "datax");
additionalInfo.put(DataConstant.UserAdditionalInfo.USERID.getKey(), user.getId());
additionalInfo.put(DataConstant.UserAdditionalInfo.USERNAME.getKey(), user.getUsername());
additionalInfo.put(DataConstant.UserAdditionalInfo.NICKNAME.getKey(), user.getNickname());
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
return accessToken;
};
......
......@@ -54,10 +54,11 @@ public class DataUserDetailService implements UserDetailsService {
UserVo userVo = userInfo.getUserVo();
List<RoleVo> roles = userVo.getRoles();
if (CollUtil.isNotEmpty(roles)) {
roles.stream().filter(roleVo -> DataConstant.TRUE == roleVo.getStatus() && StrUtil.isNotBlank(roleVo.getRoleCode())).forEach(roleVo -> authsSet.add(DataConstant.ROLE + roleVo.getRoleCode()));
roles.stream().filter(roleVo -> DataConstant.EnableState.ENABLE.getKey() == roleVo.getStatus() && StrUtil.isNotBlank(roleVo.getRoleCode()))
.forEach(roleVo -> authsSet.add(DataConstant.Security.ROLEPREFIX.getVal() + roleVo.getRoleCode()));
}
if(CollUtil.isEmpty(authsSet)){
authsSet.add(DataConstant.ROLE + "USER");
authsSet.add(DataConstant.Security.ROLEPREFIX.getVal() + "USER");
}
Collection<? extends GrantedAuthority> authorities
= AuthorityUtils.createAuthorityList(authsSet.toArray(new String[0]));
......
......@@ -105,34 +105,4 @@ public class DataConstant {
return val;
}
}
/**
* Gateway请求头TOKEN名称(不要有空格)
*/
public static final String GATEWAY_TOKEN_HEADER = "GatewayToken";
/**
* Gateway请求头TOKEN值
*/
public static final String GATEWAY_TOKEN_VALUE = "datax:gateway:123456";
/**
* OAUTH2 令牌类型
*/
public static final String OAUTH2_TOKEN_TYPE = "bearer ";
public static String ROLE = "ROLE_";
public static int TRUE = 1;
public static int FALSE = 0;
public static String DETAILS_SECURITY_LICENSE = "license";
public static String DETAILS_SECURITY_DATAX_USER = "datax_user";
public static String DETAILS_SECURITY_USER_ID = "user_id";
public static String DETAILS_SECURITY_USERNAME = "username";
public static String DETAILS_SECURITY_NICKNAME = "nickname";
public static String DETAILS_SECURITY_USER_DEPT = "user_dept";
public static String DETAILS_SECURITY_USER_ROLE = "user_role";
public static String DETAILS_SECURITY_USER_POST = "user_post";
}
......@@ -16,13 +16,13 @@ public class DataFeignRequestInterceptor {
public RequestInterceptor oauth2FeignRequestInterceptor() {
return requestTemplate -> {
// 请求头中添加 Gateway Token
String zuulToken = new String(Base64Utils.encode(DataConstant.GATEWAY_TOKEN_VALUE.getBytes()));
requestTemplate.header(DataConstant.GATEWAY_TOKEN_HEADER, zuulToken);
String zuulToken = new String(Base64Utils.encode(DataConstant.Security.TOKENVALUE.getVal().getBytes()));
requestTemplate.header(DataConstant.Security.TOKENHEADER.getVal(), zuulToken);
// 请求头中添加原请求头中的 Token
Object details = SecurityContextHolder.getContext().getAuthentication().getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
String authorizationToken = ((OAuth2AuthenticationDetails) details).getTokenValue();
requestTemplate.header(HttpHeaders.AUTHORIZATION, DataConstant.OAUTH2_TOKEN_TYPE + authorizationToken);
requestTemplate.header(HttpHeaders.AUTHORIZATION, DataConstant.Security.TOKENTYPE.getVal() + authorizationToken);
}
};
}
......
......@@ -16,11 +16,11 @@ public class DataServerProtectInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
// 从请求头中获取 Zuul Token
String token = request.getHeader(DataConstant.GATEWAY_TOKEN_HEADER);
String zuulToken = new String(Base64Utils.encode(DataConstant.GATEWAY_TOKEN_VALUE.getBytes()));
// 校验 Zuul Token的正确性
if (StrUtil.equals(zuulToken, token)) {
// 从请求头中获取Token
String token = request.getHeader(DataConstant.Security.TOKENHEADER.getVal());
String gatewayToken = new String(Base64Utils.encode(DataConstant.Security.TOKENVALUE.getVal().getBytes()));
// 校验Token的正确性
if (StrUtil.equals(gatewayToken, token)) {
return true;
} else {
ResponseUtil.makeResponse(
......
......@@ -42,9 +42,9 @@ public class DataUserAuthenticationConverter implements UserAuthenticationConver
Object principal = map.get(USERNAME);
Collection<? extends GrantedAuthority> authorities = this.getAuthorities(map);
String id = (String) map.get(DataConstant.DETAILS_SECURITY_USER_ID);
String username = (String) map.get(DataConstant.DETAILS_SECURITY_USERNAME);
String nickname = (String) map.get(DataConstant.DETAILS_SECURITY_USERNAME);
String id = (String) map.get(DataConstant.UserAdditionalInfo.USERID.getKey());
String username = (String) map.get(DataConstant.UserAdditionalInfo.USERNAME.getKey());
String nickname = (String) map.get(DataConstant.UserAdditionalInfo.NICKNAME.getKey());
DataUser user = new DataUser(id, nickname, username, N_A, true
, true, true, true, authorities);
return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
......
......@@ -36,8 +36,8 @@ feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
connectTimeout: 10000
readTimeout: 10000
compression:
request:
enabled: true
......
......@@ -31,9 +31,9 @@ public class DataGatewayRequestFilter implements GlobalFilter {
printLog(exchange);
byte[] token = Base64Utils.encode((DataConstant.GATEWAY_TOKEN_VALUE).getBytes());
byte[] token = Base64Utils.encode((DataConstant.Security.TOKENVALUE.getVal()).getBytes());
String[] headerValues = {new String(token)};
ServerHttpRequest build = request.mutate().header(DataConstant.GATEWAY_TOKEN_HEADER, headerValues).build();
ServerHttpRequest build = request.mutate().header(DataConstant.Security.TOKENHEADER.getVal(), headerValues).build();
ServerWebExchange newExchange = exchange.mutate().request(build).build();
return chain.filter(newExchange);
}
......
......@@ -148,7 +148,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
if(CollUtil.isNotEmpty(userVo.getRoles())){
Set<String> permissions = new HashSet<>();
List<String> roleIds = userVo.getRoles().stream()
.filter(roleVo -> DataConstant.TRUE == roleVo.getStatus())
.filter(roleVo -> DataConstant.EnableState.ENABLE.getKey() == roleVo.getStatus())
.map(RoleVo::getId).collect(Collectors.toList());
List<MenuEntity> menuEntitys = menuDao.selectMenuByRoleIds(roleIds);
if(CollUtil.isNotEmpty(menuEntitys)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment