세션 고정을 수정하기 위해 로그인 후에 새 세션을 만들어야하는 필터를 작성했습니다.로그인 후 새 세션 생성
//variables
public class GenerteNewSessionFilter implements Filter {
public static final String NEW_SESSION_INDICATOR = "cab";
// destroy
public void destroy() {
// TODO Auto-generated method stub
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
if (httpRequest.getSession(false) != null && httpRequest.getSession(false).getAttribute(NEW_SESSION_INDICATOR) != null) {
// copy session attributes from new session to a map.
HttpSession session = httpRequest.getSession();
// HashMap old = new HashMap();
HashMap<String, Object> old = new HashMap<String, Object>();
Enumeration keys = (Enumeration) session.getAttributeNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
if (!NEW_SESSION_INDICATOR.equals(key)) {
old.put(key, session.getAttribute(key));
session.removeAttribute(key);
}
}
// invalidation session and create new session.
session.invalidate();
session = httpRequest.getSession(true);
// copy key value pairs from map to new session.
for (Map.Entry entry : old.entrySet()) {
session.setAttribute((String) entry.getKey(), entry.getValue());
}
}
}
// initiatiliazion
public void init(FilterConfig filterConfig) throws ServletException {
}
}
하지만 난 한 번만 응용 프로그램에 사용자 로그인이 나를 인도하십시오 때 그것을 달성 할 수있는 방법을 실행할 : 시스템에 사용자 로그인이 경우에만 호출해야합니다.
감사합니다.
사용자의 자격 증명 게시를 처리하는 장소에 코드를 삽입하면 어떻게 될까요? 기본적으로 사용자가 자신이 누구라고 생각하는지 확인한 후에 세션을 무효화하십시오. –