use of org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore in project new-cloud by xie-summer.
the class UserController method removeToken.
/**
* 清除Redis中 accesstoken refreshtoken
*
* @param accesstoken accesstoken
* @param refreshToken refreshToken
* @return true/false
*/
@PostMapping("/removeToken")
@CacheEvict(value = SecurityConstants.TOKEN_USER_DETAIL, key = "#accesstoken")
public R<Boolean> removeToken(String accesstoken, String refreshToken) {
RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
tokenStore.removeRefreshToken(refreshToken);
tokenStore.removeAccessToken(accesstoken);
return new R<>(Boolean.TRUE);
}
use of org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore in project fw-cloud-framework by liuweijw.
the class FwAuthorizationConfiguration method redisTokenStore.
/**
* tokenstore 定制化处理 1. 如果使用的 redis-cluster 模式请使用 FwRedisTokenStore FwRedisTokenStore tokenStore = new
* FwRedisTokenStore();
* tokenStore.setRedisTemplate(redisTemplate);
*/
@Bean
public TokenStore redisTokenStore() {
RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
tokenStore.setPrefix(SecurityConstant.PREFIX);
return tokenStore;
}
use of org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore in project fw-cloud-framework by liuweijw.
the class FwAuthorizationConfiguration method configure.
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), jwtAccessTokenConverter()));
endpoints.tokenStore(redisTokenStore()).tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager).reuseRefreshTokens(false).userDetailsService(userDetailsService);
}
use of org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore in project fw-cloud-framework by liuweijw.
the class PermissionServiceImpl method hasPermission.
@SuppressWarnings("unchecked")
@Override
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
// options 跨域配置,现在处理是通过前端配置代理,不使用这种方式,存在风险
/*
* if (HttpMethod.OPTIONS.name().equalsIgnoreCase(request.getMethod())) { return true; }
*/
Object principal = authentication.getPrincipal();
List<SimpleGrantedAuthority> grantedAuthorityList = (List<SimpleGrantedAuthority>) authentication.getAuthorities();
boolean hasPermission = false;
if (null == principal)
return hasPermission;
if (CollectionUtils.isEmpty(grantedAuthorityList))
return hasPermission;
String token = JwtUtil.getToken(request);
if (null == token) {
log.warn("==> gateway|permissionService 未获取到Header Authorization");
return hasPermission;
}
if (!"anonymousUser".equals(principal.toString())) {
RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
tokenStore.setPrefix(SecurityConstant.PREFIX);
OAuth2AccessToken accessToken = tokenStore.readAccessToken(token);
if (null == accessToken || accessToken.isExpired()) {
log.warn("==> gateway|permissionService token 过期或者不存在");
return hasPermission;
}
}
// 接口层面做了缓存处理,后续可以继续优化
Set<AuthPermission> permissions = new HashSet<AuthPermission>();
for (SimpleGrantedAuthority authority : grantedAuthorityList) {
permissions.addAll(permissionFeignApi.findMenuByRole(authority.getAuthority()));
}
// 网关处理是否拥有菜单权限,菜单下的功能权限校验由调用子模块负责
String requestURI = request.getRequestURI();
for (AuthPermission menu : permissions) {
if (StringHelper.isNotEmpty(menu.getUrl()) && antPathMatcher.match(menu.getUrl(), requestURI)) {
hasPermission = true;
break;
}
}
return hasPermission;
}
Aggregations