vendor/symfony/security-http/EntryPoint/FormAuthenticationEntryPoint.php line 20

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\Request;
  12. use Symfony\Component\HttpKernel\HttpKernelInterface;
  13. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  14. use Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator;
  15. use Symfony\Component\Security\Http\HttpUtils;
  16. trigger_deprecation('symfony/security-http', '5.4', 'The "%s" class is deprecated, use the new security system with "%s" instead.', FormAuthenticationEntryPoint::class, FormLoginAuthenticator::class);
  17. /**
  18. * FormAuthenticationEntryPoint starts an authentication via a login form.
  19. *
  20. * @author Fabien Potencier <fabien@symfony.com>
  21. *
  22. * @deprecated since Symfony 5.4
  23. */
  24. class FormAuthenticationEntryPoint implements AuthenticationEntryPointInterface
  25. {
  26. private $loginPath;
  27. private $useForward;
  28. private $httpKernel;
  29. private $httpUtils;
  30. /**
  31. * @param string $loginPath The path to the login form
  32. * @param bool $useForward Whether to forward or redirect to the login form
  33. */
  34. public function __construct(HttpKernelInterface $kernel, HttpUtils $httpUtils, string $loginPath, bool $useForward = false)
  35. {
  36. $this->httpKernel = $kernel;
  37. $this->httpUtils = $httpUtils;
  38. $this->loginPath = $loginPath;
  39. $this->useForward = $useForward;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function start(Request $request, ?AuthenticationException $authException = null)
  45. {
  46. if ($this->useForward) {
  47. $subRequest = $this->httpUtils->createRequest($request, $this->loginPath);
  48. $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
  49. if (200 === $response->getStatusCode()) {
  50. $response->setStatusCode(401);
  51. }
  52. return $response;
  53. }
  54. return $this->httpUtils->createRedirectResponse($request, $this->loginPath);
  55. }
  56. }