Skip to content

Commit 6009b8f

Browse files
committed
minor #18101 [Security] Add argument $exceptionCode to #[IsGranted] (alexandre-daubois)
This PR was merged into the 6.3 branch. Discussion ---------- [Security] Add argument `$exceptionCode` to `#[IsGranted]` Fixes #18097 Commits ------- 52a254b [Security] Add argument `exceptionCode` to `#[IsGranted]`
2 parents 2497577 + 52a254b commit 6009b8f

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
@@ -2330,10 +2330,30 @@ is 403), this can be done by setting with the ``statusCode`` argument::
23302330
// ...
23312331
}
23322332

2333+
You can also set the internal exception code of the
2334+
:class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
2335+
that is thrown with the ``exceptionCode`` argument::
2336+
2337+
// src/Controller/AdminController.php
2338+
// ...
2339+
2340+
use Symfony\Component\Security\Http\Attribute\IsGranted;
2341+
2342+
#[IsGranted('ROLE_ADMIN', statusCode: 403, exceptionCode: 10010)]
2343+
class AdminController extends AbstractController
2344+
{
2345+
// ...
2346+
}
2347+
23332348
.. versionadded:: 6.2
23342349

23352350
The ``#[IsGranted()]`` attribute was introduced in Symfony 6.2.
23362351

2352+
.. versionadded:: 6.3
2353+
2354+
The ``exceptionCode`` argument of the ``#[IsGranted()]`` attribute was
2355+
introduced in Symfony 6.3.
2356+
23372357
.. _security-template:
23382358

23392359
Access Control in Templates

0 commit comments

Comments
 (0)