8000 Deprecated is_*() expression functions · symfony/symfony@19ed26f · GitHub
[go: up one dir, main page]

Skip to content

Commit 19ed26f

Browse files
committed
Deprecated is_*() expression functions
is_granted() should be used instead with the correct attributes
1 parent 0d888e5 commit 19ed26f

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

UPGRADE-5.0.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ Security
347347
`__serialize` and `__unserialize`
348348
* The `IS_AUTHENTICATED_ANONYMOUSLY` attribute is removed, use `IS_AUTHENTICATED` instead.
349349
* The `IS_AUTHENTICATED_REMEMBERED` attribute is removed, use `IS_REMEMBERED` instead.
350+
* The `is_anonymous()`, `is_remember_me()`, `is_authenticated()` and `is_fully_authenticated()` expression functions are removed. Use `is_granted()` with the correct attribute instead:
351+
352+
Before:
353+
```
354+
is_remember_me() or is_anonymous()
355+
```
356+
357+
After:
358+
```
359+
is_granted('IS_REMEBERED') or is_granted('IS_ANONYMOUS')
360+
```
350361

351362
SecurityBundle
352363
--------------

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CHANGELOG
2626
* Deprecated `IS_AUTHENTICATED_ANONYMOUSLY` in favor of `IS_AUTHENTICATED`
2727
* Deprecated `IS_AUTHENTICATED_REMEMBERED` in favor of `IS_REMEMBERED`
2828
* Added `IS_ANONYMOUS`
29+
* Deprecated `is_anonymous()`, `is_remember_me()`, `is_authenticated()` and `is_fully_authenticated()` in favor of `is_granted(attribute)`
2930

3031
4.2.0
3132
-----

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,32 @@ public function getFunctions()
2525
{
2626
return [
2727
new ExpressionFunction('is_anonymous', function () {
28+
@trigger_error("is_anonymous() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_ANONYMOUS') instead.", E_USER_DEPRECATED);
29+
2830
return '$trust_resolver->isAnonymous($token)';
2931
}, function (array $variables) {
32+
@trigger_error("is_anonymous() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_ANONYMOUS') instead.", E_USER_DEPRECATED);
33+
3034
return $variables['trust_resolver']->isAnonymous($variables['token']);
3135
}),
3236

3337
new ExpressionFunction('is_authenticated', function () {
38+
@trigger_error("is_authenticated() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_AUTHENTICATED') instead.", E_USER_DEPRECATED);
39+
3440
return '$token && !$trust_resolver->isAnonymous($token)';
3541
}, function (array $variables) {
42+
@trigger_error("is_authenticated() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_AUTHENTICATED') instead.", E_USER_DEPRECATED);
43+
3644
return $variables['token'] && !$variables['trust_resolver']->isAnonymous($variables['token']);
3745
}),
3846

3947
new ExpressionFunction('is_fully_authenticated', function () {
48+
@trigger_error("is_fully_authenticated() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_AUTHENTICATED_FULLY') instead.", E_USER_DEPRECATED);
49+
4050
return '$trust_resolver->isFullFledged($token)';
4151
}, function (array $variables) {
52+
@trigger_error("is_fully_authenticated() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_AUTHENTICATED_FULLY') instead.", E_USER_DEPRECATED);
53+
4254
return $variables['trust_resolver']->isFullFledged($variables['token']);
4355
}),
4456

@@ -49,8 +61,12 @@ public function getFunctions()
4961
}),
5062

5163
new ExpressionFunction('is_remember_me', function () {
64+
@trigger_error("is_remember_me() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_REMEMBERED') instead.", E_USER_DEPRECATED);
65+
5266
return '$trust_resolver->isRememberMe($token)';
5367
}, function (array $variables) {
68+
@trigger_error("is_remember_me() is deprecated since version 4.3 and will be removed in 5.0. Use is_granted('IS_REMEMBERED') instead.", E_USER_DEPRECATED);
69+
5470
return $variables['trust_resolver']->isRememberMe($variables['token']);
5571
}),
5672

src/Symfony/Component/Security/Core/Tests/Authorization/ExpressionLanguageTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ public function provider()
5858

5959
return [
6060
[$noToken, 'is_anonymous()', false],
61-
[$noToken, 'is_authenticated()', false],
61+
[$noToken, 'is_authenticated(false)', false],
6262
[$noToken, 'is_fully_authenticated()', false],
6363
[$noToken, 'is_remember_me()', false],
6464

6565
[$anonymousToken, 'is_anonymous()', true],
66-
[$anonymousToken, 'is_authenticated()', false],
66+
[$anonymousToken, 'is_authenticated(false)', true],
6767
[$anonymousToken, 'is_fully_authenticated()', false],
6868
[$anonymousToken, 'is_remember_me()', false],
6969
[$anonymousToken, "is_granted('ROLE_USER')", false],
7070

7171
[$rememberMeToken, 'is_anonymous()', false],
72-
[$rememberMeToken, 'is_authenticated()', true],
72+
[$rememberMeToken, 'is_authenticated(false)', true],
7373
[$rememberMeToken, 'is_fully_authenticated()', false],
7474
[$rememberMeToken, 'is_remember_me()', true],
7575
[$rememberMeToken, "is_granted('ROLE_FOO')", false],
7676
[$rememberMeToken, "is_granted('ROLE_USER')", true],
7777

7878
[$usernamePasswordToken, 'is_anonymous()', false],
79-
[$usernamePasswordToken, 'is_authenticated()', true],
79+
[$usernamePasswordToken, 'is_authenticated(false)', true],
8080
[$usernamePasswordToken, 'is_fully_authenticated()', true],
8181
[$usernamePasswordToken, 'is_remember_me()', false],
8282
[$usernamePasswordToken, "is_granted('ROLE_FOO')", false],
@@ -109,4 +109,15 @@ public function provideLegacyHasRole()
109109
["has_role('ROLE_ADMIN')", true, $roles],
110110
];
111111
}
112+
113+
public function testLegacyIsAuthenticated()
114+
{
115+
$expressionLanguage = new ExpressionLanguage();
116+
117+
$context = [];
118+
$context['trust_resolver'] = new AuthenticationTrustResolver();
119+
$context['token'] = new AnonymousToken('firewall', 'anon.');
120+
121+
$this->assertFalse($expressionLanguage->evaluate('is_authenticated()', $context));
122+
}
112123
}

0 commit comments

Comments
 (0)
0