summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2017-01-03 05:53:24 -0800
committerFabien Potencier <fabien.potencier@gmail.com>2017-01-03 05:53:24 -0800
commit156a6c52d8100c64462c83b76c971bbe48db8fc0 (patch)
tree9bce25be968d3a4a5367e4a1bc579bcbd81f40e1
parent43d87514e9ef2f05c6b70f5e9fa57af9eb74bc12 (diff)
parent27fdeef792e7237be2b16a2d164126276530b0ec (diff)
downloadsymfony-security-origin/master.zip
symfony-security-origin/master.tar.gz
symfony-security-origin/master.tar.bz2
bug #21136 [Security] use authenticated token for json authentication (fbourigault)HEADorigin/masterorigin/HEADmaster
This PR was merged into the 3.3-dev branch. Discussion ---------- [Security] use authenticated token for json authentication | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21123 | License | MIT | Doc PR | N/A When using `UsernamePasswordJsonAuthenticationListener` with [LexikJWTAuthenticationBundle](https://github.com/lexik/LexikJWTAuthenticationBundle), we get a type exception > Type error: Argument 1 passed to Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler::handleAuthenticationSuccess() must implement interface Symfony\Component\Security\Core\User\UserInterface, string given, called in .../vendor/lexik/jwt-authentication-bundle/Security/Http/Authentication/AuthenticationSuccessHandler.php on line 47 This error occurs because the `UsernamePasswordJsonAuthenticationListener` send to the authentication success handler the token which have the user as a string and not the authenticated one that have a UserInterface as user. Commits ------- 208c617716 use authenticated token for json authentication
-rw-r--r--Http/Firewall/UsernamePasswordJsonAuthenticationListener.php4
-rw-r--r--Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php5
2 files changed, 6 insertions, 3 deletions
diff --git a/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php b/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php
index bf3c621..dfbb4a4 100644
--- a/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php
+++ b/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php
@@ -101,8 +101,8 @@ class UsernamePasswordJsonAuthenticationListener implements ListenerInterface
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 a47111b..24070b1 100644
--- a/Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php
+++ b/Tests/Http/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php
@@ -17,6 +17,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;
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 @@ class UsernamePasswordJsonAuthenticationListenerTest extends \PHPUnit_Framework_
$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());
}