From 3f0c599289d3fdce4412fc4ccb872998b9586635 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Tue, 25 Feb 2020 00:21:47 +0100 Subject: [PATCH] Use new IS_* attributes in the expression language functions --- .../Authorization/ExpressionLanguageProvider.php | 16 ++++++++-------- .../Authorization/ExpressionLanguageTest.php | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguageProvider.php b/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguageProvider.php index 449dbce61827..d8ff9d01f964 100644 --- a/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguageProvider.php +++ b/src/Symfony/Component/Security/Core/Authorization/ExpressionLanguageProvider.php @@ -25,21 +25,21 @@ public function getFunctions() { return [ new ExpressionFunction('is_anonymous', function () { - return '$trust_resolver->isAnonymous($token)'; + return '$token && $auth_checker->isGranted("IS_ANONYMOUS")'; }, function (array $variables) { - return $variables['trust_resolver']->isAnonymous($variables['token']); + return $variables['token'] && $variables['auth_checker']->isGranted('IS_ANONYMOUS'); }), new ExpressionFunction('is_authenticated', function () { - return '$token && !$trust_resolver->isAnonymous($token)'; + return '$token && !$auth_checker->isGranted("IS_ANONYMOUS")'; }, function (array $variables) { - return $variables['token'] && !$variables['trust_resolver']->isAnonymous($variables['token']); + return $variables['token'] && !$variables['auth_checker']->isGranted('IS_ANONYMOUS'); }), new ExpressionFunction('is_fully_authenticated', function () { - return '$trust_resolver->isFullFledged($token)'; + return '$token && $auth_checker->isGranted("IS_AUTHENTICATED_FULLY")'; }, function (array $variables) { - return $variables['trust_resolver']->isFullFledged($variables['token']); + return $variables['token'] && $variables['auth_checker']->isGranted('IS_AUTHENTICATED_FULLY'); }), new ExpressionFunction('is_granted', function ($attributes, $object = 'null') { @@ -49,9 +49,9 @@ public function getFunctions() }), new ExpressionFunction('is_remember_me', function () { - return '$trust_resolver->isRememberMe($token)'; + return '$token && $auth_checker->isGranted("IS_REMEMBERED")'; }, function (array $variables) { - return $variables['trust_resolver']->isRememberMe($variables['token']); + return $variables['token'] && $variables['auth_checker']->isGranted('IS_REMEMBERED'); }), ]; } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/ExpressionLanguageTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/ExpressionLanguageTest.php index 0e0e97dac6a0..9da77568b4de 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/ExpressionLanguageTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/ExpressionLanguageTest.php @@ -21,6 +21,7 @@ use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; use Symfony\Component\Security\Core\Authorization\ExpressionLanguage; +use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter; use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter; use Symfony\Component\Security\Core\User\User; @@ -35,11 +36,10 @@ public function testIsAuthenticated($token, $expression, $result) $trustResolver = new AuthenticationTrustResolver(); $tokenStorage = new TokenStorage(); $tokenStorage->setToken($token); - $accessDecisionManager = new AccessDecisionManager([new RoleVoter()]); + $accessDecisionManager = new AccessDecisionManager([new RoleVoter(), new AuthenticatedVoter($trustResolver)]); $authChecker = new AuthorizationChecker($tokenStorage, $this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(), $accessDecisionManager); $context = []; - $context['trust_resolver'] = $trustResolver; $context['auth_checker'] = $authChecker; $context['token'] = $token;