|
@@ -2,6 +2,8 @@ package com.jiayue.ssi.filter;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.servlet.FilterChain;
|
|
import javax.servlet.FilterChain;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletException;
|
|
@@ -66,7 +68,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
@Override
|
|
@Override
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws
|
|
ServletException, IOException {
|
|
ServletException, IOException {
|
|
- SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
|
+// SecurityContextHolder.getContext().getAuthentication();
|
|
String token = request.getHeader("Authorization");
|
|
String token = request.getHeader("Authorization");
|
|
if (!StringUtils.isEmpty(token)) {
|
|
if (!StringUtils.isEmpty(token)) {
|
|
String username = "";
|
|
String username = "";
|
|
@@ -195,23 +197,49 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|
// 设置标题
|
|
// 设置标题
|
|
operLog.setTitle("连接超时");
|
|
operLog.setTitle("连接超时");
|
|
// 操作描述
|
|
// 操作描述
|
|
- operLog.setOperdesc("连接超时");
|
|
|
|
|
|
+ operLog.setOperdesc("超出非活动时长");
|
|
// 审计类型
|
|
// 审计类型
|
|
operLog.setAuditType(AuditType.SYS.ordinal());
|
|
operLog.setAuditType(AuditType.SYS.ordinal());
|
|
// 保存数据库
|
|
// 保存数据库
|
|
OperateLogFactory.recordOper(operLog);
|
|
OperateLogFactory.recordOper(operLog);
|
|
|
|
|
|
LocalCache.remove(CacheConstants.REACTIVE_KEY + token);
|
|
LocalCache.remove(CacheConstants.REACTIVE_KEY + token);
|
|
|
|
+
|
|
|
|
+ SysUser sysUser = (SysUser)SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
+ // 设置用户离线状态
|
|
|
|
+ sysUser.setOnlineStatus("1");
|
|
|
|
+ sysUserService.updateUser(sysUser);
|
|
|
|
+ CacheConstants.LOGIN_TOKEN_MAP.remove(sysUser.getUsername());
|
|
|
|
+ LoginConstants.sessionMap.remove(sysUser.getUsername());
|
|
|
|
+ Iterator<Map.Entry<String, String>> countMap = CacheConstants.IP_USER_MAP.entrySet().iterator();
|
|
|
|
+ while (countMap.hasNext()) {
|
|
|
|
+ Map.Entry<String, String> entry1 = countMap.next();
|
|
|
|
+ String cacheusername = entry1.getValue();
|
|
|
|
+ if (cacheusername.equals(sysUser.getUsername())){
|
|
|
|
+ countMap.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// 超出配置设定值则退出
|
|
// 超出配置设定值则退出
|
|
ResponseInfo.doResponse(response, "超出非活动时长退出!", 406);
|
|
ResponseInfo.doResponse(response, "超出非活动时长退出!", 406);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
- LocalCache.set(CacheConstants.REACTIVE_KEY + token,System.currentTimeMillis(),1000*60*60);
|
|
|
|
|
|
+ if (!request.getRequestURI().equals("/sysUserController/establishHeart")){
|
|
|
|
+ LocalCache.set(CacheConstants.REACTIVE_KEY + token,System.currentTimeMillis(),1000*60*60);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if ("POST".equalsIgnoreCase(request.getMethod()) && defaultFilterProcessUrl.equals(request.getServletPath())) {
|
|
if ("POST".equalsIgnoreCase(request.getMethod()) && defaultFilterProcessUrl.equals(request.getServletPath())) {
|
|
|
|
+ String currentIp = IPUtils.getIpAddr();
|
|
|
|
+ String ip = CacheConstants.IP_USER_MAP.get(currentIp);
|
|
|
|
+ if (ip!=null && !"".equals(ip)){
|
|
|
|
+ // 判断当前访问的ip是否已经存在,如果存在则不让任何用户访问
|
|
|
|
+ ResponseInfo.doResponse(response, "您的客户端IP有用户正在使用,不能登录系统!", 405);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 判断并发会话数是否满足
|
|
// 判断并发会话数是否满足
|
|
SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
|
|
SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
|
|
if (LoginConstants.sessionMap.size()+1>sysPolicy.getBfhhs()){
|
|
if (LoginConstants.sessionMap.size()+1>sysPolicy.getBfhhs()){
|