diff --git a/security/access_denied_handler.rst b/security/access_denied_handler.rst index 5671b0538a1..404c222e4c9 100644 --- a/security/access_denied_handler.rst +++ b/security/access_denied_handler.rst @@ -27,6 +27,7 @@ unauthenticated user tries to access a protected resource:: use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; + use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; @@ -41,7 +42,9 @@ unauthenticated user tries to access a protected resource:: public function start(Request $request, AuthenticationException $authException = null): RedirectResponse { // add a custom flash message and redirect to the login page - $request->getSession()->getFlashBag()->add('note', 'You have to login in order to access this page.'); + /** @var FlashBagInterface */ + $flashBag = $request->getSession()->getBag('flashes'); + $flashBag->add('note', 'You have to login in order to access this page.'); return new RedirectResponse($this->urlGenerator->generate('security_login')); }