-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用户禁用token更新问题 #5
Comments
token信息是存redis里面的,更新用户信息的时候重存下信息就可以了,可以参考下controller下面的updateCacheUserInfo方法。 |
|
我测试了下,校验token的时候它只会校验token的合法性,不会去校验用户信息的,虽然不能校验用户信息,不过可以移除token,致使token过期,重新登录就会提示禁用。 @GetMapping("/update2")
public @ResponseBody String updateUserInfo() {
Collection<OAuth2AccessToken> tokensByClientIdAndUserName =
tokenStore.findTokensByClientIdAndUserName("yaohw", "yaohw");
if (tokensByClientIdAndUserName != null) {
tokensByClientIdAndUserName.forEach(t -> {
consumerTokenServices.revokeToken(t.getValue());
});
}
return "ok";
} |
如果一定要在校验token的同时也校验用户信息可以自定义写一个过滤器实现。 |
还有个问题多种模式下,username字段得保持唯一吧,不然在存储token的时候同样的username,后面的登录的人始终使用第一个相同username登录生成的accesstoken导致获取用户信息也是第一个人 |
默认RedisTokenStore.java生成token的key是username + clientId+非空scope经过MD5加密后的结果,也就是说默认情况下username、clientId、scope相同,那么他们使用同一个token,第一次登录成功,第二次登录根据三者组成的key去redis取,发现已存在,则直接返回已存在的token,不再重新生成。 上面说的是默认情况下是通过 RedisTokenStore.java下DefaultAuthenticationKeyGenerator.java实现的,如果需要自定义,可以在配置 RedisTokenStore的时候设置一个自定义的AuthenticationKeyGenerator。 /**
* 配置token存储,这个配置token存到redis中
* @return
*/
@Bean
public TokenStore tokenStore() {
RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
redisTokenStore.setAuthenticationKeyGenerator(“自定义AuthenticationKeyGenerator”);
return redisTokenStore;
} |
private AuthenticationKeyGenerator keyGenerator() {
return new AuthenticationKeyGenerator() {
/**
* @param authentication an OAuth2Authentication
* @return a unique key identifying the authentication
*/
@Override
public String extractKey(OAuth2Authentication authentication) {
OAuth2Request oAuth2Request = authentication.getOAuth2Request();
String clientId = oAuth2Request.getClientId();
UserDetailImpl principal = (UserDetailImpl)authentication.getPrincipal();
log.info("用户信息:{}", principal);
return principal.getId() + clientId;
}
};
} |
用户被禁用的后,如果刷新token信息
The text was updated successfully, but these errors were encountered: