List of usage examples for org.springframework.security.core Authentication getAuthorities
Collection<? extends GrantedAuthority> getAuthorities();
AuthenticationManager
to indicate the authorities that the principal has been granted. 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//from w w w . j a v a 2s . 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; }
From source file:com.pwsz.kutadaniel.controllers.SecurityHelper.java
/** * * @param authentication authentication/*from w w w . ja va 2 s.c o m*/ * @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:org.mitre.oauth2.web.AuthenticationUtilities.java
public static boolean hasRole(Authentication auth, String role) { for (GrantedAuthority grantedAuthority : auth.getAuthorities()) { if (grantedAuthority.getAuthority().equals(role)) { return true; }//from w w w . jav a 2 s.co m } return false; }
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; }/* w w w. ja v a 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())); }/* w w w. ja va2 s .c om*/ } 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:de.chludwig.websec.saml2sp.springconfig.CurrentUserHandlerMethodArgumentResolver.java
private static Set<RoleId> getUserRoles(Authentication auth) { Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); Set<RoleId> roles = new HashSet<>(authorities.size()); for (GrantedAuthority authority : authorities) { RoleId roleId = RoleId.valueById(authority.getAuthority()); if (roleId != null) { roles.add(roleId);//ww w .j a v a 2 s.c o m } } return roles; }
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()); }//from w w w . ja v a 2 s . c om if (LOG.isDebugEnabled()) { LOG.debug("currentUserRoles:" + currentUserRoles); } return currentUserRoles; }
From source file:com.inkubator.securitycore.util.UserInfoUtil.java
public static List<String> getRoles() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); List<String> listAuth; if (auth != null) { listAuth = toStringList(auth.getAuthorities()); } else {/*from w w w . ja v a 2 s .c o m*/ listAuth = Collections.emptyList(); } return listAuth; }
From source file:org.slc.sli.dashboard.util.SecurityUtil.java
/** * find if a user is IT Administrator or Leader * * @return//from w ww .ja va 2 s . c o m */ public static boolean isNotEducator() { SecurityContext context = SecurityContextHolder.getContext(); if (context != null) { Authentication authentication = context.getAuthentication(); if (authentication != null) { Collection<GrantedAuthority> authorities = authentication.getAuthorities(); for (GrantedAuthority authority : authorities) { if (authority.getAuthority().equals(Constants.ROLE_IT_ADMINISTRATOR)) { return true; } else if (authority.getAuthority().equals(Constants.ROLE_LEADER)) { return true; } } } } return false; }
From source file:com.lll.util.SpringSecurityUtils.java
/** * ?, ??true.//from w w w . ja v a 2 s . c o m */ public static boolean hasAnyRole(String[] roles) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Collection<GrantedAuthority> granteds = authentication.getAuthorities(); for (String role : roles) { for (GrantedAuthority authority : granteds) { if (role.equals(authority.getAuthority())) { return true; } } } return false; }