vendor/symfony/security-http/Authenticator/AbstractLoginFormAuthenticator.php line 53

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;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  15. use Symfony\Component\Security\Core\Security;
  16. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  17. /**
  18.  * A base class to make form login authentication easier!
  19.  *
  20.  * @author Ryan Weaver <ryan@symfonycasts.com>
  21.  */
  22. abstract class AbstractLoginFormAuthenticator extends AbstractAuthenticator implements AuthenticationEntryPointInterfaceInteractiveAuthenticatorInterface
  23. {
  24.     /**
  25.      * Return the URL to the login page.
  26.      */
  27.     abstract protected function getLoginUrl(Request $request): string;
  28.     /**
  29.      * {@inheritdoc}
  30.      *
  31.      * Override to change the request conditions that have to be
  32.      * matched in order to handle the login form submit.
  33.      *
  34.      * This default implementation handles all POST requests to the
  35.      * login path (@see getLoginUrl()).
  36.      */
  37.     public function supports(Request $request): bool
  38.     {
  39.         return $request->isMethod('POST') && $this->getLoginUrl($request) === $request->getBaseUrl().$request->getPathInfo();
  40.     }
  41.     /**
  42.      * Override to change what happens after a bad username/password is submitted.
  43.      */
  44.     public function onAuthenticationFailure(Request $requestAuthenticationException $exception): Response
  45.     {
  46.         if ($request->hasSession()) {
  47.             $request->getSession()->set(Security::AUTHENTICATION_ERROR$exception);
  48.         }
  49.         $url $this->getLoginUrl($request);
  50.         return new RedirectResponse($url);
  51.     }
  52.     /**
  53.      * Override to control what happens when the user hits a secure page
  54.      * but isn't logged in yet.
  55.      */
  56.     public function start(Request $requestAuthenticationException $authException null): Response
  57.     {
  58.         $url $this->getLoginUrl($request);
  59.         return new RedirectResponse($url);
  60.     }
  61.     public function isInteractive(): bool
  62.     {
  63.         return true;
  64.     }
  65. }