title: How do I get the Session Object in Spring?
body: <p>I am relatively new to <a href="http://en.wikipedia.org/wiki/Spring_Framework" rel="noreferrer">Spring</a> and Spring security.</p>
  
  <p>I was attempting to write a program where I needed to authenticate a user at the server end using Spring security,</p>
  
  <p>I came up with the following:</p>
  
  <pre><code>public class CustomAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider{
      @Override
      protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken)
                      throws AuthenticationException
      {
          System.out.println("Method invoked : additionalAuthenticationChecks isAuthenticated ? :"+usernamePasswordAuthenticationToken.isAuthenticated());
      }
  
      @Override
      protected UserDetails retrieveUser(String username,UsernamePasswordAuthenticationToken authentication) throws AuthenticationException 
      {
          System.out.println("Method invoked : retrieveUser");
          //so far so good, i can authenticate user here, and throw exception if not authenticated!!
          //THIS IS WHERE I WANT TO ACCESS SESSION OBJECT
      }
  }
  </code></pre>
  
  <p>My usecase is that when a user is authenticated, I need to place an attribute like:</p>
  
  <pre><code>session.setAttribute("userObject", myUserObject);
  </code></pre>
  
  <p>myUserObject is an object of some class that I can access throughout my server code across multiple user requests.</p>