vendor/scheb/2fa-bundle/Security/Authorization/Voter/TwoFactorInProgressVoter.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Scheb\TwoFactorBundle\Security\Authorization\Voter;
  4. use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
  7. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  8. use function defined;
  9. /**
  10.  * @final
  11.  */
  12. class TwoFactorInProgressVoter implements VoterInterface
  13. {
  14.     public const IS_AUTHENTICATED_2FA_IN_PROGRESS 'IS_AUTHENTICATED_2FA_IN_PROGRESS';
  15.     /**
  16.      * {@inheritdoc}
  17.      */
  18.     public function vote(TokenInterface $tokenmixed $subject, array $attributes): int
  19.     {
  20.         if (!($token instanceof TwoFactorTokenInterface)) {
  21.             return VoterInterface::ACCESS_ABSTAIN;
  22.         }
  23.         foreach ($attributes as $attribute) {
  24.             if (self::IS_AUTHENTICATED_2FA_IN_PROGRESS === $attribute) {
  25.                 return VoterInterface::ACCESS_GRANTED;
  26.             }
  27.             if (AuthenticatedVoter::PUBLIC_ACCESS === $attribute) {
  28.                 return VoterInterface::ACCESS_GRANTED;
  29.             }
  30.             // Compatibility for Symfony < 6.0
  31.             if (
  32.                 defined(AuthenticatedVoter::class.'::IS_AUTHENTICATED_ANONYMOUSLY')
  33.                 && AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY === $attribute
  34.             ) {
  35.                 return VoterInterface::ACCESS_GRANTED;
  36.             }
  37.         }
  38.         return VoterInterface::ACCESS_ABSTAIN;
  39.     }
  40. }