title: How to obtain HttpSession from within the loadUserByUsername method?
body: <p>My web app is built with Spring MVC (4.2.9.RELEASE) and Spring Security (3.2.5.RELEASE). I use the <code>loadUserByUsername</code> method to find the user from the database.</p>
  
  <pre class="lang-java prettyprint-override"><code>
      public class MyUserDetailsServiceImpl implements UserDetailsService {
  
          @Override
          public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
  
              //how to get the HttpSession from within this methd?
  
          }
          ....
      }
  </code></pre>
  
  <p>How can I get the HttpSession from within this method?</p>
  
  <p>In the <code>applicationContext.xml</code> file, I have the following for security:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;http create-session="always" use-expressions="true" request-matcher="regex" entry-point-ref="authenticationEntryPoint" &gt;
  
     ....
  
  &lt;/http&gt;
  </code></pre>