From 52a254bdbbf383981b1bcad42d018125049eed10 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 20 Mar 2023 17:24:38 +0100 Subject: [PATCH] [Security] Add argument `exceptionCode` to `#[IsGranted]` --- security.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/security.rst b/security.rst index 35949345fd7..9e87a7e0f20 100644 --- a/security.rst +++ b/security.rst @@ -2321,10 +2321,30 @@ is 403), this can be done by setting with the ``statusCode`` argument:: // ... } +You can also set the internal exception code of the +:class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException` +that is thrown with the ``exceptionCode`` argument:: + + // src/Controller/AdminController.php + // ... + + use Symfony\Component\Security\Http\Attribute\IsGranted; + + #[IsGranted('ROLE_ADMIN', statusCode: 403, exceptionCode: 10010)] + class AdminController extends AbstractController + { + // ... + } + .. versionadded:: 6.2 The ``#[IsGranted()]`` attribute was introduced in Symfony 6.2. +.. versionadded:: 6.3 + + The ``exceptionCode`` argument of the ``#[IsGranted()]`` attribute was + introduced in Symfony 6.3. + .. _security-template: Access Control in Templates