added the possibility to return null from SimplePreAuthenticationListener

This commit is contained in:
adenkejawen 2014-07-18 10:15:01 +07:00 committed by Fabien Potencier
parent 924d06adf6
commit e85cb7fe2a

View File

@ -21,6 +21,7 @@ use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* SimplePreAuthenticationListener implements simple proxying to an authenticator.
@ -75,9 +76,13 @@ class SimplePreAuthenticationListener implements ListenerInterface
}
try {
$this->securityContext->setToken(null);
$token = $this->simpleAuthenticator->createToken($request, $this->providerKey);
$token = $this->authenticationManager->authenticate($token);
$this->securityContext->setToken($token);
if ($token instanceof TokenInterface) {
$token = $this->authenticationManager->authenticate($token);
$this->securityContext->setToken($token);
}
} catch (AuthenticationException $e) {
$this->securityContext->setToken(null);