title: Retrieving Session ID with Spring Security
body: <p>For logging purposes, I'd like to create a logger that automatically adds the current session's ID to logged lines.<br>
  For logged in users this isn't a problem: </p>
  
  <pre><code>((WebAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails())
      .getSessionId()
  </code></pre>
  
  <p>The problem is, before the user has logged in <code>getAuthentication()</code> returns <code>null</code>. Is there another way for getting the session ID without having a reference to the current response or anything of that sort?</p>