Exemplo n.º 1
0
 private function getProviderCollection($providers = true)
 {
     $providerCollection = new TwoFactorProviderCollection();
     if (true === $providers) {
         $providerCollection->addProvider('test', $this->provider);
     }
     return $providerCollection;
 }
 public function setUp()
 {
     $this->flagManager = $this->getMockBuilder("Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Session\\SessionFlagManager")->disableOriginalConstructor()->getMock();
     $this->provider = $this->getMock("Scheb\\TwoFactorBundle\\Security\\TwoFactor\\Provider\\TwoFactorProviderInterface");
     $this->collection = new TwoFactorProviderCollection();
     $this->collection->addProvider('test', $this->provider);
     $this->registry = new TwoFactorProviderRegistry($this->flagManager, $this->collection);
 }
Exemplo n.º 3
0
 /**
  * vote
  * @param TokenInterface $token
  * @param mixed          $object
  * @param array          $attributes
  * @return mixed result
  **/
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     foreach ($this->providerCollection->getProviders() as $providerName => $provider) {
         $res = $this->sessionFlagManager->isNotAuthenticated($providerName, $token);
         if (true === $res) {
             return VoterInterface::ACCESS_DENIED;
         }
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }
 /**
  * Iterate over two-factor providers and ask for two-factor authentcation.
  * Each provider can return a response. The first response will be returned.
  *
  * @param  \Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContext $context
  * @return \Symfony\Component\HttpFoundation\Response|null
  */
 public function requestAuthenticationCode(AuthenticationContext $context)
 {
     $token = $context->getToken();
     // Iterate over two-factor providers and ask for completion
     foreach ($this->providerCollection->getProviders() as $providerName => $provider) {
         if ($this->flagManager->isNotAuthenticated($providerName, $token)) {
             $response = $provider->requestAuthenticationCode($context);
             // Set authentication completed
             if ($context->isAuthenticated()) {
                 $this->flagManager->setComplete($providerName, $token);
             }
             // Return response
             if ($response instanceof Response) {
                 return $response;
             }
         }
     }
     return null;
 }
 /**
  * @test
  */
 public function noProvider_getProviders()
 {
     $collection = new TwoFactorProviderCollection();
     $providers = $collection->getProviders();
     $this->assertEquals(array(), $providers);
 }