关于springboot:springboot-最新稳定版

40次阅读

共计 1211 个字符,预计需要花费 4 分钟才能阅读完成。

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;
}

正文完
 0