src/Security/AuthenticationEntryPoint.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use Symfony\Component\HttpFoundation\RedirectResponse;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  6. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  7. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  8. class AuthenticationEntryPoint implements AuthenticationEntryPointInterface
  9. {
  10.     private $urlGenerator;
  11.     public function __construct(UrlGeneratorInterface $urlGenerator)
  12.     {
  13.         $this->urlGenerator $urlGenerator;
  14.     }
  15.     public function start(Request $requestAuthenticationException $authException null): RedirectResponse
  16.     {
  17.         // add a custom flash message and redirect to the login page
  18.         $request->getSession()->getFlashBag()->add('warning''You have to login in order to access this page.');
  19.         return new RedirectResponse($this->urlGenerator->generate('login'));
  20.     }
  21. }