Skip to content

[Security] Reference the new request_matcher option #16296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,12 @@ would match ``/admin/foo`` but would also match URLs like ``/foo/admin``.

Each ``access_control`` can also match on IP address, hostname and HTTP methods.
It can also be used to redirect a user to the ``https`` version of a URL pattern.

.. versionadded:: 6.1

Since Symfony 6.1, an access control rule can also be directly configured by passing a service
implementing `RequestMatcherInterface` through the `request_matcher` option.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backticks should be doubled


See :doc:`/security/access_control`.

.. _security-securing-controller:
Expand Down
16 changes: 16 additions & 0 deletions security/access_control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Take the following ``access_control`` entries as an example:
- { path: '^/admin', roles: ROLE_USER_IP, ips: '%env(TRUSTED_IPS)%' }
- { path: '^/admin', roles: ROLE_USER_IP, ips: [127.0.0.1, ::1, '%env(TRUSTED_IPS)%'] }

# Request matchers can be used to define access control rules
- { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }

.. code-block:: xml

<!-- config/packages/security.xml -->
Expand Down Expand Up @@ -82,6 +85,9 @@ Take the following ``access_control`` entries as an example:
<ip>::1</ip>
<ip>%env(TRUSTED_IPS)%</ip>
</rule>

<!-- Request matchers can be used to define access control rules -->
<rule role="ROLE_USER" request-matcher="App\Security\RequestMatcher\MyRequestMatcher"/>
</config>
</srv:container>

Expand Down Expand Up @@ -127,8 +133,18 @@ Take the following ``access_control`` entries as an example:
->roles(['ROLE_USER_IP'])
->ips(['127.0.0.1', '::1', '%env(TRUSTED_IPS)%'])
;

// Request matchers can be used to define access control rules
$security->accessControl()
->roles(['ROLE_USER'])
->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
;
};

.. versionadded:: 6.1

Support for access control rule definition based on a RequestMatcher was introduced in Symfony 6.1.

For each incoming request, Symfony will decide which ``access_control``
to use based on the URI, the client's IP address, the incoming host name,
and the request method. Remember, the first rule that matches is used, and
Expand Down