Skip to content

Commit 4a03b0e

Browse files
committed
[Security] add methods argument to #[IsGranted] to restrict access by HTTP method
1 parent 6b6a678 commit 4a03b0e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

security.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,29 @@ that is thrown with the ``exceptionCode`` argument::
25232523
// ...
25242524
}
25252525

2526+
You can restrict access validation to specific HTTP methods
2527+
by using the ``methods`` argument::
2528+
2529+
// src/Controller/AdminController.php
2530+
// ...
2531+
2532+
use Symfony\Component\Security\Http\Attribute\IsGranted;
2533+
2534+
#[IsGranted('ROLE_ADMIN', methods: 'POST')]
2535+
class AdminController extends AbstractController
2536+
{
2537+
// You can also specify an array of methods
2538+
#[IsGranted('ROLE_SUPER_ADMIN', methods: ['GET', 'PUT'])]
2539+
public function adminDashboard(): Response
2540+
{
2541+
// ...
2542+
}
2543+
}
2544+
2545+
.. versionadded:: 7.4
2546+
2547+
The ``methods`` argument was introduced in Symfony 7.4.
2548+
25262549
.. _security-template:
25272550

25282551
Access Control in Templates

0 commit comments

Comments
 (0)