From 3cc66f911c6a7b0d55ddb58c67e16963195ea351 Mon Sep 17 00:00:00 2001
From: zhaoxiaohao <279049017@qq.com>
Date: Mon, 08 Mar 2021 18:42:39 +0800
Subject: [PATCH] 账号强制被踢出登录状态逻辑的优化

---
 kidgrow-uaa/kidgrow-uaa-server/src/main/java/com/kidgrow/oauth2/handler/SingleTokenServices.java |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/kidgrow-uaa/kidgrow-uaa-server/src/main/java/com/kidgrow/oauth2/handler/SingleTokenServices.java b/kidgrow-uaa/kidgrow-uaa-server/src/main/java/com/kidgrow/oauth2/handler/SingleTokenServices.java
index 1c97969..4fe6897 100644
--- a/kidgrow-uaa/kidgrow-uaa-server/src/main/java/com/kidgrow/oauth2/handler/SingleTokenServices.java
+++ b/kidgrow-uaa/kidgrow-uaa-server/src/main/java/com/kidgrow/oauth2/handler/SingleTokenServices.java
@@ -19,6 +19,7 @@
 import org.springframework.security.oauth2.provider.*;
 import org.springframework.security.oauth2.provider.token.*;
 import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
+//import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
@@ -30,7 +31,7 @@
 @Deprecated
 public class SingleTokenServices implements AuthorizationServerTokenServices, ResourceServerTokenServices, ConsumerTokenServices, InitializingBean {
     private int refreshTokenValiditySeconds = 2592000;
-    private int accessTokenValiditySeconds = 3600;//43200
+    private int accessTokenValiditySeconds = 10800;//43200   //登录时,给的默认值;一段时间后,用的查询数据库中的oauth_client_details的表的access_token_validity;
     private boolean supportRefreshToken = false;
     private boolean reuseRefreshToken = true;
     private TokenStore tokenStore;
@@ -166,14 +167,14 @@
     public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException, InvalidTokenException {
         OAuth2AccessToken accessToken = this.tokenStore.readAccessToken(accessTokenValue);
         if (accessToken == null) {
-            throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
+            throw new InvalidTokenException("Invalid access token:1 " + accessTokenValue);
         } else if (accessToken.isExpired()) {
             this.tokenStore.removeAccessToken(accessToken);
             throw new InvalidTokenException("Access token expired: " + accessTokenValue);
         } else {
             OAuth2Authentication result = this.tokenStore.readAuthentication(accessToken);
             if (result == null) {
-                throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
+                throw new InvalidTokenException("Invalid access token:2 " + accessTokenValue);
             } else {
                 if (this.clientDetailsService != null) {
                     String clientId = result.getOAuth2Request().getClientId();
@@ -193,7 +194,7 @@
     public String getClientId(String tokenValue) {
         OAuth2Authentication authentication = this.tokenStore.readAuthentication(tokenValue);
         if (authentication == null) {
-            throw new InvalidTokenException("Invalid access token: " + tokenValue);
+            throw new InvalidTokenException("Invalid access token:3 " + tokenValue);
         } else {
             OAuth2Request clientAuth = authentication.getOAuth2Request();
             if (clientAuth == null) {

--
Gitblit v1.8.0