vendor/symfony/security-http/Authenticator/Debug/TraceableAuthenticatorManagerListener.php line 43

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\HttpKernel\Event\RequestEvent;
  13. use Symfony\Component\Security\Http\Firewall\AbstractListener;
  14. use Symfony\Component\Security\Http\Firewall\AuthenticatorManagerListener;
  15. use Symfony\Component\VarDumper\Caster\ClassStub;
  16. use Symfony\Contracts\Service\ResetInterface;
  17. /**
  18.  * Decorates the AuthenticatorManagerListener to collect information about security authenticators.
  19.  *
  20.  * @author Robin Chalas <robin.chalas@gmail.com>
  21.  */
  22. final class TraceableAuthenticatorManagerListener extends AbstractListener implements ResetInterface
  23. {
  24.     private $authenticationManagerListener;
  25.     private $authenticatorsInfo = [];
  26.     private $hasVardumper;
  27.     public function __construct(AuthenticatorManagerListener $authenticationManagerListener)
  28.     {
  29.         $this->authenticationManagerListener $authenticationManagerListener;
  30.         $this->hasVardumper class_exists(ClassStub::class);
  31.     }
  32.     public function supports(Request $request): ?bool
  33.     {
  34.         return $this->authenticationManagerListener->supports($request);
  35.     }
  36.     public function authenticate(RequestEvent $event): void
  37.     {
  38.         $request $event->getRequest();
  39.         if (!$authenticators $request->attributes->get('_security_authenticators')) {
  40.             return;
  41.         }
  42.         foreach ($request->attributes->get('_security_skipped_authenticators') as $skippedAuthenticator) {
  43.             $this->authenticatorsInfo[] = [
  44.                 'supports' => false,
  45.                 'stub' => $this->hasVardumper ? new ClassStub(\get_class($skippedAuthenticator)) : \get_class($skippedAuthenticator),
  46.                 'passport' => null,
  47.                 'duration' => 0,
  48.             ];
  49.         }
  50.         foreach ($authenticators as $key => $authenticator) {
  51.             $authenticators[$key] = new TraceableAuthenticator($authenticator);
  52.         }
  53.         $request->attributes->set('_security_authenticators'$authenticators);
  54.         $this->authenticationManagerListener->authenticate($event);
  55.         foreach ($authenticators as $authenticator) {
  56.             $this->authenticatorsInfo[] = $authenticator->getInfo();
  57.         }
  58.     }
  59.     public function getAuthenticatorManagerListener(): AuthenticatorManagerListener
  60.     {
  61.         return $this->authenticationManagerListener;
  62.     }
  63.     public function getAuthenticatorsInfo(): array
  64.     {
  65.         return $this->authenticatorsInfo;
  66.     }
  67.     public function reset(): void
  68.     {
  69.         $this->authenticatorsInfo = [];
  70.     }
  71. }