Skip to content

Commit 17ceb21

Browse files
[Security] Add argument statusCode to #[IsGranted]
1 parent 7961840 commit 17ceb21

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

security.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,27 +2299,30 @@ the ``ROLE_SUPER_ADMIN`` permission:
22992299
#[IsGranted('ROLE_ADMIN')]
23002300
class AdminController extends AbstractController
23012301
{
2302+
// Optionally, you can set a custom message that will be displayed to the user
23022303
#[IsGranted('ROLE_SUPER_ADMIN', message: 'You are not allowed to access the admin dashboard.')]
23032304
public function adminDashboard(): Response
23042305
{
23052306
// ...
23062307
}
23072308
}
23082309
2309-
A custom status code can be set with the ``statusCode`` argument. This
2310-
code will be used in the HTTP response::
2310+
If you want to use a custom status code instead of the default one (which
2311+
is 403), this can be done by setting with the ``statusCode`` argument::
23112312

23122313
// src/Controller/AdminController.php
23132314
// ...
23142315

23152316
use Symfony\Component\Security\Http\Attribute\IsGranted;
23162317

2317-
#[IsGranted('ROLE_ADMIN', statusCode: 403)]
2318+
#[IsGranted('ROLE_ADMIN', statusCode: 423)]
23182319
class AdminController extends AbstractController
23192320
{
23202321
// ...
23212322
}
23222323

2324+
The default code is 403.
2325+
23232326
.. versionadded:: 6.2
23242327

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

0 commit comments

Comments
 (0)