X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=server%2Fcompbio%2Fcontrollers%2FBasicController.java;h=389a0f71ba3030311472ce0cd3cd297cd2cbaa89;hb=c1ae48e93c766434005e5d5201af8ad23bc0a59b;hp=d4be83488055124cdf8a4003a0e0056f892eba55;hpb=341971e3170e4e957656a61ae2ffcc0e50ecf621;p=proteocache.git diff --git a/server/compbio/controllers/BasicController.java b/server/compbio/controllers/BasicController.java index d4be834..389a0f7 100644 --- a/server/compbio/controllers/BasicController.java +++ b/server/compbio/controllers/BasicController.java @@ -1,21 +1,44 @@ 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; -/* -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -*/ public class BasicController { protected String getPrincipalName() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { - return ((UserDetails) principal).getUsername(); - } + 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; + } + }