Checks if the current user has the specified role.

@param roleNames the names of the required roles
@return true iff the current user has the specified role
714
public static boolean hasRoles(List<String> roleNames) throws Throwable
    {
        DEADBOLT_HANDLER.beforeRoleCheck();

        RoleHolder roleHolder = getRoleHolder();

        return roleHolder != null &&
               roleHolder.getRoles() != null &&
               hasAllRoles(roleHolder,
                           roleNames.toArray(new String[roleNames.size()]));
    }
1175520
@Override
    final public boolean isCallerInRole(String roleName) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled()) {
            Tr.entry(tc, "isCallerInRole, role = " + roleName + ", state = " + StateStrs[state]);
        }

        if (state == METHOD_READY) // d571981
        {
            boolean inRole = super.isCallerInRole(roleName, ivEjbInstance);
            if (isTraceOn && tc.isEntryEnabled()) {
                Tr.exit(tc, "isCallerInRole: " + inRole);
            }
            return inRole;
        } else {
            throw new IllegalStateException("For Singleton, isCallerInRole only allowed while in METHOD_READY state");
        }
    }
1303757
public function hasAllRoles($roles): bool
    {
        if (is_string($roles) && false !== strpos($roles, '|')) {
            $roles = $this->convertPipeToArray($roles);
        }

        if (is_string($roles)) {
            return $this->roles->contains('name', $roles);
        }

        if ($roles instanceof Role) {
            return $this->roles->contains('id', $roles->id);
        }

        $roles = collect()->make($roles)->map(function ($role) {
            return $role instanceof Role ? $role->name : $role;
        });

        return $roles->intersect($this->roles->pluck('name')) == $roles;
    }
826222
public static boolean isLegalRoleName(String role) {
        return role != null &&
                role.length() > 0 && role.length() <= 255 &&
                ROLE_NAME_ALLOWED.matchesAllOf(role);
    }
1322258
def has_role?(role_in_question)
      return false unless role
      return true if role.name == role_in_question
      case role.name
      when 'Administrator'
        return true
      when 'Librarian'
        return true if role_in_question == 'User'
      else
        false
      end
    end
274034
public function hasRole($id, $role)
    {
        if (!$user = $this->getUser($id)) {
            return false;
        }

        return in_array($role, $user['roles']);
    }
1150774
private function checkRoleGlobalPermission($roleName, $permissionName)
    {
        $roles = $this->getRolesByGlobalPermission($permissionName);
        if (!is_array($roles)) {
            // We log it, unless the permission name is 'root'.
            if ($roleName !== self::ROLE_ROOT) {
                $this->app['logger.system']->warn(
                    "Configuration error: Permission '$permissionName' is not granted to any roles. You should add a role for this permission to <tt>permissions.yml</tt>.",
                    ['event' => 'authentication']
                );
            }

            return false;
        }

        return in_array($roleName, $roles);
    }
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])
1037470
public static boolean hasRoleOn(String role, String simpleScope) {
        return securitySupport.hasRole(role, new SimpleScope(simpleScope));
    }
318701
@Override
    public List<String> getUsers(String name) {
        if (!hasRole(name)) {
            throw new Error("error: name does not exist");
        }

        List<String> names = new ArrayList<>();
        for (Role role : allRoles.values()) {
            if (role.hasDirectRole(name)) {
                names.add(role.name);
            }
        }
        return names;
    }
808701
private List<String> getUsersFor(Collection<String> roles){
		List<String> users = new HashList<>();
		for(String role: roles){
			if(roleMembershipRU.containsKey(role))
				users.addAll(roleMembershipRU.get(role));
		}
		return users;
	}
1190327
public function hasRole($role)
    {
        return is_null($this->roles) || in_array($role, $this->roles, true);
    }
27985
def is_admin(self, roles):
        """"""
        for r in roles:
            if r in self.admin_roles:
                return True
        return False
459017
public function hasRole(...$roles)
    {
        $roles = array_flatten($roles);

        foreach ($roles as $role) {
            $name = $role instanceof Role ? $role->name : $role;

            if ($this->roles->contains('name', $name)) {
                return true;
            }
        }

        return false;
    }
1279931
private function checkRoleHierarchyPermission($roleName, $permissionName, $role)
    {
        // Can current user manipulate role?
        if (is_string($role)) {
            $permissions = $this->app['config']->get("permissions/roles-hierarchy/$permissionName/$role", []);

            return in_array($roleName, $permissions);
        }

        // Can current user manipulate user?
        $user = $role;
        foreach ($user['roles'] as $role) {
            $permissions = $this->app['config']->get("permissions/roles-hierarchy/$permissionName/$role", []);
            if (in_array($roleName, $permissions)) {
                return true;
            }
        }

        return false;
    }
1287186
public function hasRole(string $role): bool
    {
        return (null !== $this->roles) ? \in_array($role, $this->roles) : false;
    }
282324
function hasRole(roleRequired) {
  if (!roleRequired) {
    throw new Error('Required role needs to be set');
  }

  return compose()
    .use(isAuthenticated())
    .use(function meetsRequirements(req, res, next) {
      if (roles.hasRole(req.userInfo.role, roleRequired)) {
        next();
      } else {
        res.forbidden();
      }
    });
}