diff options
-rw-r--r-- | Core/Authorization/AccessDecisionManager.php | 4 | ||||
-rw-r--r-- | Core/Authorization/Voter/AbstractVoter.php | 37 | ||||
-rw-r--r-- | Core/Tests/Authorization/Voter/AbstractVoterTest.php | 38 | ||||
-rw-r--r-- | Core/Tests/LegacySecurityContextTest.php | 4 | ||||
-rw-r--r-- | Guard/Tests/Firewall/GuardAuthenticationListenerTest.php | 1 | ||||
-rw-r--r-- | Guard/Token/GuardTokenInterface.php | 4 | ||||
-rw-r--r-- | Guard/composer.json | 2 | ||||
-rw-r--r-- | composer.json | 1 |
8 files changed, 54 insertions, 37 deletions
diff --git a/Core/Authorization/AccessDecisionManager.php b/Core/Authorization/AccessDecisionManager.php index ef942b8..7cefef1 100644 --- a/Core/Authorization/AccessDecisionManager.php +++ b/Core/Authorization/AccessDecisionManager.php @@ -77,7 +77,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface */ public function supportsAttribute($attribute) { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.'); + @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); foreach ($this->voters as $voter) { if ($voter->supportsAttribute($attribute)) { @@ -93,7 +93,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface */ public function supportsClass($class) { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.'); + @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); foreach ($this->voters as $voter) { if ($voter->supportsClass($class)) { diff --git a/Core/Authorization/Voter/AbstractVoter.php b/Core/Authorization/Voter/AbstractVoter.php index 2cafc5f..12b54db 100644 --- a/Core/Authorization/Voter/AbstractVoter.php +++ b/Core/Authorization/Voter/AbstractVoter.php @@ -26,7 +26,7 @@ abstract class AbstractVoter implements VoterInterface */ public function supportsAttribute($attribute) { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.'); + @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); return in_array($attribute, $this->getSupportedAttributes()); } @@ -36,7 +36,7 @@ abstract class AbstractVoter implements VoterInterface */ public function supportsClass($class) { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.'); + @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); foreach ($this->getSupportedClasses() as $supportedClass) { if ($supportedClass === $class || is_subclass_of($class, $supportedClass)) { @@ -70,12 +70,6 @@ abstract class AbstractVoter implements VoterInterface $vote = self::ACCESS_ABSTAIN; $class = get_class($object); - $reflector = new \ReflectionMethod($this, 'voteOnAttribute'); - $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter'; - if (!$isNewOverwritten) { - @trigger_error(sprintf("The AbstractVoter::isGranted method is deprecated since 2.8 and won't be called anymore in 3.0. Override voteOnAttribute() instead.", $reflector->class), E_USER_DEPRECATED); - } - foreach ($attributes as $attribute) { if (!$this->supports($attribute, $class)) { continue; @@ -84,16 +78,9 @@ abstract class AbstractVoter implements VoterInterface // as soon as at least one attribute is supported, default is to deny access $vote = self::ACCESS_DENIED; - if ($isNewOverwritten) { - if ($this->voteOnAttribute($attribute, $object, $token)) { - // grant access as soon as at least one voter returns a positive response - return self::ACCESS_GRANTED; - } - } else { - if ($this->isGranted($attribute, $object, $token->getUser())) { - // grant access as soon as at least one voter returns a positive response - return self::ACCESS_GRANTED; - } + if ($this->voteOnAttribute($attribute, $object, $token)) { + // grant access as soon as at least one voter returns a positive response + return self::ACCESS_GRANTED; } } @@ -115,7 +102,7 @@ abstract class AbstractVoter implements VoterInterface */ protected function supports($attribute, $class) { - @trigger_error('The getSupportedClasses and getSupportedAttributes methods are deprecated since version 2.8 and will be removed in version 3.0. Overwrite supports instead.'); + @trigger_error('The getSupportedClasses and getSupportedAttributes methods are deprecated since version 2.8 and will be removed in version 3.0. Overwrite supports instead.', E_USER_DEPRECATED); $classIsSupported = false; foreach ($this->getSupportedClasses() as $supportedClass) { @@ -159,7 +146,7 @@ abstract class AbstractVoter implements VoterInterface */ protected function getSupportedClasses() { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.'); + @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); } /** @@ -171,7 +158,7 @@ abstract class AbstractVoter implements VoterInterface */ protected function getSupportedAttributes() { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.'); + @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); } /** @@ -191,7 +178,8 @@ abstract class AbstractVoter implements VoterInterface */ protected function isGranted($attribute, $object, $user = null) { - return false; + // forces isGranted() or voteOnAttribute() to be overridden + throw new \BadMethodCallException(sprintf('You must override the voteOnAttribute() method in "%s".', get_class($this))); } /** @@ -211,6 +199,9 @@ abstract class AbstractVoter implements VoterInterface */ protected function voteOnAttribute($attribute, $object, TokenInterface $token) { - return false; + // the user should override this method, and not rely on the deprecated isGranted() + @trigger_error(sprintf("The AbstractVoter::isGranted() method is deprecated since 2.8 and won't be called anymore in 3.0. Override voteOnAttribute() in %s instead.", get_class($this)), E_USER_DEPRECATED); + + return $this->isGranted($attribute, $object, $token->getUser()); } } diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php index 44da147..ea72e75 100644 --- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php +++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -19,17 +19,10 @@ use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; */ class AbstractVoterTest extends \PHPUnit_Framework_TestCase { - /** - * @var AbstractVoter - */ - private $voter; - private $token; protected function setUp() { - $this->voter = new VoterFixture(); - $tokenMock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); $tokenMock ->expects($this->any()) @@ -44,7 +37,9 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase */ public function testVote($expectedVote, $object, $attributes, $message) { - $this->assertEquals($expectedVote, $this->voter->vote($this->token, $object, $attributes), $message); + $voter = new VoterFixture(); + + $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); } /** @@ -58,6 +53,16 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); } + /** + * @group legacy + * @expectedException \BadMethodCallException + */ + public function testNoOverriddenMethodsThrowsException() + { + $voter = new DeprecatedVoterNothingImplementedFixture(); + $voter->vote($this->token, new ObjectFixture(), array('foo')); + } + public function getData() { return array( @@ -113,6 +118,23 @@ class DeprecatedVoterFixture extends AbstractVoter } } +class DeprecatedVoterNothingImplementedFixture extends AbstractVoter +{ + protected function getSupportedClasses() + { + return array( + 'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture', + ); + } + + protected function getSupportedAttributes() + { + return array('foo', 'bar', 'baz'); + } + + // this is a bad voter that hasn't overridden isGranted or voteOnAttribute +} + class ObjectFixture { } diff --git a/Core/Tests/LegacySecurityContextTest.php b/Core/Tests/LegacySecurityContextTest.php index 7db24e7..4502261 100644 --- a/Core/Tests/LegacySecurityContextTest.php +++ b/Core/Tests/LegacySecurityContextTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Security\Core\Tests; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; -use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; +use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\Security\Core\SecurityContextInterface; /** * @group legacy diff --git a/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php b/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php index ebfd3a8..3224fee 100644 --- a/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php +++ b/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php @@ -251,5 +251,6 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase $this->event = null; $this->logger = null; $this->request = null; + $this->rememberMeServices = null; } } diff --git a/Guard/Token/GuardTokenInterface.php b/Guard/Token/GuardTokenInterface.php index f0db250..063ffd3 100644 --- a/Guard/Token/GuardTokenInterface.php +++ b/Guard/Token/GuardTokenInterface.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Guard\Token; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; + /** * A marker interface that both guard tokens implement. * @@ -20,6 +22,6 @@ namespace Symfony\Component\Security\Guard\Token; * * @author Ryan Weaver <ryan@knpuniversity.com> */ -interface GuardTokenInterface +interface GuardTokenInterface extends TokenInterface { } diff --git a/Guard/composer.json b/Guard/composer.json index 1e0dc8c..176754e 100644 --- a/Guard/composer.json +++ b/Guard/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=5.3.9", "symfony/security-core": "~2.8|~3.0.0", - "symfony/security-http": "~2.8|~3.0.0" + "symfony/security-http": "~2.7|~3.0.0" }, "require-dev": { "symfony/phpunit-bridge": "~2.8|~3.0.0", diff --git a/composer.json b/composer.json index 9df0bf0..708c60f 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "replace": { "symfony/security-core": "self.version", "symfony/security-csrf": "self.version", + "symfony/security-guard": "self.version", "symfony/security-http": "self.version" }, "require-dev": { |