Skip to content

Commit 956837b

Browse files
Add configuration code example
1 parent 186ef8e commit 956837b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

security/access_control.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,50 @@ if ``ip``, ``port``, ``host`` or ``method`` are not specified for an entry, that
173173
.. versionadded:: 6.1
174174

175175
From verison 6.1 and up, if you have a custom request matcher, you can use the ``request_matcher`` option to specify the service reference to an access control item. Symfony will use this service as the request matcher for this item and won't take into account other matching options.
176+
177+
.. configuration-block::
178+
179+
.. code-block:: yaml
180+
181+
# config/packages/security.yaml
182+
security:
183+
# ...
184+
access_control:
185+
- { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }
186+
187+
.. code-block:: xml
188+
189+
<!-- config/packages/security.xml -->
190+
<?xml version="1.0" encoding="UTF-8" ?>
191+
<srv:container xmlns="http://symfony.com/schema/dic/security"
192+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
193+
xmlns:srv="http://symfony.com/schema/dic/services"
194+
xsi:schemaLocation="http://symfony.com/schema/dic/services
195+
https://symfony.com/schema/dic/services/services-1.0.xsd
196+
http://symfony.com/schema/dic/security
197+
https://symfony.com/schema/dic/security/security-1.0.xsd">
198+
199+
<config>
200+
<!-- ... -->
201+
<rule role="ROLE_USER" request-matcher="App\Security\RequestMatcher\MyRequestMatcher"/>
202+
</config>
203+
</srv:container>
204+
205+
.. code-block:: php
206+
207+
// config/packages/security.php
208+
use Symfony\Component\DependencyInjection\ContainerBuilder;
209+
use Symfony\Config\SecurityConfig;
210+
211+
return static function (ContainerBuilder $container, SecurityConfig $security) {
212+
// ...
213+
214+
$security->accessControl()
215+
->roles(['ROLE_USER'])
216+
->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
217+
;
218+
};
219+
176220
177221
.. _security-access-control-enforcement-options:
178222

0 commit comments

Comments
 (0)