vendor/symfony/security-http/EntryPoint/RetryAuthenticationEntryPoint.php line 19

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\EntryPoint;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  14. use Symfony\Component\Security\Http\Firewall\ChannelListener;
  15. trigger_deprecation('symfony/security-http', '5.4', 'The "%s" class is deprecated, use "%s" directly (and optionally configure the HTTP(s) ports there).', RetryAuthenticationEntryPoint::class, ChannelListener::class);
  16. /**
  17. * RetryAuthenticationEntryPoint redirects URL based on the configured scheme.
  18. *
  19. * This entry point is not intended to work with HTTP post requests.
  20. *
  21. * @author Fabien Potencier <fabien@symfony.com>
  22. *
  23. * @deprecated since Symfony 5.4
  24. */
  25. class RetryAuthenticationEntryPoint implements AuthenticationEntryPointInterface
  26. {
  27. private $httpPort;
  28. private $httpsPort;
  29. public function __construct(int $httpPort = 80, int $httpsPort = 443)
  30. {
  31. $this->httpPort = $httpPort;
  32. $this->httpsPort = $httpsPort;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function start(Request $request, ?AuthenticationException $authException = null)
  38. {
  39. $scheme = $request->isSecure() ? 'http' : 'https';
  40. if ('http' === $scheme && 80 != $this->httpPort) {
  41. $port = ':'.$this->httpPort;
  42. } elseif ('https' === $scheme && 443 != $this->httpsPort) {
  43. $port = ':'.$this->httpsPort;
  44. } else {
  45. $port = '';
  46. }
  47. $qs = $request->getQueryString();
  48. if (null !== $qs) {
  49. $qs = '?'.$qs;
  50. }
  51. $url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$request->getPathInfo().$qs;
  52. return new RedirectResponse($url, 301);
  53. }
  54. }