diff --git a/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php b/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php index bf3c62129..dfbb4a4c2 100644 --- a/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php +++ b/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php @@ -101,8 +101,8 @@ public function handle(GetResponseEvent $event) try { $token = new UsernamePasswordToken($username, $password, $this->providerKey); - $this->authenticationManager->authenticate($token); - $response = $this->onSuccess($request, $token); + $authenticatedToken = $this->authenticationManager->authenticate($token); + $response = $this->onSuccess($request, $authenticatedToken); } catch (AuthenticationException $e) { $response = $this->onFailure($request, $e); } diff --git a/Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php b/Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php index a47111b01..24070b1a8 100644 --- a/Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php +++ b/Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; @@ -38,8 +39,10 @@ private function createListener(array $options = array(), $success = true) $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); $authenticationManager = $this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(); + $authenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock(); + if ($success) { - $authenticationManager->method('authenticate')->willReturn(true); + $authenticationManager->method('authenticate')->willReturn($authenticatedToken); } else { $authenticationManager->method('authenticate')->willThrowException(new AuthenticationException()); }