fix: 解决由于缓存过期导致登录超时失效的bug

This commit is contained in:
fit2cloud-chenyw 2021-06-03 13:07:44 +08:00
parent 180c56f293
commit ca8b10bc13
3 changed files with 24 additions and 32 deletions

View File

@ -6,7 +6,6 @@ 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;

View File

@ -84,24 +84,17 @@ public class JWTUtils {
*/
public static boolean loginExpire(String token){
if (Login_Interval==0) {
String property = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout");
// 默认超时时间是8h
int minute = StringUtils.isNotEmpty(property) ? Integer.parseInt(property): (8*60);
int minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Integer.class, 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;
}
@ -116,7 +109,7 @@ public class JWTUtils {
}
/**
* 生成签名,5min后过期
* 生成签名,1min后过期
* @param tokenInfo 用户信息
* @param secret 用户的密码
* @return 加密的token

View File

@ -29,7 +29,7 @@
<defaultCache
eternal="false"
maxElementsInMemory="1000"
overflowToDisk="false"
overflowToDisk="true"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="600"
@ -38,46 +38,46 @@
<cache
name="users_info"
eternal="false"
maxElementsInMemory="100"
maxElementsOnDisk="1000"
maxElementsInMemory="1000"
maxElementsOnDisk="0"
overflowToDisk="true"
diskPersistent="true"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
diskPersistent="false"
timeToIdleSeconds="28800"
timeToLiveSeconds="36000"
memoryStoreEvictionPolicy="LRU"
/>
<cache
name="users_roles_info"
eternal="false"
maxElementsInMemory="100"
maxElementsOnDisk="1000"
maxElementsInMemory="1000"
maxElementsOnDisk="0"
overflowToDisk="true"
diskPersistent="true"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
diskPersistent="false"
timeToIdleSeconds="28800"
timeToLiveSeconds="36000"
memoryStoreEvictionPolicy="LRU"
/>
<cache
name="users_permissions_info"
eternal="false"
maxElementsInMemory="100"
maxElementsOnDisk="1000"
maxElementsInMemory="1000"
maxElementsOnDisk="0"
overflowToDisk="true"
diskPersistent="true"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
diskPersistent="false"
timeToIdleSeconds="28800"
timeToLiveSeconds="36000"
memoryStoreEvictionPolicy="LRU"
/>
<cache
name="tokens_expire"
eternal="false"
maxElementsInMemory="100"
maxElementsOnDisk="1000"
maxElementsInMemory="1000"
maxElementsOnDisk="0"
overflowToDisk="true"
diskPersistent="true"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
diskPersistent="false"
timeToIdleSeconds="28800"
timeToLiveSeconds="36000"
memoryStoreEvictionPolicy="LRU"
/>