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

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