Skip to content

Commit 2bc837e

Browse files
committed
Deprecated ROLE_PREVIOUS_ADMIN
1 parent 122a935 commit 2bc837e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Authorization/Voter/RoleVoter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function vote(TokenInterface $token, $subject, array $attributes)
4040
continue;
4141
}
4242

43+
if ('ROLE_PREVIOUS_ADMIN' === $attribute) {
44+
trigger_deprecation('symfony/security-core', '5.1', 'The ROLE_PREVIOUS_ADMIN role is deprecated and will be removed in version 6.0, use the IS_IMPERSONATOR attribute instead.');
45+
}
46+
4347
$result = VoterInterface::ACCESS_DENIED;
4448
foreach ($roles as $role) {
4549
if ($attribute === $role) {

Tests/Authorization/Voter/RoleVoterTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public function getVoteTests()
4444
];
4545
}
4646

47+
/**
48+
* @group legacy
49+
* @expectedDeprecation Since symfony/security-core 5.1: The ROLE_PREVIOUS_ADMIN role is deprecated and will be removed in version 6.0, use the IS_IMPERSONATOR attribute instead.
50+
*/
51+
public function testDeprecatedRolePreviousAdmin()
52+
{
53+
$voter = new RoleVoter();
54+
55+
$voter->vote($this->getTokenWithRoleNames(['ROLE_USER', 'ROLE_PREVIOUS_ADMIN']), null, ['ROLE_PREVIOUS_ADMIN']);
56+
}
57+
4758
protected function getTokenWithRoleNames(array $roles)
4859
{
4960
$token = $this->getMockBuilder(AbstractToken::class)->getMock();

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"require": {
1919
"php": "^7.2.5",
2020
"symfony/event-dispatcher-contracts": "^1.1|^2",
21-
"symfony/service-contracts": "^1.1.6|^2"
21+
"symfony/service-contracts": "^1.1.6|^2",
22+
"symfony/deprecation-contracts": "^2.1"
2223
},
2324
"require-dev": {
2425
"psr/container": "^1.0",

0 commit comments

Comments
 (0)