title: Get UserDetails object from Security Context in Spring MVC controller
body: <p>I'm using Spring Security 3 and Spring MVC 3.05.</p>
  
  <p>I would like to print username of currently logged in user,how can I fetch UserDetails in my Controller?</p>
  
  <pre><code>@RequestMapping(value="/index.html", method=RequestMethod.GET)
      public ModelAndView indexView(){
           UserDetails user = ?
                  mv.addObject("username", user.getUsername());
          ModelAndView mv = new ModelAndView("index");
          return mv;
      }   
  </code></pre>