提交 63002eef authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

rollback: 登录超时bug

上级 73dc5c7e
...@@ -6,6 +6,7 @@ import io.dataease.auth.entity.TokenInfo; ...@@ -6,6 +6,7 @@ import io.dataease.auth.entity.TokenInfo;
import io.dataease.auth.service.AuthUserService; import io.dataease.auth.service.AuthUserService;
import io.dataease.auth.util.JWTUtils; import io.dataease.auth.util.JWTUtils;
import io.dataease.commons.utils.CommonBeanFactory; import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.ServletUtils;
import io.dataease.i18n.Translator; import io.dataease.i18n.Translator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationException;
...@@ -111,7 +112,7 @@ public class JWTFilter extends BasicHttpAuthenticationFilter { ...@@ -111,7 +112,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);
......
...@@ -84,17 +84,24 @@ public class JWTUtils { ...@@ -84,17 +84,24 @@ public class JWTUtils {
*/ */
public static boolean loginExpire(String token){ public static boolean loginExpire(String token){
if (Login_Interval==0) { 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; Login_Interval = minute * 1000 * 60;
} }
Long now = System.currentTimeMillis(); Long now = System.currentTimeMillis();
Long lastOperateTime = tokenLastOperateTime(token); Long lastOperateTime = tokenLastOperateTime(token);
if (ObjectUtils.isEmpty(lastOperateTime)) return true;
boolean isExpire = false; boolean isExpire = false;
if (lastOperateTime != null) { if (lastOperateTime != null) {
isExpire = now - lastOperateTime > Login_Interval; isExpire = now - lastOperateTime > Login_Interval;
} }
if (isExpire) {
// System.out.println("-----------------------");
// System.out.println("-----上次操作时间是["+lastOperateTime+"]-----");
// System.out.println("-----当前操作时间是["+now+"]-----");
// System.out.println("-----------------------");
}
return isExpire; return isExpire;
} }
...@@ -109,7 +116,7 @@ public class JWTUtils { ...@@ -109,7 +116,7 @@ public class JWTUtils {
} }
/** /**
* 生成签名,1min后过期 * 生成签名,5min后过期
* @param tokenInfo 用户信息 * @param tokenInfo 用户信息
* @param secret 用户的密码 * @param secret 用户的密码
* @return 加密的token * @return 加密的token
...@@ -158,12 +165,10 @@ public class JWTUtils { ...@@ -158,12 +165,10 @@ 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);
...@@ -173,7 +178,6 @@ public class JWTUtils { ...@@ -173,7 +178,6 @@ 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);
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<defaultCache <defaultCache
eternal="false" eternal="false"
maxElementsInMemory="1000" maxElementsInMemory="1000"
overflowToDisk="true" overflowToDisk="false"
diskPersistent="false" diskPersistent="false"
timeToIdleSeconds="0" timeToIdleSeconds="0"
timeToLiveSeconds="600" timeToLiveSeconds="600"
...@@ -38,46 +38,46 @@ ...@@ -38,46 +38,46 @@
<cache <cache
name="users_info" name="users_info"
eternal="false" eternal="false"
maxElementsInMemory="1000" maxElementsInMemory="100"
maxElementsOnDisk="0" maxElementsOnDisk="1000"
overflowToDisk="true" overflowToDisk="true"
diskPersistent="false" diskPersistent="true"
timeToIdleSeconds="28800" timeToIdleSeconds="1800"
timeToLiveSeconds="36000" timeToLiveSeconds="3600"
memoryStoreEvictionPolicy="LRU" memoryStoreEvictionPolicy="LRU"
/> />
<cache <cache
name="users_roles_info" name="users_roles_info"
eternal="false" eternal="false"
maxElementsInMemory="1000" maxElementsInMemory="100"
maxElementsOnDisk="0" maxElementsOnDisk="1000"
overflowToDisk="true" overflowToDisk="true"
diskPersistent="false" diskPersistent="true"
timeToIdleSeconds="28800" timeToIdleSeconds="1800"
timeToLiveSeconds="36000" timeToLiveSeconds="3600"
memoryStoreEvictionPolicy="LRU" memoryStoreEvictionPolicy="LRU"
/> />
<cache <cache
name="users_permissions_info" name="users_permissions_info"
eternal="false" eternal="false"
maxElementsInMemory="1000" maxElementsInMemory="100"
maxElementsOnDisk="0" maxElementsOnDisk="1000"
overflowToDisk="true" overflowToDisk="true"
diskPersistent="false" diskPersistent="true"
timeToIdleSeconds="28800" timeToIdleSeconds="1800"
timeToLiveSeconds="36000" timeToLiveSeconds="3600"
memoryStoreEvictionPolicy="LRU" memoryStoreEvictionPolicy="LRU"
/> />
<cache <cache
name="tokens_expire" name="tokens_expire"
eternal="false" eternal="false"
maxElementsInMemory="1000" maxElementsInMemory="100"
maxElementsOnDisk="0" maxElementsOnDisk="1000"
overflowToDisk="true" overflowToDisk="true"
diskPersistent="false" diskPersistent="true"
timeToIdleSeconds="28800" timeToIdleSeconds="1800"
timeToLiveSeconds="36000" timeToLiveSeconds="3600"
memoryStoreEvictionPolicy="LRU" memoryStoreEvictionPolicy="LRU"
/> />
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论