From 961b9aa11e2e60d746966522429b3e332cb991d3 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Thu, 18 Jul 2024 10:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cweb/src/main/java/com/cweb/config/AuthConfig.java | 4 ++++ .../java/com/hfkj/common/security/UserCenter.java | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cweb/src/main/java/com/cweb/config/AuthConfig.java b/cweb/src/main/java/com/cweb/config/AuthConfig.java index 4263028..fcd1aa2 100644 --- a/cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -63,10 +63,14 @@ public class AuthConfig implements WebMvcConfigurer { } String token = request.getHeader("Authorization"); if(StringUtils.isNotBlank(token) && userCenter.isLogin(token)){//如果未登录,将无法使用任何接口 + // 刷新登录缓存时间 + userCenter.refresh(request); return true; } else if(request instanceof StandardMultipartHttpServletRequest) { StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request; if(userCenter.isLogin(re.getRequest())){ + // 刷新登录缓存时间 + userCenter.refresh(request); return true; } else { log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); diff --git a/service/src/main/java/com/hfkj/common/security/UserCenter.java b/service/src/main/java/com/hfkj/common/security/UserCenter.java index 2bde068..1433c4e 100644 --- a/service/src/main/java/com/hfkj/common/security/UserCenter.java +++ b/service/src/main/java/com/hfkj/common/security/UserCenter.java @@ -21,7 +21,7 @@ public class UserCenter { @Autowired private RedisUtil redisUtil; - private final int EXPIRE = 3600 * 24 * 180; // 登录过期时间为180天 + private final int EXPIRE = 3600 * 24 * 90; // 登录过期时间为90天 /** * 保存登录信息 @@ -31,6 +31,17 @@ public class UserCenter { redisUtil.set(seObj.getToken(), seObj, EXPIRE); } + /** + * 刷新登录缓存时间 + * @throws Exception + */ + public void refresh(HttpServletRequest request) { + String token = request.getHeader("Authorization"); + if(StringUtils.isNotBlank(token)) { + redisUtil.expire(token, EXPIRE); + } + } + /** * 是否登录 * @param request