vendor/anyx/login-gate-bundle/Security/AuthenticationHandler.php line 44

Open in your IDE?
  1. <?php
  2. namespace Anyx\LoginGateBundle\Security;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Symfony\Component\Security\Core\AuthenticationEvents;
  6. use Symfony\Component\Security\Core\Event\AuthenticationEvent;
  7. use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
  8. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  9. use Symfony\Component\Security\Http\SecurityEvents;
  10. use Anyx\LoginGateBundle\Storage\StorageInterface;
  11. class AuthenticationHandler implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var \Symfony\Component\HttpFoundation\RequestStack
  15.      */
  16.     private $requestStack;
  17.     /**
  18.      * @var \Anyx\LoginGateBundle\Storage\StorageInterface
  19.      */
  20.     private $storage;
  21.     /**
  22.      * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  23.      * @param \Anyx\LoginGateBundle\Storage\StorageInterface $storage
  24.      */
  25.     public function __construct(RequestStack $requestStackStorageInterface $storage)
  26.     {
  27.         $this->requestStack $requestStack;
  28.         $this->storage $storage;
  29.     }
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             AuthenticationEvents::AUTHENTICATION_FAILURE => 'onAuthenticationFailure',
  34.             SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin'
  35.         ];
  36.     }
  37.     public function onAuthenticationFailure(AuthenticationFailureEvent $event)
  38.     {
  39.         $request $this->getRequestStack()->getCurrentRequest();
  40.         $this->getStorage()->incrementCountAttempts($request$event->getAuthenticationException());
  41.     }
  42.     public function onInteractiveLogin(InteractiveLoginEvent $event)
  43.     {
  44.         $request $this->getRequestStack()->getCurrentRequest();
  45.         $this->getStorage()->clearCountAttempts($request);
  46.     }
  47.     /**
  48.      * @return \Symfony\Component\HttpFoundation\RequestStack
  49.      */
  50.     public function getRequestStack()
  51.     {
  52.         return $this->requestStack;
  53.     }
  54.     /**
  55.      * @return \Anyx\LoginGateBundle\Storage\StorageInterface
  56.      */
  57.     public function getStorage()
  58.     {
  59.         return $this->storage;
  60.     }
  61. }