InterviewSolution
| 1. |
How Is A Principal Defined? |
|
Answer» Inside the SecurityContextHolder we store DETAILS of the principal currently interacting with the application. Spring SECURITY uses an Authentication OBJECT to represent this information. Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal INSTANCEOF UserDetails) { STRING username = ((UserDetails)principal).getUsername(); } else { String username = principal.toString(); } Inside the SecurityContextHolder we store details of the principal currently interacting with the application. Spring Security uses an Authentication object to represent this information. Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { String username = ((UserDetails)principal).getUsername(); } else { String username = principal.toString(); } |
|