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\Http\Authenticator\AuthenticatorInterface;
  16. use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
  17. use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
  18. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  19. use Symfony\Component\Security\Http\EntryPoint\Exception\NotAnEntryPointException;
  20. use Symfony\Component\VarDumper\Caster\ClassStub;
  21. /**
  22.  * Collects info about an authenticator for debugging purposes.
  23.  *
  24.  * @author Robin Chalas <robin.chalas@gmail.com>
  25.  */
  26. final class TraceableAuthenticator implements AuthenticatorInterfaceInteractiveAuthenticatorInterfaceAuthenticationEntryPointInterface
  27. {
  28.     private AuthenticatorInterface $authenticator;
  29.     private ?Passport $passport null;
  30.     private ?float $duration null;
  31.     private ClassStub|string $stub;
  32.     public function __construct(AuthenticatorInterface $authenticator)
  33.     {
  34.         $this->authenticator $authenticator;
  35.     }
  36.     public function getInfo(): array
  37.     {
  38.         return [
  39.             'supports' => true,
  40.             'passport' => $this->passport,
  41.             'duration' => $this->duration,
  42.             'stub' => $this->stub ??= class_exists(ClassStub::class) ? new ClassStub(\get_class($this->authenticator)) : \get_class($this->authenticator),
  43.         ];
  44.     }
  45.     public function supports(Request $request): ?bool
  46.     {
  47.         return $this->authenticator->supports($request);
  48.     }
  49.     public function authenticate(Request $request): Passport
  50.     {
  51.         $startTime microtime(true);
  52.         $this->passport $this->authenticator->authenticate($request);
  53.         $this->duration microtime(true) - $startTime;
  54.         return $this->passport;
  55.     }
  56.     public function createToken(Passport $passportstring $firewallName): TokenInterface
  57.     {
  58.         return $this->authenticator->createToken($passport$firewallName);
  59.     }
  60.     public function onAuthenticationSuccess(Request $requestTokenInterface $tokenstring $firewallName): ?Response
  61.     {
  62.         return $this->authenticator->onAuthenticationSuccess($request$token$firewallName);
  63.     }
  64.     public function onAuthenticationFailure(Request $requestAuthenticationException $exception): ?Response
  65.     {
  66.         return $this->authenticator->onAuthenticationFailure($request$exception);
  67.     }
  68.     public function start(Request $requestAuthenticationException $authException null): Response
  69.     {
  70.         if (!$this->authenticator instanceof AuthenticationEntryPointInterface) {
  71.             throw new NotAnEntryPointException();
  72.         }
  73.         return $this->authenticator->start($request$authException);
  74.     }
  75.     public function isInteractive(): bool
  76.     {
  77.         return $this->authenticator instanceof InteractiveAuthenticatorInterface && $this->authenticator->isInteractive();
  78.     }
  79.     /**
  80.      * @internal
  81.      */
  82.     public function getAuthenticator(): AuthenticatorInterface
  83.     {
  84.         return $this->authenticator;
  85.     }
  86.     public function __call($method$args)
  87.     {
  88.         return $this->authenticator->{$method}(...$args);
  89.     }
  90. }