vendor/friendsofsymfony/user-bundle/EventListener/AuthenticationListener.php line 65

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSUserBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\UserBundle\EventListener;
  11. use FOS\UserBundle\CompatibilityUtil;
  12. use FOS\UserBundle\Event\FilterUserResponseEvent;
  13. use FOS\UserBundle\Event\UserEvent;
  14. use FOS\UserBundle\FOSUserEvents;
  15. use FOS\UserBundle\Security\LoginManagerInterface;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. use Symfony\Component\Security\Core\Exception\AccountStatusException;
  18. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  19. /**
  20.  * @internal
  21.  * @final
  22.  */
  23. class AuthenticationListener implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @var LoginManagerInterface
  27.      */
  28.     private $loginManager;
  29.     /**
  30.      * @var string
  31.      */
  32.     private $firewallName;
  33.     /**
  34.      * AuthenticationListener constructor.
  35.      *
  36.      * @param string $firewallName
  37.      */
  38.     public function __construct(LoginManagerInterface $loginManager$firewallName)
  39.     {
  40.         $this->loginManager $loginManager;
  41.         $this->firewallName $firewallName;
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public static function getSubscribedEvents(): array
  47.     {
  48.         return [
  49.             FOSUserEvents::REGISTRATION_COMPLETED => 'authenticate',
  50.             FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate',
  51.             FOSUserEvents::RESETTING_RESET_COMPLETED => 'authenticate',
  52.         ];
  53.     }
  54.     /**
  55.      * @param string $eventName
  56.      */
  57.     public function authenticate(FilterUserResponseEvent $event$eventNameEventDispatcherInterface $eventDispatcher)
  58.     {
  59.         $eventDispatcher CompatibilityUtil::upgradeEventDispatcher($eventDispatcher);
  60.         try {
  61.             $this->loginManager->logInUser($this->firewallName$event->getUser(), $event->getResponse());
  62.             $eventDispatcher->dispatch(new UserEvent($event->getUser(), $event->getRequest()), FOSUserEvents::SECURITY_IMPLICIT_LOGIN);
  63.         } catch (AccountStatusException $ex) {
  64.             // We simply do not authenticate users which do not pass the user
  65.             // checker (not enabled, expired, etc.).
  66.         }
  67.     }
  68. }