vendor/scheb/two-factor-bundle/Security/TwoFactor/Event/AuthenticationSuccessEventSuppressor.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Scheb\TwoFactorBundle\Security\TwoFactor\Event;
  4. use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Event\AuthenticationEvent;
  7. class AuthenticationSuccessEventSuppressor
  8. {
  9.     /**
  10.      * @var string
  11.      */
  12.     private $firewallName;
  13.     public function __construct(string $firewallName)
  14.     {
  15.         $this->firewallName $firewallName;
  16.     }
  17.     public function onLogin(AuthenticationEvent $event): void
  18.     {
  19.         $token $event->getAuthenticationToken();
  20.         // We have a TwoFactorToken, make sure the security.authentication.success is not propagated to other
  21.         // listeners, since we do not have a successful login (yet)
  22.         if ($this->isTwoFactorTokenAndFirewall($token)) {
  23.             $event->stopPropagation();
  24.         }
  25.     }
  26.     private function isTwoFactorTokenAndFirewall(TokenInterface $token): bool
  27.     {
  28.         return $token instanceof TwoFactorTokenInterface && $token->getProviderKey() === $this->firewallName;
  29.     }
  30. }