src/Core/Security/Voter/SecondAuthenticationVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Core\Security\Voter;
  3. use Harmonizely\Core\Exception\RedirectToRoute;
  4. use Harmonizely\Core\Security\Contract\ISecurityHelper;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class SecondAuthenticationVoter extends Voter
  8. {
  9.     /**
  10.      * @var ISecurityHelper
  11.      */
  12.     private ISecurityHelper $security;
  13.     /**
  14.      * SecondAuthenticationVoter constructor.
  15.      * @param ISecurityHelper $security
  16.      */
  17.     public function __construct(ISecurityHelper $security)
  18.     {
  19.         $this->security $security;
  20.     }
  21.     /**
  22.      * @param $attribute
  23.      * @param $subject
  24.      * @return bool
  25.      */
  26.     protected function supports($attribute$subject): bool
  27.     {
  28.         if (ISecurityHelper::IS_2FA_PASSED === $attribute) {
  29.             return true;
  30.         }
  31.         return false;
  32.     }
  33.     /**
  34.      * @param $attribute
  35.      * @param $subject
  36.      * @param TokenInterface $token
  37.      * @return bool
  38.      * @throws RedirectToRoute
  39.      */
  40.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  41.     {
  42.         if (!$this->security->isSecondFactorPassed()) {
  43.             throw new RedirectToRoute('fos_user_security_login');
  44.         }
  45.         return true;
  46.     }
  47. }