Skip to content

Commit 11b0377

Browse files
committed
minor #16296 [Security] Reference the new request_matcher option (TristanPouliquen)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Security] Reference the new request_matcher option Linked to symfony/symfony#44670 <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- f0432c4 [Security] Reference the new request_matcher option
2 parents 9426b5d + f0432c4 commit 11b0377

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
@@ -2117,6 +2117,12 @@ would match ``/admin/foo`` but would also match URLs like ``/foo/admin``.
21172117

21182118
Each ``access_control`` can also match on IP address, hostname and HTTP methods.
21192119
It can also be used to redirect a user to the ``https`` version of a URL pattern.
2120+
2121+
.. versionadded:: 6.1
2122+
2123+
Since Symfony 6.1, an access control rule can also be directly configured by passing a service
2124+
implementing `RequestMatcherInterface` through the `request_matcher` option.
2125+
21202126
See :doc:`/security/access_control`.
21212127

21222128
.. _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)