Skip to content

Commit f54811f

Browse files
committed
[Security] add methods argument to #[IsGranted] to restrict access by HTTP method
1 parent a352a48 commit f54811f

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
@@ -2543,6 +2543,29 @@ You can also extend the ``IsGranted`` attribute to create meaningful shortcuts::
25432543
The :class:`Symfony\\Component\\Security\\Http\\Attribute\\IsGranted`
25442544
attribute is extendable since Symfony 7.4.
25452545

2546+
You can restrict access validation to specific HTTP methods
2547+
by using the ``methods`` argument::
2548+
2549+
// src/Controller/AdminController.php
2550+
// ...
2551+
2552+
use Symfony\Component\Security\Http\Attribute\IsGranted;
2553+
2554+
#[IsGranted('ROLE_ADMIN', methods: 'POST')]
2555+
class AdminController extends AbstractController
2556+
{
2557+
// You can also specify an array of methods
2558+
#[IsGranted('ROLE_SUPER_ADMIN', methods: ['GET', 'PUT'])]
2559+
public function adminDashboard(): Response
2560+
{
2561+
// ...
2562+
}
2563+
}
2564+
2565+
.. versionadded:: 7.4
2566+
2567+
The ``methods`` argument was introduced in Symfony 7.4.
2568+
25462569
.. _security-template:
25472570

25482571
Access Control in Templates

0 commit comments

Comments
 (0)