12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
-
-
-
- namespace JMS\SecurityExtraBundle\Security\Authorization;
-
- use JMS\SecurityExtraBundle\Security\Authentication\Token\RunAsUserToken;
- use Symfony\Component\Security\Core\Role\Role;
- use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
-
-
- class RunAsManager implements RunAsManagerInterface
- {
- private $key;
- private $rolePrefix;
-
- public function __construct($key, $rolePrefix = 'ROLE_')
- {
- $this->key = $key;
- $this->rolePrefix = $rolePrefix;
- }
-
-
-
- public function buildRunAs(TokenInterface $token, $secureObject, array $attributes)
- {
- $roles = array();
- foreach ($attributes as $attribute)
- {
- if ($this->supportsAttribute($attribute)) {
- $roles[] = new Role($attribute);
- }
- }
-
- if (0 === count($roles)) {
- return null;
- }
-
- $roles = array_merge($roles, $token->getRoles());
-
- return new RunAsUserToken($this->key, $token->getUser(), $token->getCredentials(), $roles, $token);
- }
-
-
-
- public function supportsAttribute($attribute)
- {
- return !empty($attribute) && 0 === strpos($attribute, $this->rolePrefix);
- }
-
-
-
- public function supportsClass($className)
- {
- return true;
- }
- }
|