@@ -437,6 +437,10 @@ start with ``/admin``, you can:
437437 # require ROLE_ADMIN for /admin*
438438 - { path: ^/admin, roles: ROLE_ADMIN }
439439
440+ # the 'path' value can be any valid regular expression
441+ # (this one will match URLs like /api/post/7298 and /api/comment/528491)
442+ - { path: ^/api/(post|comment)/\d+$, roles: ROLE_USER }
443+
440444 .. code-block :: xml
441445
442446 <!-- config/packages/security.xml -->
@@ -456,6 +460,10 @@ start with ``/admin``, you can:
456460
457461 <!-- require ROLE_ADMIN for /admin* -->
458462 <rule path =" ^/admin" role =" ROLE_ADMIN" />
463+
464+ <!-- the 'path' value can be any valid regular expression
465+ (this one will match URLs like /api/post/7298 and /api/comment/528491) -->
466+ <rule path =" ^/api/(post|comment)/\d+$" role =" ROLE_USER" />
459467 </config >
460468 </srv : container >
461469
@@ -474,6 +482,10 @@ start with ``/admin``, you can:
474482 'access_control' => [
475483 // require ROLE_ADMIN for /admin*
476484 ['path' => '^/admin', 'role' => 'ROLE_ADMIN'],
485+
486+ // the 'path' value can be any valid regular expression
487+ // (this one will match URLs like /api/post/7298 and /api/comment/528491)
488+ ['path' => '^/api/(post|comment)/\d+$', 'role' => 'ROLE_USER'],
477489 ],
478490 ]);
479491
0 commit comments