vendor/scheb/two-factor-bundle/Security/Authorization/Voter/TwoFactorInProgressVoter.php line 12

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. class TwoFactorInProgressVoter implements VoterInterface
  9. {
  10.     const IS_AUTHENTICATED_2FA_IN_PROGRESS 'IS_AUTHENTICATED_2FA_IN_PROGRESS';
  11.     public function vote(TokenInterface $token$subject, array $attributes)
  12.     {
  13.         if (!($token instanceof TwoFactorTokenInterface)) {
  14.             return VoterInterface::ACCESS_ABSTAIN;
  15.         }
  16.         foreach ($attributes as $attribute) {
  17.             if (self::IS_AUTHENTICATED_2FA_IN_PROGRESS === $attribute) {
  18.                 return VoterInterface::ACCESS_GRANTED;
  19.             }
  20.             if (AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY === $attribute) {
  21.                 return VoterInterface::ACCESS_GRANTED;
  22.             }
  23.         }
  24.         return VoterInterface::ACCESS_ABSTAIN;
  25.     }
  26. }