|
|
@ -1,13 +1,14 @@ |
|
|
|
|
|
|
|
package com.keyware.sonar; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.classmate.Filter; |
|
|
|
import com.fasterxml.classmate.Filter; |
|
|
|
|
|
|
|
import jakarta.servlet.FilterChain; |
|
|
|
|
|
|
|
import jakarta.servlet.ServletException; |
|
|
|
|
|
|
|
import jakarta.servlet.ServletRequest; |
|
|
|
|
|
|
|
import jakarta.servlet.ServletResponse; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpSession; |
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.FilterChain; |
|
|
|
|
|
|
|
import javax.servlet.ServletException; |
|
|
|
|
|
|
|
import javax.servlet.ServletRequest; |
|
|
|
|
|
|
|
import javax.servlet.ServletResponse; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpSession; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
public class UserStatusVerifyChecker { |
|
|
|
public class UserStatusVerifyChecker { |
|
|
@ -34,7 +35,7 @@ public class UserStatusVerifyChecker { |
|
|
|
} |
|
|
|
} |
|
|
|
HttpSession newSession = request.getSession(true); |
|
|
|
HttpSession newSession = request.getSession(true); |
|
|
|
newSession.setMaxInactiveInterval(30 * 60); |
|
|
|
newSession.setMaxInactiveInterval(30 * 60); |
|
|
|
newSession.setAttribute("username", username); |
|
|
|
newSession.setAttribute("username", "username"); |
|
|
|
chain.doFilter(req, resp); // 继续执行下一个过滤器或请求
|
|
|
|
chain.doFilter(req, resp); // 继续执行下一个过滤器或请求
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
req.getRequestDispatcher("/login.jsp").forward(req, resp); // 跳转到登录页面
|
|
|
|
req.getRequestDispatcher("/login.jsp").forward(req, resp); // 跳转到登录页面
|
|
|
@ -48,14 +49,13 @@ public class UserStatusVerifyChecker { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class AuthenticationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
public class AuthenticationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {// Noncompliant {{对用户进行身份鉴别并建立一个新的会话时让原来的会话失效}}
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {// Noncompliant {{对用户进行身份鉴别并建立一个新的会话时让原来的会话失效}}
|
|
|
|
boolean isValidUser = false; |
|
|
|
boolean isValidUser = false; |
|
|
|
String username = request.getParameter("username"); |
|
|
|
String username = request.getParameter("username"); |
|
|
|
String password = request.getParameter("password"); |
|
|
|
String password = request.getParameter("password"); |
|
|
|
isValidUser = UserService.validate(username, password); |
|
|
|
isValidUser = UserService.validate(username, password); |
|
|
|
if (isValidUser) { |
|
|
|
if (isValidUser) { |
|
|
|
// HttpSession oldSession = request.getSession(false);
|
|
|
|
HttpSession oldSession = request.getSession(false); |
|
|
|
if (oldSession != null) { |
|
|
|
if (oldSession != null) { |
|
|
|
oldSession.invalidate(); |
|
|
|
oldSession.invalidate(); |
|
|
|
} |
|
|
|
} |
|
|
|