diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php index b1468b07d8..cd5a243bda 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php @@ -40,6 +40,10 @@ class RoleVoter implements VoterInterface continue; } + if ('ROLE_PREVIOUS_ADMIN' === $attribute) { + 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.'); + } + $result = VoterInterface::ACCESS_DENIED; foreach ($roles as $role) { if ($attribute === $role) { diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php index 6b473c6ffc..9282b0b06f 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php @@ -44,6 +44,17 @@ class RoleVoterTest extends TestCase ]; } + /** + * @group legacy + * @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. + */ + public function testDeprecatedRolePreviousAdmin() + { + $voter = new RoleVoter(); + + $voter->vote($this->getTokenWithRoleNames(['ROLE_USER', 'ROLE_PREVIOUS_ADMIN']), null, ['ROLE_PREVIOUS_ADMIN']); + } + protected function getTokenWithRoleNames(array $roles) { $token = $this->getMockBuilder(AbstractToken::class)->getMock(); diff --git a/src/Symfony/Component/Security/Core/composer.json b/src/Symfony/Component/Security/Core/composer.json index 8533213148..c8bfb07d05 100644 --- a/src/Symfony/Component/Security/Core/composer.json +++ b/src/Symfony/Component/Security/Core/composer.json @@ -18,7 +18,8 @@ "require": { "php": "^7.2.5", "symfony/event-dispatcher-contracts": "^1.1|^2", - "symfony/service-contracts": "^1.1.6|^2" + "symfony/service-contracts": "^1.1.6|^2", + "symfony/deprecation-contracts": "^2.1" }, "require-dev": { "psr/container": "^1.0",