vendor/symfony/security-http/EventListener/UserCheckerListener.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Security\Http\EventListener;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
  13. use Symfony\Component\Security\Core\User\UserCheckerInterface;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PreAuthenticatedUserBadge;
  16. use Symfony\Component\Security\Http\Event\CheckPassportEvent;
  17. /**
  18.  * @author Wouter de Jong <wouter@wouterj.nl>
  19.  *
  20.  * @final
  21.  */
  22. class UserCheckerListener implements EventSubscriberInterface
  23. {
  24.     private $userChecker;
  25.     public function __construct(UserCheckerInterface $userChecker)
  26.     {
  27.         $this->userChecker $userChecker;
  28.     }
  29.     public function preCheckCredentials(CheckPassportEvent $event): void
  30.     {
  31.         $passport $event->getPassport();
  32.         if ($passport->hasBadge(PreAuthenticatedUserBadge::class)) {
  33.             return;
  34.         }
  35.         $this->userChecker->checkPreAuth($passport->getUser());
  36.     }
  37.     public function postCheckCredentials(AuthenticationSuccessEvent $event): void
  38.     {
  39.         $user $event->getAuthenticationToken()->getUser();
  40.         if (!$user instanceof UserInterface) {
  41.             return;
  42.         }
  43.         $this->userChecker->checkPostAuth($user);
  44.     }
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             CheckPassportEvent::class => ['preCheckCredentials'256],
  49.             AuthenticationSuccessEvent::class => ['postCheckCredentials'256],
  50.         ];
  51.     }
  52. }