提交代码

dev
胡锐 4 months ago
parent b3d2435a0e
commit 961b9aa11e
  1. 4
      cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 13
      service/src/main/java/com/hfkj/common/security/UserCenter.java

@ -63,10 +63,14 @@ public class AuthConfig implements WebMvcConfigurer {
} }
String token = request.getHeader("Authorization"); String token = request.getHeader("Authorization");
if(StringUtils.isNotBlank(token) && userCenter.isLogin(token)){//如果未登录,将无法使用任何接口 if(StringUtils.isNotBlank(token) && userCenter.isLogin(token)){//如果未登录,将无法使用任何接口
// 刷新登录缓存时间
userCenter.refresh(request);
return true; return true;
} else if(request instanceof StandardMultipartHttpServletRequest) { } else if(request instanceof StandardMultipartHttpServletRequest) {
StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request; StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request;
if(userCenter.isLogin(re.getRequest())){ if(userCenter.isLogin(re.getRequest())){
// 刷新登录缓存时间
userCenter.refresh(request);
return true; return true;
} else { } else {
log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL());

@ -21,7 +21,7 @@ public class UserCenter {
@Autowired @Autowired
private RedisUtil redisUtil; 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); 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 * @param request

Loading…
Cancel
Save