Skip to content

Commit 8674f7d

Browse files
[Security] Add argument exceptionCode to #[IsGranted]
1 parent dc7368b commit 8674f7d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

security.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,10 +2306,30 @@ the ``ROLE_SUPER_ADMIN`` permission:
23062306
}
23072307
}
23082308
2309+
When using ``#[IsGranted()]``, you can set the internal exception code
2310+
of the :class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
2311+
that is thrown, thanks to the ``exceptionCode`` argument::
2312+
2313+
// src/Controller/AdminController.php
2314+
// ...
2315+
2316+
use Symfony\Component\Security\Http\Attribute\IsGranted;
2317+
2318+
#[IsGranted('ROLE_ADMIN', statusCode: 403, exceptionCode: 10010)]
2319+
class AdminController extends AbstractController
2320+
{
2321+
// ...
2322+
}
2323+
23092324
.. versionadded:: 6.2
23102325

23112326
The ``#[IsGranted()]`` attribute was introduced in Symfony 6.2.
23122327

2328+
.. versionadded:: 6.3
2329+
2330+
The ``exceptionCode`` argument of the ``#[IsGranted()]`` attribute was
2331+
introduced in Symfony 6.3.
2332+
23132333
.. _security-template:
23142334

23152335
Access Control in Templates

0 commit comments

Comments
 (0)