验证当前用户是否属于以下所有角色。

@param roleNames 角色列表
@return 属于:true,否则false
185476
public static boolean hasAllRoles(String roleNames) {
        boolean hasAllRole = true;
        Subject subject = getSubject();
        if (subject != null && roleNames != null && roleNames.length() > 0) {
            // Iterate through roles and check to see if the user has one of the
            // roles
            for (String role : roleNames.split(NAMES_DELIMETER)) {
                if (!subject.hasRole(role.trim())) {
                    hasAllRole = false;
                    break;
                }
            }
        }
        return hasAllRole;
    }
1137277
@Transactional(readOnly = true)
    public E findByRoleName(String roleName) {

        SimpleExpression eqRoleName =
            Restrictions.eq("name", roleName);

        E role = dao.findByUniqueCriteria(eqRoleName);

        return role;
    }
999327
@Override
    public boolean isUserInRole(String role) {
        if (userRoles == null) {
            return false;
        }

        return userRoles.contains(role);
    }
988365
@Override
	public String[] searchRoles(String search) throws RolesException {
		// Complete list of users
		String[] roles = role_list.keySet().toArray(new String[role_list.size()]);
		List<String> found = new ArrayList<String>();

		// Look through the list for anyone who matches
		for (int i = 0; i < roles.length; i++) {
			if (roles[i].toLowerCase().contains(search.toLowerCase())) {
				found.add(roles[i]);
			}
		}

		// Return the list
		return found.toArray(new String[found.size()]);
	}
1117374
public boolean isUserInRole(String role)
    {
        Principal principal = getUserPrincipal();
        if (principal != null)
        {
            UserRealm realm = getHttpResponse().getHttpContext().getRealm();
            if (realm != null) return realm.isUserInRole(principal, role);
        }
        return false;
    }
994539
def has_any_roles(self, *roles):
        
        roles = map(utils.slugify, list(roles))

        return True \
            if AuthUserRole.query() \
            .join(AuthUser) \
            .filter(AuthUserRole.name.in_(roles)) \
            .filter(AuthUser.id == self.id) \
            .count() \
            else False
357217
public function hasRoles($roles): bool
    {
        $userRoles = $this->getRoles()->all();

        // We should ensure that all given roles match the current user,
        // consider it as a AND condition instead of OR.
        foreach ((array) $roles as $role) {
            if (! \in_array($role, $userRoles)) {
                return false;
            }
        }

        return true;
    }
307289
public static boolean hasAllRoles(RoleHolder roleHolder,
                                      String[] roleNames)
    {
        boolean hasRole = false;
        if (roleHolder != null)
        {
            List<? extends Role> roles = roleHolder.getRoles();

            if (roles != null)
            {
                List<String> heldRoles = new ArrayList<String>();
                for (Role role : roles)
                {
                    if (role != null)
                    {
                        heldRoles.add(role.getRoleName());
                    }
                }

                boolean roleCheckResult = true;
                for (int i = 0; roleCheckResult && i < roleNames.length; i++)
                {
                    boolean invert = false;
                    String roleName = roleNames[i];
                    if (roleName.startsWith("!"))
                    {
                        invert = true;
                        roleName = roleName.substring(1);
                    }
                    roleCheckResult = heldRoles.contains(roleName);

                    if (invert)
                    {
                        roleCheckResult = !roleCheckResult;
                    }
                }
                hasRole = roleCheckResult;
            }
        }
        return hasRole;
    }
1374301
private void verifyPermissionToGrantRoles(Subject subject, Iterable<RoleIdentifier> roleIds) {
        Set<RoleIdentifier> unauthorizedIds = Sets.newTreeSet();
        boolean anyAuthorized = false;

        for (RoleIdentifier roleId : roleIds) {
            // Verify the caller has permission to grant this role
            if (subject.hasPermission(Permissions.grantRole(roleId))) {
                anyAuthorized = true;
            } else {
                unauthorizedIds.add(roleId);
            }
        }

        if (!unauthorizedIds.isEmpty()) {
            // If the caller was not authorized to assign any of the provided roles raise a generic exception, otherwise
            // the exception provides insight as to which roles were unauthorized.  This provides some helpful feedback
            // where appropriate without exposing potentially exploitable information about whether the subject's API key
            // is valid.
            if (!anyAuthorized) {
                throw new UnauthorizedException();
            } else {
                throw new UnauthorizedException("Not authorized for roles: " + Joiner.on(", ").join(unauthorizedIds));
            }
        }
    }
1057656
public List<ResourceCollection> getByRole(Roles role)
  {
    return role == null ? ImmutableList.<ResourceCollection> of() : getByRole(role.toString());
  }
737021
public synchronized boolean isUserInRole(Principal user, String roleName)
    {
        if (user instanceof WrappedUser)
            return ((WrappedUser)user).isUserInRole(roleName);
         
        if (user==null || ((User)user).getUserRealm()!=this)
            return false;
        
        HashSet userSet = (HashSet)_roles.get(roleName);
        return userSet!=null && userSet.contains(user.getName());
    }
699492
@Override
    public void printRoles() {
        for (Role role : allRoles.values()) {
            Util.logPrint(role.toString());
        }
    }
961966
def has_role(user, roles):
    """"""
    if user and user.is_superuser:
        return True

    if not isinstance(roles, list):
        roles = [roles]

    normalized_roles = []
    for role in roles:
        if not inspect.isclass(role):
            role = RolesManager.retrieve_role(role)

        normalized_roles.append(role)

    user_roles = get_user_roles(user)

    return any([role in user_roles for role in normalized_roles])
104488
public boolean hasRole(String roleName){
        if (roles != null) {
            for (String r : roles) {
                if (r.equals(roleName))
                    return true;
            }
        }
        return false;
    }
298298
public boolean isCallerInRole(String roleName, Object bean)
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
        {
            Tr.entry(tc, "isCallerInRole, role = " + roleName
                         + " EJB = " + bean); //182011
        }

        // Check whether security is enabled or not. Note, the subclasses
        // do override this method to do additional processing and then they
        // call super.isCallerInRole which usually causes this code to
        // execute.  However, the subclass will throw IllegalStateException
        // (e.g. MessageDrivenBeanO) if not valid to call isCallerInRole.
        boolean inRole; //d444696.2
        EJBSecurityCollaborator<?> securityCollaborator = container.ivSecurityCollaborator;
        if (securityCollaborator == null) //d444696.2
        {
            // Security is disabled, so return false for 1.x and 2.x modules to
            // ensure pre EJB 3 applications see no behavior change. For EJB 3 modules
            // or later, return true so that we are consistent with web container.
            BeanMetaData bmd = home.beanMetaData;
            if (isTraceOn && tc.isDebugEnabled())
            {
                Tr.debug(tc, "isCallerInRole called with security disabled for EJB module version = "
                             + bmd.ivModuleVersion);
            }
            inRole = (bmd.ivModuleVersion >= BeanMetaData.J2EE_EJB_VERSION_3_0);
        }
        else //d444696.2
        {
            // Pass null EJSDeployedSupport for callback methods.            d739835
            EJSDeployedSupport s = bean == null ? null : EJSContainer.getMethodContext();

            try
            {
                inRole = isCallerInRole(securityCollaborator, roleName, s);
            } catch (RuntimeException ex)
            {
                FFDCFilter.processException(ex, CLASS_NAME + ".isCallerInRole", "982", this);
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "isCallerInRole collaborator throwing", ex);
                throw ex;
            }
        }

        if (isTraceOn && tc.isEntryEnabled()) //d444696.2
        {
            Tr.exit(tc, "isCallerInRole returning " + inRole);
        }
        return inRole; //d444696.2
    }
179081
public Collection<Peer> getPeers(EnumSet<PeerRole> roles) {

        Set<Peer> ret = new HashSet<>(getPeers().size());

        for (PeerRole peerRole : roles) {
            ret.addAll(peerRoleSetMap.get(peerRole));
        }

        return Collections.unmodifiableCollection(ret);
    }
1351002
public void setRoles(List<NamedRoleInfo> roles) {
		this.roles = roles;
		List<AuthorizationInfo> authorizations = new ArrayList<AuthorizationInfo>();
		for (NamedRoleInfo role : roles) {
			authorizations.addAll(role.getAuthorizations());
		}
		super.setAuthorizations(authorizations);
	}