vendor/scheb/two-factor-bundle/Security/TwoFactor/Voter.php line 9

Open in your IDE?
  1. <?php
  2. namespace Scheb\TwoFactorBundle\Security\TwoFactor;
  3. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Scheb\TwoFactorBundle\Security\TwoFactor\Session\SessionFlagManager;
  6. class Voter implements VoterInterface
  7. {
  8.     /**
  9.      * @var SessionFlagManager
  10.      */
  11.     protected $sessionFlagManager;
  12.     /**
  13.      * @var string[]
  14.      */
  15.     protected $providers;
  16.     /**
  17.      * @param SessionFlagManager $sessionFlagManager
  18.      * @param string[]           $providers
  19.      */
  20.     public function __construct(SessionFlagManager $sessionFlagManager, array $providers)
  21.     {
  22.         $this->sessionFlagManager $sessionFlagManager;
  23.         $this->providers $providers;
  24.     }
  25.     /**
  26.      * @param string $class
  27.      *
  28.      * @return bool true
  29.      */
  30.     public function supportsClass($class)
  31.     {
  32.         return true;
  33.     }
  34.     /**
  35.      * @param string $attribute
  36.      *
  37.      * @return bool true
  38.      */
  39.     public function supportsAttribute($attribute)
  40.     {
  41.         return true;
  42.     }
  43.     /**
  44.      * @param TokenInterface $token
  45.      * @param mixed          $object
  46.      * @param array          $attributes
  47.      *
  48.      * @return mixed result
  49.      */
  50.     public function vote(TokenInterface $token$object, array $attributes)
  51.     {
  52.         foreach ($this->providers as $providerName) {
  53.             if ($this->sessionFlagManager->isNotAuthenticated($providerName$token)) {
  54.                 return VoterInterface::ACCESS_DENIED;
  55.             }
  56.         }
  57.         return VoterInterface::ACCESS_ABSTAIN;
  58.     }
  59. }