/**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     if (!count($this->providers)) {
         throw new \LogicException('You must add at least one provider.');
     }
     $lastException = null;
     $result = null;
     foreach ($this->providers as $provider) {
         if (!$provider->supports($token)) {
             continue;
         }
         try {
             $result = $provider->authenticate($token);
         } catch (AccountStatusException $e) {
             $e->setExtraInformation($token);
             throw $e;
         } catch (AuthenticationException $e) {
             $lastException = $e;
         }
     }
     if (null !== $result) {
         if (true === $this->eraseCredentials) {
             $result->eraseCredentials();
         }
         return $result;
     }
     if (null === $lastException) {
         $lastException = new ProviderNotFoundException(sprintf('No Authentication Provider found for token of class "%s".', get_class($token)));
     }
     $lastException->setExtraInformation($token);
     throw $lastException;
 }
 /**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     $lastException = null;
     $result = null;
     foreach ($this->providers as $provider) {
         if (!$provider->supports($token)) {
             continue;
         }
         try {
             $result = $provider->authenticate($token);
             if (null !== $result) {
                 break;
             }
         } catch (AccountStatusException $e) {
             $e->setExtraInformation($token);
             throw $e;
         } catch (AuthenticationException $e) {
             $lastException = $e;
         }
     }
     if (null !== $result) {
         if (true === $this->eraseCredentials) {
             $result->eraseCredentials();
         }
         if (null !== $this->eventDispatcher) {
             $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($result));
         }
         return $result;
     }
     if (null === $lastException) {
         $lastException = new ProviderNotFoundException(sprintf('No Authentication Provider found for token of class "%s".', get_class($token)));
     }
     if (null !== $this->eventDispatcher) {
         $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException));
     }
     $lastException->setExtraInformation($token);
     throw $lastException;
 }