@@ -437,6 +437,10 @@ start with ``/admin``, you can:
437
437
# require ROLE_ADMIN for /admin*
438
438
- { path: ^/admin, roles: ROLE_ADMIN }
439
439
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
+
440
444
.. code-block :: xml
441
445
442
446
<!-- config/packages/security.xml -->
@@ -456,6 +460,10 @@ start with ``/admin``, you can:
456
460
457
461
<!-- require ROLE_ADMIN for /admin* -->
458
462
<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" />
459
467
</config >
460
468
</srv : container >
461
469
@@ -474,6 +482,10 @@ start with ``/admin``, you can:
474
482
'access_co
6969
ntrol' => [
475
483
// require ROLE_ADMIN for /admin*
476
484
['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'],
477
489
],
478
490
]);
479
491
0 commit comments