Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit613789f

Browse files
committed
Deprecated is_*() expression functions
is_granted() should be used instead with the correct attributes
1 parentd714c1a commit613789f

File tree

5 files changed

+90
-20
lines changed

5 files changed

+90
-20
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/Bundle/SecurityBundle/Tests/Functional/app/StandardFormLogin/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ security:
4444
-{ path: ^/secured-by-one-real-ip-with-mask$, ips: '203.0.113.0/24', roles: IS_AUTHENTICATED }
4545
-{ path: ^/secured-by-one-real-ipv6$, ips: 0:0:0:0:0:ffff:c633:6400, roles: IS_AUTHENTICATED }
4646
-{ path: ^/highly_protected_resource$, roles: IS_ADMIN }
47-
-{ path: ^/protected-via-expression$, allow_if: "(is_anonymous() and request.headers.get('user-agent') matches '/Firefox/i') or is_granted('ROLE_USER')" }
47+
-{ path: ^/protected-via-expression$, allow_if: "(is_granted('IS_ANONYMOUS') and request.headers.get('user-agent') matches '/Firefox/i') or is_granted('ROLE_USER')" }
4848
-{ path: .*, roles: IS_AUTHENTICATED_FULLY }

‎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
newExpressionFunction('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
newExpressionFunction('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
newExpressionFunction('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
newExpressionFunction('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: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
useSymfony\Component\Security\Core\Authorization\AccessDecisionManager;
2222
useSymfony\Component\Security\Core\Authorization\AuthorizationChecker;
2323
useSymfony\Component\Security\Core\Authorization\ExpressionLanguage;
24+
useSymfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2425
useSymfony\Component\Security\Core\Authorization\Voter\RoleVoter;
2526
useSymfony\Component\Security\Core\User\User;
2627

@@ -35,7 +36,7 @@ public function testIsAuthenticated($token, $expression, $result)
3536
$trustResolver =newAuthenticationTrustResolver();
3637
$tokenStorage =newTokenStorage();
3738
$tokenStorage->setToken($token);
38-
$accessDecisionManager =newAccessDecisionManager([newRoleVoter()]);
39+
$accessDecisionManager =newAccessDecisionManager([newRoleVoter(),newAuthenticatedVoter($trustResolver)]);
3940
$authChecker =newAuthorizationChecker($tokenStorage,$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),$accessDecisionManager);
4041

4142
$context = [];
@@ -51,34 +52,28 @@ public function provider()
5152
$roles = ['ROLE_USER','ROLE_ADMIN'];
5253
$user =newUser('username','password',$roles);
5354

54-
$noToken =null;
5555
$anonymousToken =newAnonymousToken('firewall','anon.');
5656
$rememberMeToken =newRememberMeToken($user,'providerkey','firewall');
5757
$usernamePasswordToken =newUsernamePasswordToken('username','password','providerkey',$roles);
5858

5959
return [
60-
[$noToken,'is_anonymous()',false],
61-
[$noToken,'is_authenticated()',false],
62-
[$noToken,'is_fully_authenticated()',false],
63-
[$noToken,'is_remember_me()',false],
64-
65-
[$anonymousToken,'is_anonymous()',true],
66-
[$anonymousToken,'is_authenticated()',false],
67-
[$anonymousToken,'is_fully_authenticated()',false],
68-
[$anonymousToken,'is_remember_me()',false],
60+
[$anonymousToken,"is_granted('IS_ANONYMOUS')",true],
61+
[$anonymousToken,"is_granted('IS_AUTHENTICATED')",true],
62+
[$anonymousToken,"is_granted('IS_AUTHENTICATED_FULLY')",false],
63+
[$anonymousToken,"is_granted('IS_REMEMBERED')",false],
6964
[$anonymousToken,"is_granted('ROLE_USER')",false],
7065

71-
[$rememberMeToken,'is_anonymous()',false],
72-
[$rememberMeToken,'is_authenticated()',true],
73-
[$rememberMeToken,'is_fully_authenticated()',false],
74-
[$rememberMeToken,'is_remember_me()',true],
66+
[$rememberMeToken,"is_granted('IS_ANONYMOUS')",false],
67+
[$rememberMeToken,"is_granted('IS_AUTHENTICATED')",true],
68+
[$rememberMeToken,"is_granted('IS_AUTHENTICATED_FULLY')",false],
69+
[$rememberMeToken,"is_granted('IS_REMEMBERED')",true],
7570
[$rememberMeToken,"is_granted('ROLE_FOO')",false],
7671
[$rememberMeToken,"is_granted('ROLE_USER')",true],
7772

78-
[$usernamePasswordToken,'is_anonymous()',false],
79-
[$usernamePasswordToken,'is_authenticated()',true],
80-
[$usernamePasswordToken,'is_fully_authenticated()',true],
81-
[$usernamePasswordToken,'is_remember_me()',false],
73+
[$usernamePasswordToken,"is_granted('IS_ANONYMOUS')",false],
74+
[$usernamePasswordToken,"is_granted('IS_AUTHENTICATED')",true],
75+
[$usernamePasswordToken,"is_granted('IS_AUTHENTICATED_FULLY')",true],
76+
[$usernamePasswordToken,"is_granted('IS_REMEMBERED')",false],
8277
[$usernamePasswordToken,"is_granted('ROLE_FOO')",false],
8378
[$usernamePasswordToken,"is_granted('ROLE_USER')",true],
8479
];
@@ -109,4 +104,51 @@ public function provideLegacyHasRole()
109104
["has_role('ROLE_ADMIN')",true,$roles],
110105
];
111106
}
107+
108+
/**
109+
* @dataProvider provideLegacyIsAuthenticated
110+
*/
111+
publicfunctiontestLegacyIsAuthenticated()
112+
{
113+
$expressionLanguage =newExpressionLanguage();
114+
115+
$context = [];
116+
$context['trust_resolver'] =newAuthenticationTrustResolver();
117+
$context['token'] =newAnonymousToken('firewall','anon.');
118+
119+
$this->assertFalse($expressionLanguage->evaluate('is_authenticated()',$context));
120+
}
121+
122+
publicfunctionprovideLegacyIsAuthenticated()
123+
{
124+
$roles = ['ROLE_USER','ROLE_ADMIN'];
125+
$user =newUser('username','password',$roles);
126+
127+
$noToken =null;
128+
$anonymousToken =newAnonymousToken('firewall','anon.');
129+
$rememberMeToken =newRememberMeToken($user,'providerkey','firewall');
130+
$usernamePasswordToken =newUsernamePasswordToken('username','password','providerkey',$roles);
131+
132+
return [
133+
[$noToken,'is_anonymous()',false],
134+
[$noToken,'is_authenticated()',false],
135+
[$noToken,'is_fully_authenticated()',false],
136+
[$noToken,'is_remember_me()',false],
137+
138+
[$anonymousToken,'is_anonymous()',true],
139+
[$anonymousToken,'is_authenticated()',true],
140+
[$anonymousToken,'is_fully_authenticated()',false],
141+
[$anonymousToken,'is_remember_me()',false],
142+
143+
[$rememberMeToken,'is_anonymous()',false],
144+
[$rememberMeToken,'is_authenticated()',true],
145+
[$rememberMeToken,'is_fully_authenticated()',false],
146+
[$rememberMeToken,'is_remember_me()',true],
147+
148+
[$usernamePasswordToken,'is_anonymous()',false],
149+
[$usernamePasswordToken,'is_authenticated()',true],
150+
[$usernamePasswordToken,'is_fully_authenticated()',true],
151+
[$usernamePasswordToken,'is_remember_me()',false],
152+
];
153+
}
112154
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp