/** * @param null $arguments * @param RenderingContextInterface $renderingContext * @return bool */ protected static function evaluateCondition($arguments = null, RenderingContextInterface $renderingContext) { $objectManager = $renderingContext->getObjectManager(); /** @var Context $securityContext */ $securityContext = $objectManager->get(Context::class); $activeTokens = $securityContext->getAuthenticationTokens(); $isAuthenticated = false; foreach ($activeTokens as $token) { if ($token->isAuthenticated()) { $isAuthenticated = true; } } return $isAuthenticated; }
/** * @test */ public function getObjectManagerReturnsObjectManagerPropertyValue() { $this->renderingContext->_set('objectManager', 'test'); $this->assertEquals('test', $this->renderingContext->getObjectManager()); }
/** * @param null $arguments * @param RenderingContextInterface $renderingContext * @return boolean */ protected static function evaluateCondition($arguments = null, RenderingContextInterface $renderingContext) { $objectManager = $renderingContext->getObjectManager(); /** @var PolicyService $policyService */ $policyService = $objectManager->get(PolicyService::class); /** @var Context $securityContext */ $securityContext = $objectManager->get(Context::class); $role = $arguments['role']; $account = $arguments['account']; $packageKey = isset($arguments['packageKey']) ? $arguments['packageKey'] : $renderingContext->getControllerContext()->getRequest()->getControllerPackageKey(); if (is_string($role)) { $roleIdentifier = $role; if (in_array($roleIdentifier, ['Everybody', 'Anonymous', 'AuthenticatedUser'])) { $roleIdentifier = 'Neos.Flow:' . $roleIdentifier; } if (strpos($roleIdentifier, '.') === false && strpos($roleIdentifier, ':') === false) { $roleIdentifier = $packageKey . ':' . $roleIdentifier; } $role = $policyService->getRole($roleIdentifier); } $hasRole = $securityContext->hasRole($role->getIdentifier()); if ($account instanceof Account) { $hasRole = $account->hasRole($role); } return $hasRole; }