ISE-ComProg-After-Midterm/screwdriver-3.5.6/box/snippets/java/ldapAuthenticationModel.java

9 lines
602 B
Java
Raw Normal View History

2020-10-29 09:38:56 +00:00
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication == null) {
throw new IllegalStateException("authentication cannot be null. Make sure you are logged in.");
}
Object principal = authentication.getPrincipal();
model.addAttribute("user", principal);
model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails);
model.addAttribute("isLdapPerson", principal instanceof Person);
model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson);