Find facets visible by the current User.

@param TokenInterface $token
@param bool           $isRegistration

@return Facet[]
327301
public function findVisibleFacets(TokenInterface $token, $isRegistration = false)
    {
        // retrieves current user roles
        $roleNames = array_map(function (Role $role) {
            return $role->getRole();
        }, $token->getRoles());

        $qb = $this->createQueryBuilder('f');

        if ($isRegistration) {
            $qb->andWhere('f.forceCreationForm = true');
        } else {
            if (!in_array('ROLE_ADMIN', $roleNames)) {
                // filter query to only get accessible facets for the current roles
                $qb
                  ->leftJoin('f.roles', 'r')
                  ->where('(r.id IS NULL OR r.name IN (:roles))')
                  ->setParameter('roles', $roleNames);
            }
        }

        $qb->orderBy('f.main DESC, f.position');

        return $qb->getQuery()->getResult();
    }
45994
protected function findTagsByIdentifier(string $identifier): array
    {
        $success = false;
        $tags = apcu_fetch($this->identifierPrefix . 'ident_' . $identifier, $success);
        return ($success ? (array)$tags : []);
    }
658581
public function getAvailableSites()
    {
        $sites = array();
        $token = $this->tokenStorage->getToken();
        if ($token instanceof TokenInterface) {
            if ($this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN)) {
                return $this->siteRepository->findByDeleted(false);
            }

            if (($user = $token->getUser()) instanceof GroupableInterface) {
                foreach ($user->getGroups() as $group) {
                    /** @var SiteInterface $site */
                    $site = $group->getSite();
                    if (null !== $site && !$group->isDeleted() && !$site->isDeleted()) {
                        $sites[$site->getId()] = $site;
                    }
                }
            }
        }

        return $sites;
    }
113785
protected function refreshUser(TokenInterface $token)
    {
        $user = $token->getUser();

        if (!$user instanceof UserInterface) {
            return;
        }

        $refreshedUser = $this->userProvider->refreshUser($user);
        $token->setUser($refreshedUser);

        return $token;
    }
394535
public function checkRegisterRoles($packageId = '', $carrier = '', $isPackage = FALSE)
    {
        $packageSettings           = $this->packageSettings;
        $currentSessionListPackage = $this->getListUserPackageId();
        if (is_array($currentSessionListPackage)) {
            if (in_array($packageId, $currentSessionListPackage)) {
                return TRUE;
            }
            if ($isPackage !== TRUE) {
                foreach ($currentSessionListPackage as $params) {
                    $packageGroup = $packageSettings[$carrier][$params]['category_group'];
                    if (in_array($packageId, $packageGroup)) {
                        return TRUE;
                    }
                }
            }
        }
        if ($isPackage !== TRUE) {
            $packageGroup = $packageSettings[$carrier][$packageId]['category_group'];
            if (in_array($currentSessionListPackage, $packageGroup)) {
                return TRUE;
            }
        }
        if ($packageId == $currentSessionListPackage) {
            return TRUE;
        }

        return FALSE;
    }
489554
public function getSecurityIdentities(TokenInterface $token)
    {
        $sids = parent::getSecurityIdentities($token);

        if ($token->getUser() instanceof \BackBee\Security\User) {
            foreach ($token->getUser()->getGroups() as $group) {
                $securityIdentity = new UserSecurityIdentity($group->getObjectIdentifier(), ClassUtils::getRealClass($group));
                array_unshift($sids, $securityIdentity);
            }
        }

        return $sids;
    }
1136121
public function generateTokenValues(TokenInterface $token): array
    {
        $tokenValue     = bin2hex(random_bytes(16)) . uniqid();
        $tokenType      = 'bearer';
        $tokenExpiresIn = $this->getTokenExpirationPeriod();
        $refreshValue   = bin2hex(random_bytes(16)) . uniqid();

        assert(is_string($tokenValue) === true && empty($tokenValue) === false);
        assert(is_string($tokenType) === true && empty($tokenType) === false);
        assert(is_int($tokenExpiresIn) === true && $tokenExpiresIn > 0);
        assert($refreshValue === null || (is_string($refreshValue) === true && empty($refreshValue) === false));

        return [$tokenValue, $tokenType, $tokenExpiresIn, $refreshValue];
    }
1149484
private function checkJWT(JWTInterface $jwt)
    {
        $checked_claims = [];

        foreach ($this->claim_checkers as $claim_checker) {
            $checked_claims = array_merge(
                $checked_claims,
                $claim_checker->checkClaim($jwt)
            );
        }

        return $checked_claims;
    }
384346
public function getMarkedPlaces($subject, $placesNameOnly = true, $name = null)
    {
        $places = $this->workflowRegistry->get($subject, $name)->getMarking($subject)->getPlaces();

        if ($placesNameOnly) {
            return array_keys($places);
        }

        return $places;
    }
432495
public static function findByActivationToken($token)
    {
        if (!static::isActivationTokenValid($token)) {
            return null;
        }
        return static::find()->where(['activation_token' => $token, 'status' => self::STATUS_REGISTERED])->limit(1)->one();
    }
516544
public function getAllDrafts(TokenInterface $token)
    {
        $owner = UserSecurityIdentity::fromToken($token);
        $states = [Revision::STATE_ADDED, Revision::STATE_MODIFIED];

        $result = [];

        try {
            $result = $this->findBy([
                '_owner' => $owner,
                '_state' => $states,
            ]);
        } catch (ConversionException $e) {
            $result = [];
            foreach ($this->getAllDraftsUids($owner, $states) as $data) {
                try {
                    $result[] = $this->find($data['_uid']);
                } catch (ConversionException $e) {
                    $this->_em->getConnection()->executeUpdate(
                        'DELETE FROM revision WHERE uid = :uid',
                        ['uid' => $data['_uid']]
                    );
                }
            }
        } catch (MappingException $e) {
            $result = [];
            foreach ($this->getAllDraftsUids($owner, $states) as $data) {
                $draft = $this->find($data['_uid']);
                if (null !== $draft->getContent()) {
                    $result[] = $draft;
                } else {
                    $this->_em->getConnection()->executeUpdate(
                        'DELETE FROM revision WHERE uid = :uid',
                        ['uid' => $data['_uid']]
                    );
                }
            }
        }

        return $result;
    }
1153064
public static function getTokenCustomProperties(ContainerInterface $container, TokenInterface $token): array
    {
        $userId = $token->getUserIdentifier();

        /** @var FactoryInterface $factory */
        $factory = $container->get(FactoryInterface::class);
        /** @var UsersApi $usersApi */
        $usersApi = $factory->createApi(UsersApi::class);

        $builder = $usersApi->shouldBeUntyped()->withIndexFilter($userId)->createIndexBuilder([
            User::FIELD_EMAIL,
            User::FIELD_FIRST_NAME,
            User::FIELD_LAST_NAME,
        ]);

        $user = $usersApi->fetchRow($builder, User::class);

        return [
            User::FIELD_ID         => $userId,
            User::FIELD_EMAIL      => $user[User::FIELD_EMAIL],
            User::FIELD_FIRST_NAME => $user[User::FIELD_FIRST_NAME],
            User::FIELD_LAST_NAME  => $user[User::FIELD_LAST_NAME],
        ];
    }
829987
public function getEntityRoles($areGroupsIncluded = true)
    {
        $roles = [];
        if ($this->roles) {
            $roles = $this->roles->toArray();
        }

        if ($areGroupsIncluded) {
            foreach ($this->groups as $group) {
                foreach ($group->getEntityRoles() as $role) {
                    if (!in_array($role, $roles)) {
                        $roles[] = $role;
                    }
                }
            }
        }

        return $roles;
    }
196943
protected function findUserByToken(Token $token)
    {
        // retrieves the user ID from the token.
        $id = $token->getClaim('sub');

        // use the users provider to find the token subject (user)
        // but it's id (subject)
        return $this->provider->retrieveById($id);
    }
777004
public function getAPI(TokenInterface $token) {
            $id = $token->getService();
            if (!isset($this->apis[$id])) {
                // TODO: execption
                return null;
            }
            if (is_string($this->apis[$id])) {
                $this->apis[$id] = $this->container->get($this->apis[$id]);
            }

            $this->apis[$id]->setAccessToken($token);
            return $this->apis[$id];
        }
1057660
public function checkCreation(TokenInterface $token, $object)
    {
        return $this->manager->isAllowedBadgeManagement($token, $object->getBadge());
    }
1109832
public function showRegistrationForm($token = null)
    {
        $this->showPageBanner = false;

        // check if token is valid
        $userInvite = UserInvite::whereToken($token)->whereNull('claimed_at')->first();

        return $this->view('titan::register')->with('userInvite', $userInvite);
    }