diff --git a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php index 6028c42c4b..18c3569aa9 100644 --- a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php +++ b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php @@ -43,8 +43,13 @@ class AccessDecisionManager implements AccessDecisionManagerInterface throw new \InvalidArgumentException('You must at least add one voter.'); } + $strategyMethod = 'decide'.ucfirst($strategy); + if (!is_callable(array($this, $strategyMethod))) { + throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy)); + } + $this->voters = $voters; - $this->strategy = 'decide'.ucfirst($strategy); + $this->strategy = $strategyMethod; $this->allowIfAllAbstainDecisions = (Boolean) $allowIfAllAbstainDecisions; $this->allowIfEqualGrantedDeniedDecisions = (Boolean) $allowIfEqualGrantedDeniedDecisions; } diff --git a/src/Symfony/Component/Security/Tests/Core/Authorization/AccessDecisionManagerTest.php b/src/Symfony/Component/Security/Tests/Core/Authorization/AccessDecisionManagerTest.php index 1c706ccdae..ead97d2bc6 100644 --- a/src/Symfony/Component/Security/Tests/Core/Authorization/AccessDecisionManagerTest.php +++ b/src/Symfony/Component/Security/Tests/Core/Authorization/AccessDecisionManagerTest.php @@ -54,6 +54,14 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase $manager = new AccessDecisionManager(array()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testSetUnsupportedStrategy() + { + new AccessDecisionManager(array($this->getVoter(VoterInterface::ACCESS_GRANTED)), 'fooBar'); + } + /** * @dataProvider getStrategyTests */