If all that you need is details of User, for Spring Version 4.x you can use @AuthenticationPrincipal
and @EnableWebSecurity
tag provided by Spring as shown below.
Security Configuration Class:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
}
Controller method:
@RequestMapping("/messages/inbox")
public ModelAndView findMessagesForUser(@AuthenticationPrincipal User user) {
...
}