Change JSESSIONID cookie if the login is successful
<p>For security purposes, upon successful logon, I need to change the JSESSIONID. I have something below. But it seems that, JSESSIONID is changed upon successful logon. But when I navigate to other pages, the JSESSIONID is changed again. I could not figure out what is wrong. </p>

<pre><code>public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    String _LOC = "[Redirect Filter: doFilter]";

    SB_UtilityLocal UTIL = createSB_UtilityLocal();

    boolean authorized = false;

    String user_sys_id = null;
    HttpSession oldsession = null;
    HttpSession session = null;     

    if (request instanceof HttpServletRequest) {
        oldsession = ((HttpServletRequest) request).getSession(false);

        if (oldsession != null) {
            // make a copy of the session content
            Map&lt;String, Object&gt; temp = new ConcurrentHashMap&lt;String, Object&gt;();
            Enumeration e = oldsession.getAttributeNames();
            while (e != null &amp;&amp; e.hasMoreElements()) {
                String name = (String) e.nextElement();
                Object value = oldsession.getAttribute(name);
                temp.put(name, value);
            }

            // kill the old session and create a new one
            oldsession.invalidate();
            session = ((HttpServletRequest) request).getSession();

            // copy back the session content
            for (Map.Entry&lt;String, Object&gt; stringObjectEntry : temp.entrySet()) {
                session.setAttribute(stringObjectEntry.getKey(),
                        stringObjectEntry.getValue());
            }           

            if (session != null) {
                user_sys_id = (String) session.getAttribute("user_sys_id");
                if (user_sys_id != null) {
                    authorized = true;
                }
            }
        }
    }
}
</code></pre>