Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
bug #21136 [Security] use authenticated token for json authentication…
Browse files Browse the repository at this point in the history
… (fbourigault)

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
  • Loading branch information
fabpot committed Jan 3, 2017
2 parents 43d8751 + 27fdeef commit 156a6c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Http/Firewall/UsernamePasswordJsonAuthenticationListener.php
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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());
}
Expand Down

0 comments on commit 156a6c5

Please sign in to comment.