diff --git a/src/Symfony/Component/Security/Acl/Voter/AclVoter.php b/src/Symfony/Component/Security/Acl/Voter/AclVoter.php index d401ef3bed..b21b1e675b 100644 --- a/src/Symfony/Component/Security/Acl/Voter/AclVoter.php +++ b/src/Symfony/Component/Security/Acl/Voter/AclVoter.php @@ -48,12 +48,16 @@ class AclVoter implements VoterInterface public function supportsAttribute($attribute) { - return $this->permissionMap->contains($attribute); + return is_string($attribute) && $this->permissionMap->contains($attribute); } public function vote(TokenInterface $token, $object, array $attributes) { foreach ($attributes as $attribute) { + if (!$this->supportsAttribute($attribute)) { + continue; + } + if (null === $masks = $this->permissionMap->getMasks($attribute, $object)) { continue; } diff --git a/src/Symfony/Component/Security/Tests/Acl/Voter/AclVoterTest.php b/src/Symfony/Component/Security/Tests/Acl/Voter/AclVoterTest.php index 2474515b5c..98e5ab9c55 100644 --- a/src/Symfony/Component/Security/Tests/Acl/Voter/AclVoterTest.php +++ b/src/Symfony/Component/Security/Tests/Acl/Voter/AclVoterTest.php @@ -27,7 +27,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase */ public function testSupportsAttribute($attribute, $supported) { - list($voter,, $permissionMap,,) = $this->getVoter(); + list($voter,, $permissionMap,,) = $this->getVoter(true, false); $permissionMap ->expects($this->once()) @@ -39,6 +39,16 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase $this->assertSame($supported, $voter->supportsAttribute($attribute)); } + /** + * @dataProvider getSupportsAttributeNonStringTests + */ + public function testSupportsAttributeNonString($attribute) + { + list($voter,,,,,) = $this->getVoter(true, false); + + $this->assertFalse($voter->supportsAttribute($attribute)); + } + public function getSupportsAttributeTests() { return array( @@ -47,6 +57,16 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase ); } + public function getSupportsAttributeNonStringTests() + { + return array( + array(new \stdClass()), + array(1), + array(true), + array(array()), + ); + } + /** * @dataProvider getSupportsClassTests */ @@ -387,13 +407,20 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); } - protected function getVoter($allowIfObjectIdentityUnavailable = true) + protected function getVoter($allowIfObjectIdentityUnavailable = true, $alwaysContains = true) { $provider = $this->getMock('Symfony\Component\Security\Acl\Model\AclProviderInterface'); $permissionMap = $this->getMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface'); $oidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface'); $sidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface'); + if ($alwaysContains) { + $permissionMap + ->expects($this->any()) + ->method('contains') + ->will($this->returnValue(true)); + } + return array( new AclVoter($provider, $oidStrategy, $sidStrategy, $permissionMap, null, $allowIfObjectIdentityUnavailable), $provider,