summaryrefslogtreecommitdiffstats
path: root/Core
diff options
context:
space:
mode:
authorJonatan Männchen <jonatan.maennchen@ibrows.ch>2016-08-24 15:49:11 +0000
committerJonatan Männchen <jonatan@maennchen.ch>2016-09-21 07:35:02 +0000
commit942c0b2c8429f60a3a43545dc35eee9c836abad5 (patch)
tree4fb25db9d0fbaf02b80321f7430bf32fac40d7ee /Core
parentbd170760b502967a6b42f90fd8db57646683a345 (diff)
downloadsymfony-security-942c0b2c8429f60a3a43545dc35eee9c836abad5.zip
symfony-security-942c0b2c8429f60a3a43545dc35eee9c836abad5.tar.gz
symfony-security-942c0b2c8429f60a3a43545dc35eee9c836abad5.tar.bz2
bug #18042 [Security] $attributes can be anything, but RoleVoter assumes strings
Diffstat (limited to 'Core')
-rw-r--r--Core/Authorization/Voter/RoleVoter.php7
-rw-r--r--Core/Tests/Authorization/Voter/RoleVoterTest.php6
2 files changed, 12 insertions, 1 deletions
diff --git a/Core/Authorization/Voter/RoleVoter.php b/Core/Authorization/Voter/RoleVoter.php
index 722675d..539dcda 100644
--- a/Core/Authorization/Voter/RoleVoter.php
+++ b/Core/Authorization/Voter/RoleVoter.php
@@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Core\Authorization\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Role\RoleInterface;
/**
* RoleVoter votes if any attribute starts with a given prefix.
@@ -37,7 +38,7 @@ class RoleVoter implements VoterInterface
*/
public function supportsAttribute($attribute)
{
- return 0 === strpos($attribute, $this->prefix);
+ return is_string($attribute) && 0 === strpos($attribute, $this->prefix);
}
/**
@@ -57,6 +58,10 @@ class RoleVoter implements VoterInterface
$roles = $this->extractRoles($token);
foreach ($attributes as $attribute) {
+ if ($attribute instanceof RoleInterface) {
+ $attribute = $attribute->getRole();
+ }
+
if (!$this->supportsAttribute($attribute)) {
continue;
}
diff --git a/Core/Tests/Authorization/Voter/RoleVoterTest.php b/Core/Tests/Authorization/Voter/RoleVoterTest.php
index 03ab2da..c15e936 100644
--- a/Core/Tests/Authorization/Voter/RoleVoterTest.php
+++ b/Core/Tests/Authorization/Voter/RoleVoterTest.php
@@ -43,6 +43,12 @@ class RoleVoterTest extends \PHPUnit_Framework_TestCase
array(array('ROLE_FOO'), array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
array(array('ROLE_FOO'), array('FOO', 'ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
array(array('ROLE_BAR', 'ROLE_FOO'), array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
+
+ // Test mixed Types
+ array(array(), array(array()), VoterInterface::ACCESS_ABSTAIN),
+ array(array(), array(new \stdClass()), VoterInterface::ACCESS_ABSTAIN),
+ array(array('ROLE_BAR'), array(new Role('ROLE_BAR')), VoterInterface::ACCESS_GRANTED),
+ array(array('ROLE_BAR'), array(new Role('ROLE_FOO')), VoterInterface::ACCESS_DENIED),
);
}