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

10 lines
644 B
Java
Raw Permalink 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 = userDetailsService.loadUserByUsername(authentication.getName());
model.addAttribute("user", principal);
model.addAttribute("isLdapUserDetails", principal instanceof LdapUserDetails);
model.addAttribute("isLdapPerson", principal instanceof Person);
model.addAttribute("isLdapInetOrgPerson", principal instanceof InetOrgPerson);