I am writing a Spring web application. Regarding the authentication, I'm using Spring Security , i need to retreive the information detail of the user , how to avoid that ?
Asked
Active
Viewed 44 times
1
-
Possible duplicate of: http://stackoverflow.com/questions/8764545/how-to-get-active-users-userdetails – Thomas Eizinger Apr 17 '15 at 13:01
1 Answers
0
The path is SecurityContextHolder.getContext().getAuthentication().getPrincipal()
This is for you as an example:
public UserDetails getCurrentUserDetails() {
org.springframework.security.core.context.SecurityContext securityContext = SecurityContextHolder
.getContext();
Authentication authentication = securityContext.getAuthentication();
UserDetails user = null;
if (authentication != null) {
if (authentication.getPrincipal() instanceof UserDetails)
{
user = ((UserDetails) authentication.getPrincipal());
}
}
return user;
}

Yernar Arystanov
- 176
- 1
- 4
- 10