From 97b9d66c26407300226155c6c8179d27d08d3ec8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Thu, 14 Nov 2019 23:58:06 +0100 Subject: [PATCH] Add access denied security handler --- Security/AccessDeniedHandler.php | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Security/AccessDeniedHandler.php 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'; + } +} -- 2.41.0