fix: 解决token刷新导致登录超时bug

This commit is contained in:
fit2cloud-chenyw 2021-06-03 14:18:15 +08:00
parent 0a99716b09
commit 23a003787e
2 changed files with 4 additions and 1 deletions

View File

@ -111,7 +111,7 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
// JWTUtils.removeTokenExpire(token); // JWTUtils.removeTokenExpire(token);
String newToken = JWTUtils.sign(tokenInfo, password); String newToken = JWTUtils.sign(tokenInfo, password);
// 记录新token操作时间 // 记录新token操作时间
// JWTUtils.addTokenExpire(newToken); JWTUtils.addTokenExpire(newToken);
JWTToken jwtToken = new JWTToken(newToken); JWTToken jwtToken = new JWTToken(newToken);
this.getSubject(request, response).login(jwtToken); this.getSubject(request, response).login(jwtToken);

View File

@ -158,10 +158,12 @@ public class JWTUtils {
CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class); CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class);
Cache tokens_expire = cacheManager.getCache("tokens_expire"); Cache tokens_expire = cacheManager.getCache("tokens_expire");
Long expTime = tokens_expire.get(token, Long.class); Long expTime = tokens_expire.get(token, Long.class);
// System.out.println("get-------"+token+" :"+expTime);
return expTime; return expTime;
} }
public static void removeTokenExpire(String token){ public static void removeTokenExpire(String token){
// System.out.println("remove----"+token);
CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class); CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class);
Cache tokens_expire = cacheManager.getCache("tokens_expire"); Cache tokens_expire = cacheManager.getCache("tokens_expire");
tokens_expire.evict(token); tokens_expire.evict(token);
@ -171,6 +173,7 @@ public class JWTUtils {
CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class); CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class);
Cache tokens_expire = cacheManager.getCache("tokens_expire"); Cache tokens_expire = cacheManager.getCache("tokens_expire");
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// System.out.println("add-------"+token+" :"+now);
tokens_expire.put(token, now); tokens_expire.put(token, now);
} }