From 437398d6d03c86552777fdb8ed97c0f9c6cecbd5 Mon Sep 17 00:00:00 2001 From: "Konstantin.Myakshin" Date: Thu, 1 Oct 2015 00:29:16 +0300 Subject: [PATCH] [3.0][Security] Remove deprecated features (follow up of #15899) --- UPGRADE-3.0.md | 33 +++++++++++++++++++ .../Authorization/Voter/AbstractVoter.php | 8 ++--- .../Voter/AuthenticatedVoter.php | 20 ++--------- .../Authorization/Voter/ExpressionVoter.php | 18 +--------- .../Core/Authorization/Voter/RoleVoter.php | 18 +--------- .../AccessDecisionManagerTest.php | 20 ----------- .../Voter/AuthenticatedVoterTest.php | 6 ---- .../Voter/ExpressionVoterTest.php | 9 ----- .../Authorization/Voter/RoleVoterTest.php | 7 ---- 9 files changed, 40 insertions(+), 99 deletions(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 0345e12dd3e41..dba1d48be33c2 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -725,6 +725,39 @@ UPGRADE FROM 2.x to 3.0 } ``` + * The `AbstractVoter::isGranted()` method have been replaced by `AbstractVoter::voteOnAttribute()`. + + Before: + + ```php + class MyVoter extends AbstractVoter + { + protected function isGranted($attribute, $object, $user = null) + { + return 'EDIT' === $attribute && $user === $object->getAuthor(); + } + + // ... + } + ``` + + After: + + ```php + class MyVoter extends AbstractVoter + { + protected function voteOnAttribute($attribute, $object, TokenInterface $token) + { + return 'EDIT' === $attribute && $token->getUser() === $object->getAuthor(); + } + + // ... + } + ``` + + * The `supportsAttribute()` and `supportsClass()` methods of classes `AuthenticatedVoter`, `ExpressionVoter` + and `RoleVoter` have been removed. + ### Translator * The `Translator::setFallbackLocale()` method has been removed in favor of diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php index ee73d2901c852..71f570f15e22a 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Security\Core\Authorization\Voter; -use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** @@ -89,11 +88,8 @@ protected function isClassInstanceOf($actualClass, $expectedClass) } /** - * Perform a single access check operation on a given attribute, object and (optionally) user - * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass - * $user can be one of the following: - * a UserInterface object (fully authenticated user) - * a string (anonymously authenticated user). + * Perform a single access check operation on a given attribute, object and token. + * It is safe to assume that $attribute and $object's class pass supports method call. * * @param string $attribute * @param object $object diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php index 5847e0d15c058..762e9bc50d2bd 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php @@ -41,22 +41,6 @@ public function __construct(AuthenticationTrustResolverInterface $authentication $this->authenticationTrustResolver = $authenticationTrustResolver; } - /** - * {@inheritdoc} - */ - public function supportsAttribute($attribute) - { - return null !== $attribute && (self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_REMEMBERED === $attribute || self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute); - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - return true; - } - /** * {@inheritdoc} */ @@ -64,7 +48,9 @@ public function vote(TokenInterface $token, $object, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN; foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { + if (null === $attribute || (self::IS_AUTHENTICATED_FULLY !== $attribute + && self::IS_AUTHENTICATED_REMEMBERED !== $attribute + && self::IS_AUTHENTICATED_ANONYMOUSLY !== $attribute)) { continue; } diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php index 98b8f50f15d03..084285624be38 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php @@ -49,22 +49,6 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac $this->expressionLanguage->registerProvider($provider); } - /** - * {@inheritdoc} - */ - public function supportsAttribute($attribute) - { - return $attribute instanceof Expression; - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - return true; - } - /** * {@inheritdoc} */ @@ -73,7 +57,7 @@ public function vote(TokenInterface $token, $object, array $attributes) $result = VoterInterface::ACCESS_ABSTAIN; $variables = null; foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { + if (!$attribute instanceof Expression) { continue; } diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php index 722675d29be0c..74e2363ed283e 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php @@ -32,22 +32,6 @@ public function __construct($prefix = 'ROLE_') $this->prefix = $prefix; } - /** - * {@inheritdoc} - */ - public function supportsAttribute($attribute) - { - return 0 === strpos($attribute, $this->prefix); - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - return true; - } - /** * {@inheritdoc} */ @@ -57,7 +41,7 @@ public function vote(TokenInterface $token, $object, array $attributes) $roles = $this->extractRoles($token); foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { + if (0 !== strpos($attribute, $this->prefix)) { continue; } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php index 9c23672ba101f..72bae0a794ba5 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php @@ -137,24 +137,4 @@ protected function getVoter($vote) return $voter; } - - protected function getVoterSupportsClass($ret) - { - $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface'); - $voter->expects($this->any()) - ->method('supportsClass') - ->will($this->returnValue($ret)); - - return $voter; - } - - protected function getVoterSupportsAttribute($ret) - { - $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface'); - $voter->expects($this->any()) - ->method('supportsAttribute') - ->will($this->returnValue($ret)); - - return $voter; - } } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php index 4679c0ff0e5ea..60e2a1959f944 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php @@ -17,12 +17,6 @@ class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase { - public function testSupportsClass() - { - $voter = new AuthenticatedVoter($this->getResolver()); - $this->assertTrue($voter->supportsClass('stdClass')); - } - /** * @dataProvider getVoteTests */ diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ExpressionVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ExpressionVoterTest.php index dc8ea7960e960..529629690b86e 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ExpressionVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/ExpressionVoterTest.php @@ -17,15 +17,6 @@ class ExpressionVoterTest extends \PHPUnit_Framework_TestCase { - public function testSupportsAttribute() - { - $expression = $this->createExpression(); - $expressionLanguage = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage'); - $voter = new ExpressionVoter($expressionLanguage, $this->createTrustResolver(), $this->createRoleHierarchy()); - - $this->assertTrue($voter->supportsAttribute($expression)); - } - /** * @dataProvider getVoteTests */ 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 03ab2da27e050..9982bdfb1895b 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php @@ -17,13 +17,6 @@ class RoleVoterTest extends \PHPUnit_Framework_TestCase { - public function testSupportsClass() - { - $voter = new RoleVoter(); - - $this->assertTrue($voter->supportsClass('Foo')); - } - /** * @dataProvider getVoteTests */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy