title: Store User object in session with Spring Security
body: <p>Based on my understanding, there are a number of different ways to retrieve the authenticated username in Spring Security. </p>
  
  <p>I'm currently grabbing the username by included the <code>Principal</code> as a controller method argument:</p>
  
  <pre><code>@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
  public ModelAndView displayHomePage(ModelAndView modelAndView, Principal principal) {
  
    modelAndView.addObject("email", principal.getName());
  
    // Render template located at src/main/resources/templates/dashboard.html
    modelAndView.setViewName("dashboard");
  
    return modelAndView;
  }
  </code></pre>
  
  <p>Does Spring Security offer an easy way for me to store the User object into the session so it can be easily retrieved by any controller method?</p>
  
  <p>I want to avoid performing a DB lookup each time:</p>
  
  <pre><code>// Lookup user in database by e-mail
  User user = userService.findUserByEmail(principal.getName());
  </code></pre>
  
  <p>I'm using Spring Security 4.2.</p>