how to refresh JSESSIONID cookie after login

前端 未结 10 1533
我在风中等你
我在风中等你 2021-01-30 17:41

A product I work on got a tough security audit by a potential customer and they are upset that Tomcat sets a JSESSIONID cookie before authentication has happened. That is, Tomc

10条回答
  •  执笔经年
    2021-01-30 18:04

    I have followed following way to regenerate the new session from old session. Hope you will be benefited from it.

    private void regenerateSession(HttpServletRequest request) {
    
        HttpSession oldSession = request.getSession();
    
        Enumeration attrNames = oldSession.getAttributeNames();
        Properties props = new Properties();
    
        if (attrNames != null) {
            while (attrNames.hasMoreElements()) {
                String key = (String) attrNames.nextElement();
                props.put(key, oldSession.getAttribute(key));
            }
    
            //Invalidating previous session
            oldSession.invalidate();
            //Generate new session
            HttpSession newSession = request.getSession(true);
            attrNames = props.keys();
    
            while (attrNames.hasMoreElements()) {
                String key = (String) attrNames.nextElement();
                newSession.setAttribute(key, props.get(key));
            }
        }
    

提交回复
热议问题