Skip to content

Commit 52a254b

Browse files
[Security] Add argument exceptionCode to #[IsGranted]
1 parent 4b00ae1 commit 52a254b

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
@@ -2321,10 +2321,30 @@ is 403), this can be done by setting with the ``statusCode`` argument::
23212321
// ...
23222322
}
23232323

2324+
You can also set the internal exception code of the
2325+
:class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
2326+
that is thrown with the ``exceptionCode`` argument::
2327+
2328+
// src/Controller/AdminController.php
2329+
// ...
2330+
2331+
use Symfony\Component\Security\Http\Attribute\IsGranted;
2332+
2333+
#[IsGranted('ROLE_ADMIN', statusCode: 403, exceptionCode: 10010)]
2334+
class AdminController extends AbstractController
2335+
{
2336+
// ...
2337+
}
2338+
23242339
.. versionadded:: 6.2
23252340

23262341
The ``#[IsGranted()]`` attribute was introduced in Symfony 6.2.
23272342

2343+
.. versionadded:: 6.3
2344+
2345+
The ``exceptionCode`` argument of the ``#[IsGranted()]`` attribute was
2346+
introduced in Symfony 6.3.
2347+
23282348
.. _security-template:
23292349

23302350
Access Control in Templates

0 commit comments

Comments
 (0)