title: how to refresh JSESSIONID cookie after login
body: <p>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, Tomcat sets this cookie when our stateless Login Page loads, but before login.</p>
  
  <p>They suggest either of the following:</p>
  
  <ol>
  <li>issue a new JSESSIONID cookie after login</li>
  <li>prevent a JSESSIONID cookie from being set in the first place on the Login Page (i.e., before authentication has happened)</li>
  </ol>
  
  <p>I have been poring through everything JSESSIONID-related on this site and can find no easy answer.  I'm just hoping for some ideas.  My best solutions for each are:</p>
  
  <ol>
  <li>right after login, clone the Session (minus the id) by copying all the attributes, invalidating the old session, creating a new one, copying the values, associating it with the request, and hoping that works.</li>
  <li>create a servlet Filter at the very end of the chain that strips out the JSESSIONID cookie before the Login Page is initially loaded.  And then hope the login request works out without a JSESSIONID set.</li>
  </ol>
  
  <p>I've got to get some sleep, but will be attempting these in the morning.  It would be awesome to get some feedback or better suggestions from people much smarter than myself -- like you!</p>
  
  <p>Regardless, I'll post my results here because it seems like a lot of other people have been wanting to do something similar.</p>