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<String, String> values = new LinkedHashMap<String, String>();

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<String>(authorizationRequest.getScope())));

}

    return generateKey(values);

}
}

public TokenStore tokenStore() {

RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);

redisTokenStore.setAuthenticationKeyGenerator(new MyAuthenticationKeyGenerator());
return redisTokenStore;
}


Steven
21 声望3 粉丝

对酒当歌,人生几何,美景之中,举杯畅饮,放下心中的执念,醉一回,痛快一回;一本樱花酒,醉了春风醉了酒。