|
@@ -8,12 +8,15 @@ import javax.servlet.ServletException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.jiayue.ssi.constant.CacheConstants;
|
|
|
import com.jiayue.ssi.constant.Constants;
|
|
|
import com.jiayue.ssi.constant.LoginConstants;
|
|
|
import com.jiayue.ssi.dto.UserVisitInfoDto;
|
|
|
+import com.jiayue.ssi.entity.SysPolicy;
|
|
|
import com.jiayue.ssi.entity.SysUser;
|
|
|
import com.jiayue.ssi.factory.LoginFactory;
|
|
|
+import com.jiayue.ssi.service.SysPolicyService;
|
|
|
import com.jiayue.ssi.service.SysUserService;
|
|
|
import com.jiayue.ssi.service.impl.UserServiceImpl;
|
|
|
import com.jiayue.ssi.util.*;
|
|
@@ -29,6 +32,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.filter.OncePerRequestFilter;
|
|
|
+import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
|
|
|
/**
|
|
|
* jwt过滤器
|
|
@@ -45,12 +49,14 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
|
UserServiceImpl userServiceImpl;
|
|
|
JwtTokenUtil jwtTokenUtil;
|
|
|
SysUserService sysUserService;
|
|
|
+ SysPolicyService sysPolicyService;
|
|
|
int bfhhs;
|
|
|
|
|
|
- public JwtAuthenticationTokenFilter(UserServiceImpl userServiceImpl, JwtTokenUtil jwtTokenUtil,SysUserService sysUserService,int bfhhs) {
|
|
|
+ public JwtAuthenticationTokenFilter(UserServiceImpl userServiceImpl, JwtTokenUtil jwtTokenUtil,SysUserService sysUserService,int bfhhs,SysPolicyService sysPolicyService) {
|
|
|
this.userServiceImpl = userServiceImpl;
|
|
|
this.jwtTokenUtil = jwtTokenUtil;
|
|
|
this.sysUserService = sysUserService;
|
|
|
+ this.sysPolicyService = sysPolicyService;
|
|
|
this.bfhhs = bfhhs;
|
|
|
}
|
|
|
|
|
@@ -159,6 +165,27 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 先判断非活动时长
|
|
|
+ if (LocalCache.get(CacheConstants.REACTIVE_KEY + token)==null){
|
|
|
+ ResponseInfo.doResponse(response, "超出非活动时长退出!", 406);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Long lastOperTime = (Long)LocalCache.get(CacheConstants.REACTIVE_KEY + token);
|
|
|
+ // 获取非活动配置值
|
|
|
+ SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
|
|
|
+ Long expiration = sysPolicy.getInactiveLogout().longValue()*1000*60L;
|
|
|
+ if (System.currentTimeMillis()>lastOperTime+expiration){
|
|
|
+ LocalCache.remove(CacheConstants.REACTIVE_KEY + token);
|
|
|
+ // 超出配置设定值则退出
|
|
|
+ ResponseInfo.doResponse(response, "超出非活动时长退出!", 406);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ LocalCache.set(CacheConstants.REACTIVE_KEY + token,System.currentTimeMillis(),1000*60*60);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
if ("POST".equalsIgnoreCase(request.getMethod()) && defaultFilterProcessUrl.equals(request.getServletPath())) {
|
|
|
// 判断并发会话数是否满足
|