summaryrefslogtreecommitdiffstats
path: root/Core/SecurityContext.php
diff options
context:
space:
mode:
Diffstat (limited to 'Core/SecurityContext.php')
-rw-r--r--Core/SecurityContext.php30
1 files changed, 8 insertions, 22 deletions
diff --git a/Core/SecurityContext.php b/Core/SecurityContext.php
index 405ace9..079636a 100644
--- a/Core/SecurityContext.php
+++ b/Core/SecurityContext.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Security\Core;
+use Symfony\Component\Security\Core\User\AccountInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -22,13 +24,10 @@ use Symfony\Component\Security\Acl\Voter\FieldVote;
* It gives access to the token representing the current user authentication.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
-class SecurityContext
+class SecurityContext implements SecurityContextInterface
{
- const ACCESS_DENIED_ERROR = '_security.403_error';
- const AUTHENTICATION_ERROR = '_security.last_error';
- const LAST_USERNAME = '_security.last_username';
-
protected $token;
protected $accessDecisionManager;
protected $authenticationManager;
@@ -39,30 +38,17 @@ class SecurityContext
*
* @param AccessDecisionManagerInterface|null $accessDecisionManager An AccessDecisionManager instance
*/
- public function __construct(AuthenticationManagerInterface $authenticationManager, AccessDecisionManagerInterface $accessDecisionManager = null, $alwaysAuthenticate = false)
+ public function __construct(AuthenticationManagerInterface $authenticationManager, AccessDecisionManagerInterface $accessDecisionManager, $alwaysAuthenticate = false)
{
$this->authenticationManager = $authenticationManager;
$this->accessDecisionManager = $accessDecisionManager;
$this->alwaysAuthenticate = $alwaysAuthenticate;
}
- public function getUser()
- {
- return null === $this->token ? null : $this->token->getUser();
- }
-
- public function vote($attributes, $object = null, $field = null)
+ public final function vote($attributes, $object = null)
{
- if (null === $this->token || null === $this->accessDecisionManager) {
- return false;
- }
-
- if ($field !== null) {
- if (null === $object) {
- throw new \InvalidArgumentException('$object cannot be null when field is not null.');
- }
-
- $object = new FieldVote($object, $field);
+ if (null === $this->token) {
+ throw new AuthenticationCredentialsNotFoundException('The security context contains no authentication token.');
}
if ($this->alwaysAuthenticate || !$this->token->isAuthenticated()) {