赞
踩
1、springboot 核心依赖最新版本:
Spring Boot 2.3.3
Spring Cloud Hoxton.SR8
Spring Cloud Alibaba 2.2.2
MybatisPlus 3.4.0
Element 2.3.12
2、更新auth认证时,更改,RedisTokenStore记录登录用户,同时保证单点、多点登录,token认证成功之后对于相同的用户信息返回的token值是一样的,不适合在多地同时登录。
重写DefaultAuthenticationKeyGenerator
public class AuthenticationKeyGenerator extends DefaultAuthenticationKeyGenerator {private static final String CLIENT_ID = “client_id”;
private static final String SCOPE = “scope”;
private static final String USERNAME = “username”;
@Override
public String extractKey(OAuth2Authentication authentication) {Map values = new LinkedHashMap();
OAuth2Request authorizationRequest = authentication.getOAuth2Request();
if (!authentication.isClientOnly()) {//在用户名后面添加时间戳,使每次的key都不一样
values.put(USERNAME, authentication.getName()+System.currentTimeMillis());
}values.put(CLIENT_ID, authorizationRequest.getClientId());
if (authorizationRequest.getScope() != null) {values.put(SCOPE, OAuth2Utils.formatParameterList(new TreeSet(authorizationRequest.getScope())));
}return generateKey(values);
}
}
public TokenStore tokenStore() {RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
redisTokenStore.setAuthenticationKeyGenerator(new MyAuthenticationKeyGenerator());
return redisTokenStore;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。