Skip to content

Commit 7bcc8cd

Browse files
Added example for PHP, XML format
1 parent fc96d8a commit 7bcc8cd

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

security/access_control.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Take the following ``access_control`` entries as an example:
6666
# for custom matching needs, use a request matcher service
6767
- { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }
6868
69-
# require ROLE_ADMIN for 'admin' route. You can use the shortcut "route: xxx", instead of "attributes": ["_route": "xxx"].
69+
# require ROLE_ADMIN for 'admin' route. You can use the shortcut "route: "xxx", instead of "attributes": ["_route": "xxx"]
7070
- { attributes: {'_route': 'admin'}, roles: ROLE_ADMIN }
7171
- { route: 'admin', roles: ROLE_ADMIN }
7272
@@ -103,6 +103,12 @@ Take the following ``access_control`` entries as an example:
103103
104104
<!-- for custom matching needs, use a request matcher service -->
105105
<rule role="ROLE_USER" request-matcher="App\Security\RequestMatcher\MyRequestMatcher"/>
106+
107+
<!-- require ROLE_ADMIN for 'admin' route. You can use the shortcut route="xxx" -->
108+
<rule role="ROLE_ADMIN">
109+
<attribute key="_route">admin</attribute>
110+
</rule>
111+
<rule route="admin" role="ROLE_ADMIN"/>
106112
</config>
107113
</srv:container>
108114
@@ -154,6 +160,17 @@ Take the following ``access_control`` entries as an example:
154160
->roles(['ROLE_USER'])
155161
->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
156162
;
163+
164+
// require ROLE_ADMIN for 'admin' route. You can use the shortcut route('xxx') mehtod,
165+
// instead of attributes(['_route' => 'xxx']) method
166+
$security->accessControl()
167+
->roles(['ROLE_ADMIN'])
168+
->attributes(['_route' => 'admin'])
169+
;
170+
$security->accessControl()
171+
->roles(['ROLE_ADMIN'])
172+
->route('admin')
173+
;
157174
};
158175
159176
For each incoming request, Symfony will decide which ``access_control``

0 commit comments

Comments
 (0)