List of usage examples for org.springframework.security.core GrantedAuthority getAuthority
String getAuthority();
GrantedAuthority
can be represented as a String
and that String
is sufficient in precision to be relied upon for an access control decision by an AccessDecisionManager (or delegate), this method should return such a String
. From source file:rights.UserRightsUtil.java
public static boolean isRight(String right) { Collection<? extends GrantedAuthority> grantes = SecurityContextHolder.getContext().getAuthentication() .getAuthorities();/*from w w w. j av a 2 s .com*/ for (GrantedAuthority grant : grantes) { if (grant.getAuthority().equals(right)) { return true; } } return false; }
From source file:com.pwsz.kutadaniel.controllers.SecurityHelper.java
/** * * @param authentication authentication// w w w .ja v a 2 s . com * @param rolename role name * @return whether it has a role */ public static boolean hasRole(Authentication authentication, String rolename) { boolean result = false; for (GrantedAuthority authority : authentication.getAuthorities()) { if (authority.getAuthority().equals(rolename)) { result = true; break; } } return result; }
From source file:hsa.awp.admingui.util.AccessUtil.java
public static boolean isTeacher() { for (GrantedAuthority authority : getAuthorities()) { if (authority.getAuthority().equals(Role.TEACHER.toString())) { return true; }/* www .j ava 2s.c o m*/ } return false; }
From source file:com.sentinel.util.SecurityUtil.java
public static ArrayList<String> getUserRoles() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); ArrayList<String> currentUserRoles = new ArrayList<String>(); for (GrantedAuthority authority : authorities) { currentUserRoles.add(authority.getAuthority()); }/* w ww . jav a2s.c o m*/ if (LOG.isDebugEnabled()) { LOG.debug("currentUserRoles:" + currentUserRoles); } return currentUserRoles; }
From source file:org.meruvian.yama.web.SessionCredentials.java
public static List<String> getAuthorities() { List<String> roles = new ArrayList<String>(); Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication() .getAuthorities();//w w w . ja v a 2s . c o m for (GrantedAuthority authority : authorities) { roles.add(authority.getAuthority()); } return roles; }
From source file:com.acc.oauth2.HybrisOauth2UserFilter.java
private static boolean containsRole(final Authentication auth, final String role) { for (final GrantedAuthority ga : auth.getAuthorities()) { if (ga.getAuthority().equals(role)) { return true; }//from w w w. j ava 2 s . co m } return false; }
From source file:org.socialhistoryservices.pid.util.NamingAuthority.java
public static List<String> getNaRole(Authentication userAuthentication) { final Collection<? extends GrantedAuthority> authorities = userAuthentication.getAuthorities(); final List<String> nas = new ArrayList(authorities.size()); for (GrantedAuthority authority : authorities) { String role = authority.getAuthority().replace("\n", ""); // ToDo: find out if there still is a \n in the role. if (role.startsWith(role_prefix)) { nas.add(role.substring(role_prefix.length())); } else if (role.startsWith(role_prefix_deprecated)) { nas.add(role.substring(role_prefix_deprecated.length())); }/* ww w .j a v a 2s . co m*/ } if (nas.size() == 0) throw new SecurityException("User " + userAuthentication.getName() + " has not got the required roles to use this service."); return nas; }
From source file:com.sshdemo.common.web.util.ContextUtil.java
private static Collection<String> getGrantedAuthorities(String perfix) { List<String> names = new ArrayList<String>(); UserDetails user = getUserDetails(); if (user == null) { return names; }//w ww. j a v a 2 s.c om Collection<? extends GrantedAuthority> authorites = user.getAuthorities(); for (GrantedAuthority auth : authorites) { if (StringUtils.startsWith(auth.getAuthority(), perfix)) { names.add(auth.getAuthority()); } } return names; }
From source file:org.appverse.web.framework.backend.security.xs.SecurityHelper.java
/** * Retrieves the authorities list corresponding to the currently authenticated principal * @return the authorities granted to the principal */// w w w . ja v a 2s .c om @SuppressWarnings("unchecked") public static List<String> getAuthorities() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); List<String> credentials = new ArrayList<String>(); Collection<GrantedAuthority> grantedAuthorities = (Collection<GrantedAuthority>) authentication .getAuthorities(); for (GrantedAuthority grantedAuthority : grantedAuthorities) { credentials.add(grantedAuthority.getAuthority()); } return credentials; }
From source file:org.mitre.oauth2.web.AuthenticationUtilities.java
/** * Check to see if the given auth object has ROLE_ADMIN assigned to it or not * @param auth/* w w w. j av a 2 s. c o m*/ * @return */ public static boolean isAdmin(Authentication auth) { for (GrantedAuthority grantedAuthority : auth.getAuthorities()) { if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) { return true; } } return false; }