vendor/symfony/security-http/Authenticator/Debug/TraceableAuthenticator.php line 60

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Http\Authenticator\Debug;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  14. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  15. use Symfony\Component\Security\Guard\Authenticator\GuardBridgeAuthenticator;
  16. use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
  17. use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
  18. use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
  19. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  20. use Symfony\Component\Security\Http\EntryPoint\Exception\NotAnEntryPointException;
  21. use Symfony\Component\VarDumper\Caster\ClassStub;
  22. /**
  23.  * Collects info about an authenticator for debugging purposes.
  24.  *
  25.  * @author Robin Chalas <robin.chalas@gmail.com>
  26.  */
  27. final class TraceableAuthenticator implements AuthenticatorInterfaceInteractiveAuthenticatorInterfaceAuthenticationEntryPointInterface
  28. {
  29.     private $authenticator;
  30.     private $passport;
  31.     private $duration;
  32.     private $stub;
  33.     public function __construct(AuthenticatorInterface $authenticator)
  34.     {
  35.         $this->authenticator $authenticator;
  36.     }
  37.     public function getInfo(): array
  38.     {
  39.         $class \get_class($this->authenticator instanceof GuardBridgeAuthenticator $this->authenticator->getGuardAuthenticator() : $this->authenticator);
  40.         return [
  41.             'supports' => true,
  42.             'passport' => $this->passport,
  43.             'duration' => $this->duration,
  44.             'stub' => $this->stub ?? $this->stub class_exists(ClassStub::class) ? new ClassStub($class) : $class,
  45.         ];
  46.     }
  47.     public function supports(Request $request): ?bool
  48.     {
  49.         return $this->authenticator->supports($request);
  50.     }
  51.     public function authenticate(Request $request): PassportInterface
  52.     {
  53.         $startTime microtime(true);
  54.         $this->passport $this->authenticator->authenticate($request);
  55.         $this->duration microtime(true) - $startTime;
  56.         return $this->passport;
  57.     }
  58.     public function createToken(PassportInterface $passportstring $firewallName): TokenInterface
  59.     {
  60.         return method_exists($this->authenticator'createToken') ? $this->authenticator->createToken($passport$firewallName) : $this->authenticator->createAuthenticatedToken($passport$firewallName);
  61.     }
  62.     public function createAuthenticatedToken(PassportInterface $passportstring $firewallName): TokenInterface
  63.     {
  64.         return $this->authenticator->createAuthenticatedToken($passport$firewallName);
  65.     }
  66.     public function onAuthenticationSuccess(Request $requestTokenInterface $tokenstring $firewallName): ?Response
  67.     {
  68.         return $this->authenticator->onAuthenticationSuccess($request$token$firewallName);
  69.     }
  70.     public function onAuthenticationFailure(Request $requestAuthenticationException $exception): ?Response
  71.     {
  72.         return $this->authenticator->onAuthenticationFailure($request$exception);
  73.     }
  74.     public function start(Request $requestAuthenticationException $authException null): Response
  75.     {
  76.         if (!$this->authenticator instanceof AuthenticationEntryPointInterface) {
  77.             throw new NotAnEntryPointException();
  78.         }
  79.         return $this->authenticator->start($request$authException);
  80.     }
  81.     public function isInteractive(): bool
  82.     {
  83.         return $this->authenticator instanceof InteractiveAuthenticatorInterface && $this->authenticator->isInteractive();
  84.     }
  85.     /**
  86.      * @internal
  87.      */
  88.     public function getAuthenticator(): AuthenticatorInterface
  89.     {
  90.         return $this->authenticator;
  91.     }
  92.     public function __call($method$args)
  93.     {
  94.         return $this->authenticator->{$method}(...$args);
  95.     }
  96. }