Skip to content

Commit ca5c684

Browse files
Add configuration code example
1 parent 7f8c440 commit ca5c684

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
@@ -169,6 +169,50 @@ if ``ip``, ``port``, ``host`` or ``method`` are not specified for an entry, that
169169
.. versionadded:: 6.1
170170

171171
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.
172+
173+
.. configuration-block::
174+
175+
.. code-block:: yaml
176+
177+
# config/packages/security.yaml
178+
security:
179+
# ...
180+
access_control:
181+
- { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }
182+
183+
.. code-block:: xml
184+
185+
<!-- config/packages/security.xml -->
186+
<?xml version="1.0" encoding="UTF-8" ?>
187+
<srv:container xmlns="http://symfony.com/schema/dic/security"
188+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
189+
xmlns:srv="http://symfony.com/schema/dic/services"
190+
xsi:schemaLocation="http://symfony.com/schema/dic/services
191+
https://symfony.com/schema/dic/services/services-1.0.xsd
192+
http://symfony.com/schema/dic/security
193+
https://symfony.com/schema/dic/security/security-1.0.xsd">
194+
195+
<config>
196+
<!-- ... -->
197+
<rule role="ROLE_USER" request-matcher="App\Security\RequestMatcher\MyRequestMatcher"/>
198+
</config>
199+
</srv:container>
200+
201+
.. code-block:: php
202+
203+
// config/packages/security.php
204+
use Symfony\Component\DependencyInjection\ContainerBuilder;
205+
use Symfony\Config\SecurityConfig;
206+
207+
return static function (ContainerBuilder $container, SecurityConfig $security) {
208+
// ...
209+
210+
$security->accessControl()
211+
->roles(['ROLE_USER'])
212+
->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
213+
;
214+
};
215+
172216
173217
.. _security-access-control-enforcement-options:
174218

0 commit comments

Comments
 (0)