Build the permission contexts for the role.

@param RoleInterface $role The role

@return null|string[]
180588
protected function buildContexts(RoleInterface $role)
    {
        $contexts = null;

        if ($role instanceof OrganizationalInterface) {
            $contexts = [null !== $role->getOrganization() ? PermissionContexts::ORGANIZATION_ROLE : PermissionContexts::ROLE];
        }

        return $contexts;
    }
170581
public function getCallerPermissions(Caller $caller)
    {
        $key = $this->getCallerKey($caller);

        return array_key_exists($key, $this->permissions) ? $this->permissions[$key] : [];
    }
878596
private function getRoles(ApiUserInterface $user)
    {
        $roles = $user->getRoles();
        if ($user->getApiKeyEnabled()) {
            $roles[] = $this->apiUserRole;
        }

        return $roles;
    }
407789
public function getRolePermissions(Role $role)
    {
        $key = $this->getRoleKey($role);

        return array_key_exists($key, $this->permissions) ? $this->permissions[$key] : [];
    }
1291846
protected static function getSecurityIdentityForCurrentOrganization(
        OrganizationalContextInterface $context,
        $roleHierarchy = null
    ) {
        $sids = [];
        $org = $context->getCurrentOrganization();
        $userOrg = $context->getCurrentOrganizationUser();
        $orgRoles = [];

        if ($org) {
            $sids[] = self::fromAccount($org);
        }

        if (null !== $userOrg) {
            $sids = array_merge($sids, static::getOrganizationGroups($userOrg));
            $orgRoles = static::getOrganizationUserRoles($userOrg, $roleHierarchy);
        } elseif ($org && $org->isUserOrganization()) {
            $orgRoles = static::getOrganizationRoles($org, $roleHierarchy);
        }

        foreach ($orgRoles as $role) {
            $sids[] = RoleSecurityIdentity::fromAccount($role);
        }

        return $sids;
    }
1080800
public function userHasRole($roleName, DeterminableUserInterface $user)
    {
        $userHasRole = false;
        if (true === in_array($roleName, $user->getRoles())) {
            $userHasRole = true;
        }
        return $userHasRole;
    }
942099
public function grantAccessByRoles($roles, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();
        return count(array_diff($roles, $user->getRoles())) === 0;
    }
661031
protected function getHierarchy($role, array $roleHierarchy)
    {
        $roles = [];
        if (array_key_exists($role, $roleHierarchy)) {
            $roleRoles = (array) $roleHierarchy[$role];
            foreach ($roleRoles as $role) {
                $roles = array_merge($roles, $this->getHierarchy($role, $roleHierarchy));
            }
            $roles = array_merge($roles, $roleRoles);
        }

        return $roles;
    }
338233
public function rolesPermissions() {
    return [
      self::ROLE_USER => [
      ],
      self::ROLE_USER_MANAGER => [
        self::USER_VIEW,
        self::USER_CREATE,
        self::USER_UPDATE,
        self::USER_CHANGE_SECURITY_INFO,
        self::USER_CHANGE_PROFILE_INFO,
      ],
      self::ROLE_ADMIN => [
      ],
    ];
  }
72870
public function addRole(string $role): PermissionManager
    {
        if ($this->hasRole($role)) {
            throw new RoleException("Role '{$role}' already exists");
        }

        $this->permissions[$role] = [
            //No associated permissions
        ];

        return $this;
    }
1003628
protected function getRole($roleName)
    {
        if (isset($this->roles[$roleName])) {
            return $this->roles[$roleName];
        }

        // If no config, we create a simple role with no permission
        if (!isset($this->rolesConfig[$roleName])) {
            $role = new Role($roleName);
            $this->roles[$roleName] = $role;
            return $role;
        }

        $roleConfig = $this->rolesConfig[$roleName];

        if (isset($roleConfig['children'])) {
            $role = new HierarchicalRole($roleName);
            $childRoles = (array)$roleConfig['children'];
            foreach ($childRoles as $childRole) {
                $childRole = $this->getRole($childRole);
                $role->addChild($childRole);
            }
        } else {
            $role = new Role($roleName);
        }

        $permissions = isset($roleConfig['permissions']) ? $roleConfig['permissions'] : [];
        foreach ($permissions as $permission) {
            $role->addPermission($permission);
        }

        $this->roles[$roleName] = $role;

        return $role;
    }
174829
public function getIdentityRoles(UserInterface $user = null)
    {
        if ($user === null) {
            $user = $this->getDefaultIdentity();
            if (!$user) {
                return (array) $this->getModuleOptions()->getDefaultGuestRole();
            }
        }

        $resultSet = $this->getUserRoleLinkerMapper()->findByUser($user);

        if (count($resultSet) > 0) { // if exists in database
            $roles = array();
            foreach ($resultSet  as $userRoleLinker) {
                $roles[] = $userRoleLinker->getRoleId();
            }

            return $roles;
        } else {
            return (array) $this->getModuleOptions()->getDefaultUserRole();
        }

    }
731195
protected static function getOrganizationRoles(OrganizationInterface $organization, $roleHierarchy = null)
    {
        $roles = [];

        if ($organization instanceof RoleableInterface && $organization instanceof OrganizationInterface) {
            $roles = self::buildOrganizationRoles([], $organization);

            if ($roleHierarchy instanceof RoleHierarchyInterface) {
                $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles));
            }
        }

        return $roles;
    }
276688
public function removeRole(string $role): PermissionManager
    {
        if (!$this->hasRole($role)) {
            throw new RoleException("Undefined role '{$role}'");
        }

        unset($this->permissions[$role]);

        return $this;
    }
557541
public function setRole( Acl\Role\RoleInterface $role = null )
    {
        $this->role = $role;
        return $this;
    }
972986
public function removeRole(RoleInterface $role)
    {
        $this->roles->removeElement($role);

        if ($role->hasUser($this) === true)
            $role->removeUser($this);
        
        return $this;
    }
1287162
public function getPermission($role)
    {
        if ($role instanceof RoleInterface || $role instanceof \Symfony\Component\Security\Core\Role\Role) {
            $role = $role->getRole();
        }
        if (isset($this->permissions[$role])) {
            return $this->permissions[$role];
        }

        return null;
    }