diff options
author | Johannes Schmitt <schmittjoh@gmail.com> | 2011-01-25 20:28:26 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2011-01-26 16:38:54 +0100 |
commit | 521c9f65e9d70618f63ac6ed803a495651b9fd35 (patch) | |
tree | 4e64bf3f877a4050eb3eb95c0b55630a4105053c /SecurityContext.php | |
parent | bff922f5c7ab61fb144e124b584da067842cb955 (diff) | |
download | symfony-security-521c9f65e9d70618f63ac6ed803a495651b9fd35.zip symfony-security-521c9f65e9d70618f63ac6ed803a495651b9fd35.tar.gz symfony-security-521c9f65e9d70618f63ac6ed803a495651b9fd35.tar.bz2 |
[Security] many improvements, and fixes
Diffstat (limited to 'SecurityContext.php')
-rw-r--r-- | SecurityContext.php | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/SecurityContext.php b/SecurityContext.php index e694d82..bf6324a 100644 --- a/SecurityContext.php +++ b/SecurityContext.php @@ -11,8 +11,9 @@ namespace Symfony\Component\Security; +use Symfony\Component\Security\Authorization\AccessDecisionManagerInterface; +use Symfony\Component\Security\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Authorization\AccessDecisionManager; use Symfony\Component\Security\Acl\Voter\FieldVote; /** @@ -30,15 +31,19 @@ class SecurityContext protected $token; protected $accessDecisionManager; + protected $authenticationManager; + protected $alwaysAuthenticate; /** * Constructor. * - * @param AccessDecisionManager|null $accessDecisionManager An AccessDecisionManager instance + * @param AccessDecisionManagerInterface|null $accessDecisionManager An AccessDecisionManager instance */ - public function __construct(AccessDecisionManager $accessDecisionManager = null) + public function __construct(AuthenticationManagerInterface $authenticationManager, AccessDecisionManagerInterface $accessDecisionManager = null, $alwaysAuthenticate = false) { + $this->authenticationManager = $authenticationManager; $this->accessDecisionManager = $accessDecisionManager; + $this->alwaysAuthenticate = $alwaysAuthenticate; } public function getUser() @@ -60,6 +65,10 @@ class SecurityContext $object = new FieldVote($object, $field); } + if ($this->alwaysAuthenticate || !$this->token->isAuthenticated()) { + $this->token = $this->authenticationManager->authenticate($this->token); + } + return $this->accessDecisionManager->decide($this->token, (array) $attributes, $object); } |