I\'m using Spring Security 3 and Spring MVC 3.05.
I would like to print username of currently logged in user,how can I fetch UserDetails in my Controller?
That's another solution (Spring Security 3):
public String getLoggedUser() throws Exception { String name = SecurityContextHolder.getContext().getAuthentication().getName(); return (!name.equals("anonymousUser")) ? name : null; }