From: Raphaƫl Gertz Date: Thu, 14 Nov 2019 22:58:06 +0000 (+0100) Subject: Add access denied security handler X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/97b9d66c26407300226155c6c8179d27d08d3ec8 Add access denied security handler --- diff --git a/Security/AccessDeniedHandler.php b/Security/AccessDeniedHandler.php new file mode 100644 index 0000000..5494fb0 --- /dev/null +++ b/Security/AccessDeniedHandler.php @@ -0,0 +1,68 @@ +config = $container->getParameter($this->getAlias()); + + //Set the translator + $this->translator = $translator; + + //Set the environment + $this->environment = $environment; + } + + /** + * {@inheritdoc} + */ +#use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; + #public function login(Request $request, AuthenticationUtils $authenticationUtils) { + public function handle(Request $request, AccessDeniedException $accessDeniedException) { + //Set section + $section = $this->translator->trans('Access denied'); + + //Set title + $title = $section.' - '.$this->translator->trans($this->config['site']['title']); + + //Set message + $message = $this->translator->trans($accessDeniedException->getMessage()); + + //Render template + return new Response( + $this->environment->render( + '@RapsysAir/security/denied.html.twig', + ['title' => $title, 'section' => $section, 'message' => $message] + ), + 403 + ); + } + + /** + * {@inheritdoc} + */ + public function getAlias() { + return 'rapsys_air'; + } +}