* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ 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. * * @author Fabien Potencier */ class RoleVoter implements VoterInterface { private $prefix; /** * @param string $prefix The role prefix */ public function __construct($prefix = 'ROLE_') { $this->prefix = $prefix; } /** * {@inheritdoc} */ public function vote(TokenInterface $token, $subject, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN; $roles = $this->extractRoles($token); foreach ($attributes as $attribute) { if ($attribute instanceof RoleInterface) { $attribute = $attribute->getRole(); } if (!is_string($attribute) || 0 !== strpos($attribute, $this->prefix)) { continue; } $result = VoterInterface::ACCESS_DENIED; foreach ($roles as $role) { if ($attribute === $role->getRole()) { return VoterInterface::ACCESS_GRANTED; } } } return $result; } protected function extractRoles(TokenInterface $token) { return $token->getRoles(); } } __halt_compiler();----SIGNATURE:----YCi0CqsrZGD2RMcD4Hx9v0PV07bIsOZOMj3vdtuVPgynx4IhfOKjN3T1zlHsLYkHqBk7rXTES3I33oHVe9uJQDsrAmloh4gFCBMn/syJFxy8AUiWcjShJ+4bVpk1qNfxkQADWoOcx/woRDK6ZpvQ3mUY7HxhO4b4CQpFXaAw0wfxDWnlWsYfucDzOaE9YOSmLdFtl4MZzqPPhXTrJ2uVztFgEcjVwGKfOEASpRWutMCji6zqiUVxVpsqLTcU4/upnpC1OYFSP6uAZzbwEiZgU8EZ4gj4wv1lYFVCTKNirQYIiXS5TfeXQv08VY0Bhbeaih8OAedFyU5IJh48c4gNmBBQuM+VIi161IP/f4dWs6qQg87iHVWYvT6SMRLA8GxmvysJSJm/xFPJI2pwkREn/b0cKGyjh3QFnpJ9FHcjgJLJrjKvAhvHFag9irStMQuRQpiD6ntGwqjCJIhYCutZUMiaV6ZE08aiftOmYgCt5aYegIkfn49JWvMdTfwLL9hYPh7zCGVP4DDDxDq3r0zFkIONTdKZTr0IwoFtdW3UJsSLbAga116UgjvlLxEYF8t9S8GP32cgieJgU8UnIHPA5q+/OmsuRkZH6OH8hoPirqBakMbQgvFBzhmxtmIz1tQpQD/Vb2c7o0UcyyO8xOv4xzE4cL8HlBdWVh31TPOWMYE=----ATTACHMENT:----MzMxMzQ0MTAzNzUzNzY4NCAxMDc2Njg2MzE0NjYwMTM1IDczODkzNDc1Mzc1OTYyODQ=