Skip to content

Commit

Permalink
bug #669 Fix dispatch signature on SF > 4.3 (Webonaute)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x-dev branch.

Discussion
----------

Fix dispatch signature on SF > 4.3

Commits
-------

fb25c5e Fix dispatch signature on SF > 4.3
  • Loading branch information
chalasr committed Jul 18, 2019
2 parents 14262e8 + fb25c5e commit b694e7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Security/Authentication/Provider/JWTProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTManagerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Expand Down Expand Up @@ -90,7 +91,11 @@ public function authenticate(TokenInterface $token)
$authToken->setRawToken($token->getCredentials());

$event = new JWTAuthenticatedEvent($payload, $authToken);
$this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, $event);
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($event, Events::JWT_AUTHENTICATED);
} else {
$this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, $event);
}

return $authToken;
}
Expand Down
15 changes: 13 additions & 2 deletions Security/Firewall/JWTListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator;
use Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor\TokenExtractorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
Expand Down Expand Up @@ -80,7 +81,12 @@ public function handle(GetResponseEvent $event)

if (null === $requestToken) {
$jwtNotFoundEvent = new JWTNotFoundEvent();
$this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $jwtNotFoundEvent);
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($jwtNotFoundEvent, Events::JWT_NOT_FOUND);
} else {
$this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $jwtNotFoundEvent);
}


if ($response = $jwtNotFoundEvent->getResponse()) {
$event->setResponse($response);
Expand All @@ -105,7 +111,12 @@ public function handle(GetResponseEvent $event)
$response = new JWTAuthenticationFailureResponse($failed->getMessage());

$jwtInvalidEvent = new JWTInvalidEvent($failed, $response);
$this->dispatcher->dispatch(Events::JWT_INVALID, $jwtInvalidEvent);
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($jwtInvalidEvent, Events::JWT_INVALID);
} else {
$this->dispatcher->dispatch(Events::JWT_INVALID, $jwtInvalidEvent);
}


$event->setResponse($jwtInvalidEvent->getResponse());
}
Expand Down

0 comments on commit b694e7a

Please sign in to comment.