From 63002eefffdc6adcf014e0185d1f1b162599b6f2 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 3 Jun 2021 16:26:16 +0800 Subject: [PATCH] =?UTF-8?q?rollback:=20=E7=99=BB=E5=BD=95=E8=B6=85?= =?UTF-8?q?=E6=97=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/auth/filter/JWTFilter.java | 3 +- .../java/io/dataease/auth/util/JWTUtils.java | 18 ++++---- .../src/main/resources/ehcache/ehcache.xml | 42 +++++++++---------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java b/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java index 48376db8c6..4729dcb089 100644 --- a/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java +++ b/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java @@ -6,6 +6,7 @@ import io.dataease.auth.entity.TokenInfo; import io.dataease.auth.service.AuthUserService; import io.dataease.auth.util.JWTUtils; import io.dataease.commons.utils.CommonBeanFactory; +import io.dataease.commons.utils.ServletUtils; import io.dataease.i18n.Translator; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authc.AuthenticationException; @@ -111,7 +112,7 @@ public class JWTFilter extends BasicHttpAuthenticationFilter { // JWTUtils.removeTokenExpire(token); String newToken = JWTUtils.sign(tokenInfo, password); // 记录新token操作时间 - JWTUtils.addTokenExpire(newToken); + // JWTUtils.addTokenExpire(newToken); JWTToken jwtToken = new JWTToken(newToken); this.getSubject(request, response).login(jwtToken); diff --git a/backend/src/main/java/io/dataease/auth/util/JWTUtils.java b/backend/src/main/java/io/dataease/auth/util/JWTUtils.java index 7b25d06748..4daecc0d84 100644 --- a/backend/src/main/java/io/dataease/auth/util/JWTUtils.java +++ b/backend/src/main/java/io/dataease/auth/util/JWTUtils.java @@ -24,7 +24,7 @@ public class JWTUtils { // token过期时间1min (过期会自动刷新续命 目的是避免一直都是同一个token ) private static final long EXPIRE_TIME = 1*60*1000; // 登录间隔时间10min 超过这个时间强制重新登录 - private static long Login_Interval; + private static long Login_Interval; @@ -84,17 +84,24 @@ public class JWTUtils { */ public static boolean loginExpire(String token){ if (Login_Interval==0) { - int minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Integer.class, 8*60); + String property = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout"); + // 默认超时时间是8h + int minute = StringUtils.isNotEmpty(property) ? Integer.parseInt(property): (8*60); // 分钟换算成毫秒 Login_Interval = minute * 1000 * 60; } Long now = System.currentTimeMillis(); Long lastOperateTime = tokenLastOperateTime(token); - if (ObjectUtils.isEmpty(lastOperateTime)) return true; boolean isExpire = false; if (lastOperateTime != null) { isExpire = now - lastOperateTime > Login_Interval; } + if (isExpire) { +// System.out.println("-----------------------"); +// System.out.println("-----上次操作时间是["+lastOperateTime+"]-----"); +// System.out.println("-----当前操作时间是["+now+"]-----"); +// System.out.println("-----------------------"); + } return isExpire; } @@ -109,7 +116,7 @@ public class JWTUtils { } /** - * 生成签名,1min后过期 + * 生成签名,5min后过期 * @param tokenInfo 用户信息 * @param secret 用户的密码 * @return 加密的token @@ -158,12 +165,10 @@ public class JWTUtils { CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class); Cache tokens_expire = cacheManager.getCache("tokens_expire"); Long expTime = tokens_expire.get(token, Long.class); - // System.out.println("get-------"+token+" :"+expTime); return expTime; } public static void removeTokenExpire(String token){ - // System.out.println("remove----"+token); CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class); Cache tokens_expire = cacheManager.getCache("tokens_expire"); tokens_expire.evict(token); @@ -173,7 +178,6 @@ public class JWTUtils { CacheManager cacheManager = CommonBeanFactory.getBean(CacheManager.class); Cache tokens_expire = cacheManager.getCache("tokens_expire"); long now = System.currentTimeMillis(); - // System.out.println("add-------"+token+" :"+now); tokens_expire.put(token, now); } diff --git a/backend/src/main/resources/ehcache/ehcache.xml b/backend/src/main/resources/ehcache/ehcache.xml index 82848300e9..ff551ec033 100644 --- a/backend/src/main/resources/ehcache/ehcache.xml +++ b/backend/src/main/resources/ehcache/ehcache.xml @@ -29,7 +29,7 @@