8000 Use new IS_* attributes in the expression language functions · symfony/security-core@9aba4d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9aba4d0

Browse files
committed
Use new IS_* attributes in the expression language functions
1 parent 122a935 commit 9aba4d0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Authorization/ExpressionLanguageProvider.php

Lines changed: 8 additions & 8 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ public function getFunctions()
2525
{
2626
return [
2727
new ExpressionFunction('is_anonymous', function () {
28-
return '$trust_resolver->isAnonymous($token)';
28+
return '$token && $auth_checker->isGranted("IS_ANONYMOUS")';
2929
}, function (array $variables) {
30-
return $variables['trust_resolver']->isAnonymous($variables['token']);
30+
return $variables['token'] && $variables['auth_checker']->isGranted('IS_ANONYMOUS');
3131
}),
3232

3333
new ExpressionFunction('is_authenticated', function () {
34-
return '$token && !$trust_resolver->isAnonymous($token)';
34+
return '$token && !$auth_checker->isGranted("IS_ANONYMOUS")';
3535
}, function (array $variables) {
36-
return $variables['token'] && !$variables['trust_resolver']->isAnonymous($variables['token']);
36+
return $variables['token'] && !$variables['auth_checker']->isGranted('IS_ANONYMOUS');
3737
}),
3838

3939
new ExpressionFunction('is_fully_authenticated', function () {
40-
return '$trust_resolver->isFullFledged($token)';
40+
return '$token && $auth_checker->isGranted("IS_AUTHENTICATED_FULLY")';
4141
}, function (array $variables) {
42-
return $variables['trust_resolver']->isFullFledged($variables['token']);
42+
return $variables['token'] && $variables['auth_checker']->isGranted('IS_AUTHENTICATED_FULLY');
4343
}),
4444

4545
new ExpressionFunction('is_granted', function ($attributes, $object = 'null') {
@@ -49,9 +49,9 @@ public function getFunctions()
4949
}),
5050

5151
new ExpressionFunction('is_remember_me', function () {
52-
return '$trust_resolver->isRememberMe($token)';
52+
return '$token && $auth_checker->isGranted("IS_REMEMBERED")';
5353
}, function (array $variables) {
54-
return $variables['trust_resolver']->isRememberMe($variables['token']);
54+
return $variables['token'] && $variables['auth_checker']->isGranted('IS_REMEMBERED');
5555
}),
5656
];
5757
}

Tests/Authorization/ExpressionLanguageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
2222
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
2323
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
24+
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2425
use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
2526
use Symfony\Component\Security\Core\User\User;
2627

@@ -35,11 +36,10 @@ public function testIsAuthenticated($token, $expression, $result)
3536
$trustResolver = new AuthenticationTrustResolver();
3637
$tokenStorage = new TokenStorage();
3738
$tokenStorage->setToken($token);
38-
$accessDecisionManager = new AccessDecisionManager([new RoleVoter()]);
39+
$accessDecisionManager = new AccessDecisionManager([new RoleVoter(), new AuthenticatedVoter($trustResolver)]);
3940
$authChecker = new AuthorizationChecker($tokenStorage, $this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(), $accessDecisionManager);
4041

4142
$context = [];
42-
$context['trust_resolver'] = $trustResolver;
4343
$context['auth_checker'] = $authChecker;
4444
$context['token'] = $token;
4545

0 commit comments

Comments
 (0)
0