1

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 ?

Abel
  • 19
  • 5

1 Answers1

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