Skip to content

Commit 3f5b97a

Browse files
TristanPouliquenSpomky
authored andcommitted
[Security] Reference the new request_matcher option
1 parent d1d231c commit 3f5b97a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

security.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,12 @@ would match ``/admin/foo`` but would also match URLs like ``/foo/admin``.
21322132

21332133
Each ``access_control`` can also match on IP address, hostname and HTTP methods.
21342134
It can also be used to redirect a user to the ``https`` version of a URL pattern.
2135+
2136+
.. versionadded:: 6.1
2137+
2138+
Since Symfony 6.1, an access control rule can also be directly configured by passing a service
2139+
implementing `RequestMatcherInterface` through the `request_matcher` option.
2140+
21352141
See :doc:`/security/access_control`.
21362142

21372143
.. _security-securing-controller:

security/access_control.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Take the following ``access_control`` entries as an example:
5252
- { path: '^/admin', roles: ROLE_USER_IP, ips: '%env(TRUSTED_IPS)%' }
5353
- { path: '^/admin', roles: ROLE_USER_IP, ips: [127.0.0.1, ::1, '%env(TRUSTED_IPS)%'] }
5454
55+
# Request matchers can be used to define access control rules
56+
- { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }
57+
5558
.. code-block:: xml
5659
5760
<!-- config/packages/security.xml -->
@@ -82,6 +85,9 @@ Take the following ``access_control`` entries as an example:
8285
<ip>::1</ip>
8386
<ip>%env(TRUSTED_IPS)%</ip>
8487
</rule>
88+
89+
<!-- Request matchers can be used to define access control rules -->
90+
<rule role="ROLE_USER" request-matcher="App\Security\RequestMatcher\MyRequestMatcher"/>
8591
</config>
8692
</srv:container>
8793
@@ -127,8 +133,18 @@ Take the following ``access_control`` entries as an example:
127133
->roles(['ROLE_USER_IP'])
128134
->ips(['127.0.0.1', '::1', env('TRUSTED_IPS')])
129135
;
136+
137+
// Request matchers can be used to define access control rules
138+
$security->accessControl()
139+
->roles(['ROLE_USER'])
140+
->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
141+
;
130142
};
131143
144+
.. versionadded:: 6.1
145+
146+
Support for access control rule definition based on a RequestMatcher was introduced in Symfony 6.1.
147+
132148
For each incoming request, Symfony will decide which ``access_control``
133149
to use based on the URI, the client's IP address, the incoming host name,
134150
and the request method. Remember, the first rule that matches is used, and

0 commit comments

Comments
 (0)