From e85cb7fe2a3fb5e3b0026159939d433501dc97bc Mon Sep 17 00:00:00 2001 From: adenkejawen Date: Fri, 18 Jul 2014 10:15:01 +0700 Subject: [PATCH 1/2] added the possibility to return null from SimplePreAuthenticationListener --- .../Http/Firewall/SimplePreAuthenticationListener.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php index 258ca96d6d..47996b2d95 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php @@ -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); From faa8e98063612aa9dfae575569b710d0488082a5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 23 Sep 2014 16:12:58 +0200 Subject: [PATCH 2/2] fixed bug --- .../Http/Firewall/SimplePreAuthenticationListener.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php index 47996b2d95..a6f4f77109 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php @@ -21,7 +21,6 @@ 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. @@ -76,13 +75,15 @@ class SimplePreAuthenticationListener implements ListenerInterface } try { - $this->securityContext->setToken(null); $token = $this->simpleAuthenticator->createToken($request, $this->providerKey); - if ($token instanceof TokenInterface) { - $token = $this->authenticationManager->authenticate($token); - $this->securityContext->setToken($token); + // allow null to be returned to skip authentication + if (null === $token) { + return; } + + $token = $this->authenticationManager->authenticate($token); + $this->securityContext->setToken($token); } catch (AuthenticationException $e) { $this->securityContext->setToken(null);