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

9 lines
602 B
Java

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);