Skip to content

Commit e77f4c8

Browse files
committed
[Security] Deprecate the is_anonymous() expression function
1 parent db8694a commit e77f4c8

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

UPGRADE-5.4.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ Security
6161

6262
* Deprecate `AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY` and `AuthenticatedVoter::IS_ANONYMOUS`,
6363
use `AuthenticatedVoter::IS_AUTHENTICATED_FULLY` or `AuthenticatedVoter::IS_AUTHENTICATED` instead.
64-
* Deprecate `AuthenticationTrustResolverInterface::isAnonymous()` as anonymous no longer exists
65-
in version 6, use the `isFullFledged()` or the new `isAuthenticated()` instead if you want to
66-
check if the request is (fully) authenticated.
64+
* Deprecate `AuthenticationTrustResolverInterface::isAnonymous()` and the `is_anonymous()` expression function
65+
as anonymous no longer exists in version 6, use the `isFullFledged()` or the new `isAuthenticated()` instead
66+
if you want to check if the request is (fully) authenticated.
6767
* Deprecate the `$authManager` argument of `AccessListener`
6868
* Deprecate the `$authenticationManager` argument of the `AuthorizationChecker` constructor
6969
* Deprecate setting the `$alwaysAuthenticate` argument to `true` and not setting the

src/Symfony/Component/Security/Core/Authorization/ExpressionLanguageProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ public function getFunctions()
2626
{
2727
return [
2828
new ExpressionFunction('is_anonymous', function () {
29-
return '$token && $auth_checker->isGranted("IS_ANONYMOUS")';
29+
return 'trigger_deprecation("symfony/security-core", "5.4", "The \"is_anonymous()\" expression function is deprecated.") || ($token && $auth_checker->isGranted("IS_ANONYMOUS"))';
3030
}, function (array $variables) {
31+
trigger_deprecation('symfony/security-core', '5.4', 'The "is_anonymous()" expression function is deprecated.');
32+
3133
return $variables['token'] && $variables['auth_checker']->isGranted('IS_ANONYMOUS');
3234
}),
3335

3436
// @deprecated remove the ternary and always use IS_AUTHENTICATED in 6.0
3537
new ExpressionFunction('is_authenticated', function () {
3638
return 'defined("'.AuthenticatedVoter::class.'::IS_AUTHENTICATED") ? $auth_checker->isGranted("IS_AUTHENTICATED") : ($token && !$auth_checker->isGranted("IS_ANONYMOUS"))';
3739
}, function (array $variables) {
38-
return defined(AuthenticatedVoter::class.'::IS_AUTHENTICATED') ? $variables['auth_checker']->isGranted('IS_AUTHENTICATED') : ($variables['token'] && !$variables['auth_checker']->isGranted('IS_ANONYMOUS'));
40+
return \defined(AuthenticatedVoter::class.'::IS_AUTHENTICATED') ? $variables['auth_checker']->isGranted('IS_AUTHENTICATED') : ($variables['token'] && !$variables['auth_checker']->isGranted('IS_ANONYMOUS'));
3941
}),
4042

4143
new ExpressionFunction('is_fully_authenticated', function () {

src/Symfony/Component/Security/Core/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ CHANGELOG
66

77
* Deprecate `AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY` and `AuthenticatedVoter::IS_ANONYMOUS`,
88
use `AuthenticatedVoter::IS_AUTHENTICATED_FULLY` or `AuthenticatedVoter::IS_AUTHENTICATED` instead.
9-
* Deprecate `AuthenticationTrustResolverInterface::isAnonymous()` as anonymous no longer exists
10-
in version 6, use the `isFullFledged()` or the new `isAuthenticated()` instead if you want to
11-
check if the request is (fully) authenticated.
9+
* Deprecate `AuthenticationTrustResolverInterface::isAnonymous()` and the `is_anonymous()` expression
10+
function as anonymous no longer exists in version 6, use the `isFullFledged()` or the new
11+
`isAuthenticated()` instead if you want to check if the request is (fully) authenticated.
1212
* Deprecate the `$authenticationManager` argument of the `AuthorizationChecker` constructor
1313
* Deprecate setting the `$alwaysAuthenticate` argument to `true` and not setting the
1414
`$exceptionOnNoToken` argument to `false` of `AuthorizationChecker`

0 commit comments

Comments
 (0)