Skip to content

Commit

Permalink
Avoid calling onAuthenticationFailure() from start()
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Aug 28, 2016
1 parent e5f5149 commit 4070e57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
13 changes: 4 additions & 9 deletions Security/Guard/JWTTokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Security\Guard;

use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTFailureEventInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTNotFoundEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Events;
Expand Down Expand Up @@ -138,15 +137,11 @@ public function getUser($preAuthToken, UserProviderInterface $userProvider)

/**
* {@inheritdoc}
*
* @param JWTFailureEventInterface $event An event to be dispatched (default JWTInvalidEvent)
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $authException, JWTFailureEventInterface $event = null)
public function onAuthenticationFailure(Request $request, AuthenticationException $authException)
{
if (null === $event) {
$event = new JWTInvalidEvent($authException, new JWTAuthenticationFailureResponse($authException->getMessage()));
$this->dispatcher->dispatch(Events::JWT_INVALID, $event);
}
$event = new JWTInvalidEvent($authException, new JWTAuthenticationFailureResponse($authException->getMessage()));
$this->dispatcher->dispatch(Events::JWT_INVALID, $event);

return $event->getResponse();
}
Expand All @@ -171,7 +166,7 @@ public function start(Request $request, AuthenticationException $authException =

$this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $event);

return $this->onAuthenticationFailure($request, $authException, $event);
return $event->getResponse();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/SubscribedTokenAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\Tests\Functional;

use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTNotFoundEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Events;

Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/Utils/CallableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\Tests\Functional\Utils;

use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTEncodedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTNotFoundEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Events;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CallableEventSubscriber implements EventSubscriberInterface
{
private static $listeners = [];
private static $listeners = [];
private static $eventClassMap = [
Events::JWT_CREATED => JWTCreatedEvent::class,
Events::JWT_DECODED => JWTDecodedEvent::class,
Expand Down

0 comments on commit 4070e57

Please sign in to comment.