@@ -2198,8 +2198,10 @@ will happen:
2198
2198
2199
2199
.. _security-securing-controller-annotations :
2200
2200
2201
- Thanks to the SensioFrameworkExtraBundle, you can also secure your controller
2202
- using annotations:
2201
+ Another way to secure one or more controller actions is to use an attribute or
2202
+ annotation. In the following example, all controller actions will require the
2203
+ ``ROLE_ADMIN `` permission, except for ``adminDashboard() ``, which will require
2204
+ the ``ROLE_SUPER_ADMIN `` permission:
2203
2205
2204
2206
.. configuration-block ::
2205
2207
@@ -2211,15 +2213,11 @@ using annotations:
2211
2213
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2212
2214
2213
2215
/**
2214
- * Require ROLE_ADMIN for all the actions of this controller
2215
- *
2216
2216
* @IsGranted("ROLE_ADMIN")
2217
2217
*/
2218
2218
class AdminController extends AbstractController
2219
2219
{
2220
2220
/**
2221
- * Require ROLE_SUPER_ADMIN only for this action
2222
- *
2223
2221
* @IsGranted("ROLE_SUPER_ADMIN")
2224
2222
*/
2225
2223
public function adminDashboard(): Response
@@ -2233,25 +2231,25 @@ using annotations:
2233
2231
// src/Controller/AdminController.php
2234
2232
// ...
2235
2233
2236
- use Sensio\Bundle\FrameworkExtraBundle\Configuration \IsGranted;
2234
+ use Symfony\Component\Security\Http\Attribute \IsGranted;
2237
2235
2238
- /**
2239
- * Require ROLE_ADMIN for all the actions of this controller
2240
- */
2241
2236
#[IsGranted('ROLE_ADMIN')]
2242
2237
class AdminController extends AbstractController
2243
2238
{
2244
- /**
2245
- * Require ROLE_SUPER_ADMIN only for this action
2246
- */
2247
2239
#[IsGranted('ROLE_SUPER_ADMIN')]
2248
2240
public function adminDashboard(): Response
2249
2241
{
2250
2242
// ...
2251
2243
}
2252
2244
}
2253
2245
2254
- For more information, see the `FrameworkExtraBundle documentation `_.
2246
+ The ``#[IsGranted()] `` attribute is built-in in Symfony and it's recommended for
2247
+ modern applications. Using the ``@IsGranted() `` annotation requires to install
2248
+ an external bundle called `FrameworkExtraBundle `_.
2249
+
2250
+ .. versionadded :: 6.2
2251
+
2252
+ The ``#[IsGranted()] `` attribute was introduced in Symfony 6.2.
2255
2253
2256
2254
.. _security-template :
2257
2255
@@ -2690,7 +2688,7 @@ Authorization (Denying Access)
2690
2688
security/access_denied_handler
2691
2689
security/force_https
2692
2690
2693
- .. _`FrameworkExtraBundle documentation ` : https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
2691
+ .. _`FrameworkExtraBundle` : https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
2694
2692
.. _`HWIOAuthBundle` : https://github.com/hwi/HWIOAuthBundle
2695
2693
.. _`OWASP Brute Force Attacks` : https://owasp.org/www-community/controls/Blocking_Brute_Force_Attacks
2696
2694
.. _`brute force login attacks` : https://owasp.org/www-community/controls/Blocking_Brute_Force_Attacks
0 commit comments