|
@@ -19,12 +19,15 @@ import org.springframework.security.authentication.BadCredentialsException;
|
19
|
19
|
import org.springframework.security.core.Authentication;
|
20
|
20
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
21
|
21
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
22
|
+import org.springframework.security.oauth2.common.OAuth2RefreshToken;
|
22
|
23
|
import org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException;
|
23
|
24
|
import org.springframework.security.oauth2.provider.*;
|
24
|
25
|
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
|
|
26
|
+import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
|
25
|
27
|
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
|
26
|
28
|
import org.springframework.stereotype.Component;
|
27
|
29
|
|
|
30
|
+import javax.annotation.Resource;
|
28
|
31
|
import javax.servlet.ServletException;
|
29
|
32
|
import javax.servlet.http.HttpServletRequest;
|
30
|
33
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -54,6 +57,8 @@ public class CustomAuthenticationSuccessHandler extends SavedRequestAwareAuthent
|
54
|
57
|
private SysConfigService configService;
|
55
|
58
|
@Autowired
|
56
|
59
|
private RedisCache redisCache;
|
|
60
|
+ @Resource
|
|
61
|
+ private RedisTokenStore redisTokenStore;
|
57
|
62
|
|
58
|
63
|
@Override
|
59
|
64
|
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
|
@@ -84,6 +89,12 @@ public class CustomAuthenticationSuccessHandler extends SavedRequestAwareAuthent
|
84
|
89
|
TokenRequest tokenRequest = new TokenRequest(MapUtils.EMPTY_MAP, clientId, clientDetails.getScope(), "custom");
|
85
|
90
|
OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails);
|
86
|
91
|
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication);
|
|
92
|
+ OAuth2AccessToken oldToken = authorizationServerTokenServices.getAccessToken(oAuth2Authentication);
|
|
93
|
+ if (oldToken != null){
|
|
94
|
+ OAuth2RefreshToken auth2RefreshToken = oldToken.getRefreshToken();
|
|
95
|
+ redisTokenStore.removeAccessToken(oldToken);
|
|
96
|
+ redisTokenStore.removeRefreshToken(auth2RefreshToken);
|
|
97
|
+ }
|
87
|
98
|
OAuth2AccessToken token = authorizationServerTokenServices.createAccessToken(oAuth2Authentication);
|
88
|
99
|
|
89
|
100
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(request, Constants.LOGIN_SUCCESS, "登录成功"));
|