package compbio.controllers; import java.util.Collection; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; public class BasicController { protected String getPrincipalName() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { UserDetails details = (UserDetails) principal; String ldapprefix = ""; String role = details.getUsername(); Collection au = details.getAuthorities(); for (GrantedAuthority ga : au) { System.out.println("role -> " + ga.getAuthority()); if (ga.getAuthority().equals("ROLE_LDAP_USER")) { ldapprefix = "LDAP:"; } } return ldapprefix + role; } return principal.toString(); } protected boolean isUserRole() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { UserDetails details = (UserDetails) principal; Collection au = details.getAuthorities(); for (GrantedAuthority ga : au) { if (ga.getAuthority().equals("ROLE_USER") || ga.getAuthority().equals("ROLE_LDAP_USER")) { return true; } } return false; } return false; } }