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

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