Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
UserDetails details = (UserDetails) principal;
- String ldapprefix = "";
+ String rolefix = "";
String role = details.getUsername();
Collection<? extends GrantedAuthority> au = details.getAuthorities();
for (GrantedAuthority ga : au) {
- System.out.println("role -> " + ga.getAuthority());
if (ga.getAuthority().equals("ROLE_LDAP_USER")) {
- ldapprefix = "LDAP:";
+ rolefix = "LDAP:";
}
}
- return ldapprefix + role;
+ return rolefix + role;
}
return principal.toString();
}
return false;
}
+ protected boolean isAdminRole() {
+ Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ if (principal instanceof UserDetails) {
+ UserDetails details = (UserDetails) principal;
+ Collection<? extends GrantedAuthority> au = details.getAuthorities();
+ for (GrantedAuthority ga : au) {
+ if (ga.getAuthority().equals("ROLE_ADMIN")) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return false;
+ }
+
}