Get the security identities for all organizations of user.

@param UserInterface               $user          The user
@param null|RoleHierarchyInterface $roleHierarchy The role hierarchy

@return SecurityIdentityInterface[]
11200
protected static function getSecurityIdentityForAllOrganizations(UserInterface $user, $roleHierarchy = null)
    {
        $sids = [];

        if ($user instanceof UserOrganizationUsersInterface) {
            foreach ($user->getUserOrganizations() as $userOrg) {
                $sids[] = self::fromAccount($userOrg->getOrganization());
                $sids = array_merge($sids, static::getOrganizationGroups($userOrg));
                $roles = static::getOrganizationUserRoles($userOrg, $roleHierarchy);

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

        return $sids;
    }
340871
public function getIncludeUserIds()
    {
        $userIds = array();
        $roleUsers = $this->role->getUsers();
        foreach ($roleUsers as $user) {
            array_push($userIds, $user->getId());
        }
        $roleGroups = $this->role->getGroups();
        foreach ($roleGroups as $group) {
            $userIds = array_merge($userIds, $group->getUserIds());
        }
        $userIds = array_unique($userIds);

        return $userIds;
    }
595478
public function getAssignments(User $user)
    {
        $assignments = [];
        foreach ($this->getInternalServices() as $service) {
            $assignments = array_merge($assignments, $service->getAssignments($user));
        }

        return $assignments;
    }
851114
public function roles(User $user)
    {
        if ($this->session->hasValue(Roles::SESSION_KEY)) {
            return $this->session->value(Roles::SESSION_KEY);
        }

        $roles = $this->authorizationProvider->roles($user);
        $this->session->putValue(Roles::SESSION_KEY, $roles);
        return $roles;
    }
317763
protected function getCoinsEntry(UserInterface $user)
    {
        $class = $this->getGameOptions()->getEntityBillingClass();
        $accEntityManager = $this->getBillingEntityManager();

        /** @var \GameBackend\Entity\CrossFire\Repository\Billing $repository */
        $repository = $accEntityManager->getRepository($class);
        return $repository->getEntry4User($user);
    }
949461
public function findNotInRole(RoleInterface $role)
    {
        return array_filter(
            $this->findAll(),
            function ($user) use ($role) {
                return $user->not($role->key);
            }
        );
    }
312186
private function getAllRoles(TokenInterface $token)
    {
        if (null !== $this->sim) {
            $sids = $this->sim->getSecurityIdentities($token);

            return IdentityUtils::filterRolesIdentities($sids);
        }

        return RoleUtil::formatNames($token->getRoles());
    }
822366
public static function isSuperAdmin(\Nette\Security\User $user)
    {
        $roles = $user->getIdentity()->getRoles();

        return in_array('superadmin', $roles);
    }
1369074
protected function getUserId(UserInterface $user)
    {
        $class = $this->container->getParameter('tree_house.keystone.model.user.class');
        $meta = $this->getDoctrine()->getManagerForClass($class)->getClassMetadata($class);

        $ids = $meta->getIdentifierValues($user);
        if (sizeof($ids) === 1) {
            return current($ids);
        }

        return $ids;
    }
121086
private function getUserRolesAsObjects(UserInterface $user)
    {
        $userRoles = array();
        foreach ($user->getRoles() as $userRole) {
            $userRoles[] = $userRole instanceof Role ? $userRole : new Role($userRole);
        }

        return $userRoles;
    }
10828
protected function convertRole(RoleInterface $role)
    {
        $roleData['id'] = $role->getId();
        $roleData['name'] = $role->getName();
        $roleData['identifier'] = $role->getIdentifier();
        $roleData['system'] = $role->getSystem();
        $roleData['permissions'] = [];

        $permissions = $role->getPermissions();
        if (!empty($permissions)) {
            foreach ($permissions as $permission) {
                /* @var Permission $permission */
                $roleData['permissions'][] = [
                    'id' => $permission->getId(),
                    'context' => $permission->getContext(),
                    'module' => $permission->getModule(),
                    'permissions' => $this->get('sulu_security.mask_converter')
                        ->convertPermissionsToArray($permission->getPermissions()),
                ];
            }
        }

        $securityType = $role->getSecurityType();
        if ($securityType) {
            $roleData['securityType'] = [
                'id' => $securityType->getId(),
                'name' => $securityType->getName(),
            ];
        }

        return $roleData;
    }
319892
private function getUserKey(PKEncryptionEnabledUserInterface $user)
    {
        $pkiKey = $this->findKeyByUser($user);

        if (!$pkiKey) {
            $userId = $user->getId();
            $userClass = $this->getUserClass($user);

            $pkiKey = new PKIPrivateKey();
            $pkiKey->setUserClass($userClass);
            $pkiKey->setUserId($userId);
        }

        return $pkiKey;
    }
903745
public function getUserRoles( core_kernel_classes_Resource $user)
    {
        $returnValue = array();
        // We use a Depth First Search approach to flatten the Roles Graph.
        $rolesProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_ROLES);
        $rootRoles = $user->getPropertyValuesCollection($rolesProperty);
        
        foreach ($rootRoles->getIterator() as $r){
        	$returnValue[$r->getUri()] = $r;
        	$returnValue = array_merge($returnValue, $this->getIncludedRoles($r));
        }
        
        $returnValue = array_unique($returnValue);
        
        return (array) $returnValue;
    }
271206
protected function getImpersonatingUserFromRole($token, $user = null)
    {
        foreach ($token->getRoles() as $role) {
            if ($role instanceof SwitchUserRole) {
                $user = $role->getSource()->getUser();
                break;
            }
        }

        return $user;
    }
254082
private function getEmail(UserInterface $user)
    {
        if (null !== $user->getEmail()) {
            return $user->getEmail();
        }

        return $this->container->getParameter('sulu_admin.email');
    }
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();
        }

    }
220250
final public function hasRequiredRole(UserInterface $user = null, array $roles = [])
    {
        if ($user != null) {
            // Check if user's roles matches required roles
            $userRoles = $user->getRoles();

            foreach ($userRoles as $role) {
                if (\in_array($role, $roles)) {
                    return true;
                }
            }
        }

        return false;
    }