Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
* 3.1:
  Minor fixes & cleanups
  [DependencyInjection] Add missing PHPDoc type
  Correct a typo in the ReflectionExtractor's description
  [HttpFoundation] JSONP callback validation
  [Console] Improved the explanation of the hasOption() method
  Uniformize exception vars according to our CS
  add missing use statement
  bug #18042 [Security] $attributes can be anything, but RoleVoter assumes strings
  • Loading branch information
nicolas-grekas committed Oct 6, 2016
2 parents c4b4d16 + 7549746 commit 140f8dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Core/Authorization/Voter/RoleVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -41,7 +42,11 @@ public function vote(TokenInterface $token, $subject, array $attributes)
$roles = $this->extractRoles($token);

foreach ($attributes as $attribute) {
if (0 !== strpos($attribute, $this->prefix)) {
if ($attribute instanceof RoleInterface) {
$attribute = $attribute->getRole();
}

if (!is_string($attribute) || 0 !== strpos($attribute, $this->prefix)) {
continue;
}

Expand Down
6 changes: 6 additions & 0 deletions Core/Tests/Authorization/Voter/RoleVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public function getVoteTests()
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),
);
}

Expand Down

0 comments on commit 140f8dd

Please sign in to comment.