Spring / Spring Security
What is security principal?
A principal is an identity: a user, account, or service the security runtime authenticated. In Spring Security it lives on the Authentication object.
SecurityContextHolder stores the principal currently interacting with the application. The principal is the currently logged in user that you retrieve it through the security context.
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { String username = ((UserDetails)principal).getUsername(); } else { String username = principal.toString(); }
More Related questions...