Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/security-http/Authentication/DefaultAuthenticationSuccessHandler.php line 49

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\Authentication;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  14. use Symfony\Component\Security\Http\HttpUtils;
  15. use Symfony\Component\Security\Http\ParameterBagUtils;
  16. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  17. /**
  18.  * Class with the default authentication success handling logic.
  19.  *
  20.  * @author Fabien Potencier <fabien@symfony.com>
  21.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  22.  * @author Alexander <iam.asm89@gmail.com>
  23.  */
  24. class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
  25. {
  26.     use TargetPathTrait;
  27.     protected $httpUtils;
  28.     protected $logger;
  29.     protected $options;
  30.     /** @deprecated since Symfony 5.2, use $firewallName instead */
  31.     protected $providerKey;
  32.     protected $firewallName;
  33.     protected $defaultOptions = [
  34.         'always_use_default_target_path' => false,
  35.         'default_target_path' => '/',
  36.         'login_path' => '/login',
  37.         'target_path_parameter' => '_target_path',
  38.         'use_referer' => false,
  39.     ];
  40.     /**
  41.      * @param array $options Options for processing a successful authentication attempt
  42.      */
  43.     public function __construct(HttpUtils $httpUtils, array $options = [], LoggerInterface $logger null)
  44.     {
  45.         $this->httpUtils $httpUtils;
  46.         $this->logger $logger;
  47.         $this->setOptions($options);
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function onAuthenticationSuccess(Request $requestTokenInterface $token)
  53.     {
  54.         return $this->httpUtils->createRedirectResponse($request$this->determineTargetUrl($request));
  55.     }
  56.     /**
  57.      * Gets the options.
  58.      *
  59.      * @return array
  60.      */
  61.     public function getOptions()
  62.     {
  63.         return $this->options;
  64.     }
  65.     public function setOptions(array $options)
  66.     {
  67.         $this->options array_merge($this->defaultOptions$options);
  68.     }
  69.     /**
  70.      * Get the provider key.
  71.      *
  72.      * @return string
  73.      *
  74.      * @deprecated since Symfony 5.2, use getFirewallName() instead
  75.      */
  76.     public function getProviderKey()
  77.     {
  78.         if (!== \func_num_args() || true !== func_get_arg(0)) {
  79.             trigger_deprecation('symfony/security-core''5.2''Method "%s()" is deprecated, use "getFirewallName()" instead.'__METHOD__);
  80.         }
  81.         if ($this->providerKey !== $this->firewallName) {
  82.             trigger_deprecation('symfony/security-core''5.2''The "%1$s::$providerKey" property is deprecated, use "%1$s::$firewallName" instead.'__CLASS__);
  83.             return $this->providerKey;
  84.         }
  85.         return $this->firewallName;
  86.     }
  87.     public function setProviderKey(string $providerKey)
  88.     {
  89.         if (!== \func_num_args() || true !== func_get_arg(1)) {
  90.             trigger_deprecation('symfony/security-http''5.2''Method "%s" is deprecated, use "setFirewallName()" instead.'__METHOD__);
  91.         }
  92.         $this->providerKey $providerKey;
  93.     }
  94.     public function getFirewallName(): ?string
  95.     {
  96.         return $this->getProviderKey(true);
  97.     }
  98.     public function setFirewallName(string $firewallName): void
  99.     {
  100.         $this->setProviderKey($firewallNametrue);
  101.         $this->firewallName $firewallName;
  102.     }
  103.     /**
  104.      * Builds the target URL according to the defined options.
  105.      *
  106.      * @return string
  107.      */
  108.     protected function determineTargetUrl(Request $request)
  109.     {
  110.         if ($this->options['always_use_default_target_path']) {
  111.             return $this->options['default_target_path'];
  112.         }
  113.         $targetUrl ParameterBagUtils::getRequestParameterValue($request$this->options['target_path_parameter']);
  114.         if (\is_string($targetUrl) && (str_starts_with($targetUrl'/') || str_starts_with($targetUrl'http'))) {
  115.             return $targetUrl;
  116.         }
  117.         if ($this->logger && $targetUrl) {
  118.             $this->logger->debug(sprintf('Ignoring query parameter "%s": not a valid URL.'$this->options['target_path_parameter']));
  119.         }
  120.         $firewallName $this->getFirewallName();
  121.         if (null !== $firewallName && $targetUrl $this->getTargetPath($request->getSession(), $firewallName)) {
  122.             $this->removeTargetPath($request->getSession(), $firewallName);
  123.             return $targetUrl;
  124.         }
  125.         if ($this->options['use_referer'] && $targetUrl $request->headers->get('Referer')) {
  126.             if (false !== $pos strpos($targetUrl'?')) {
  127.                 $targetUrl substr($targetUrl0$pos);
  128.             }
  129.             if ($targetUrl && $targetUrl !== $this->httpUtils->generateUri($request$this->options['login_path'])) {
  130.                 return $targetUrl;
  131.             }
  132.         }
  133.         return $this->options['default_target_path'];
  134.     }
  135. }