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

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