Spring Security - Get current user details in controller

To get currently logged in user details in Spring controller, use the following code

User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();

Search