Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow specifying attributes forRequestMatcher#17388

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
OskarStark merged 1 commit intosymfony:6.2frommdoutreluingne:fix_17377
Oct 24, 2022
Merged
Changes fromall 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
Allow specifying attributes forRequestMatcher
  • Loading branch information
@mdoutreluingne@OskarStark
mdoutreluingne authored andOskarStark committedOct 24, 2022
commit0b08f8193e51c4cbdd367da98f0cf0d35e5d9274
27 changes: 27 additions & 0 deletionssecurity/access_control.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,11 +30,17 @@ options are used for matching:
* ``host``: a regular expression
* ``methods``: one or many HTTP methods
* ``request_matcher``: a service implementing ``RequestMatcherInterface``
* ``attributes``: an array, which can be used to specify one or more :ref:`request attributes <accessing-request-data>` that must match exactly
* ``route``: a route name

.. versionadded:: 6.1

The ``request_matcher`` option was introduced in Symfony 6.1.

.. versionadded:: 6.2

The ``route`` and ``attributes`` options were introduced in Symfony 6.2.

Take the following ``access_control`` entries as an example:

.. configuration-block::
Expand All@@ -60,6 +66,10 @@ Take the following ``access_control`` entries as an example:
# for custom matching needs, use a request matcher service
- { roles: ROLE_USER, request_matcher: App\Security\RequestMatcher\MyRequestMatcher }

# require ROLE_ADMIN for 'admin' route. You can use the shortcut "route: "xxx", instead of "attributes": ["_route": "xxx"]
- { attributes: {'_route': 'admin'}, roles: ROLE_ADMIN }
- { route: 'admin', roles: ROLE_ADMIN }

.. code-block:: xml

<!-- config/packages/security.xml -->
Expand DownExpand Up@@ -93,6 +103,12 @@ Take the following ``access_control`` entries as an example:

<!-- for custom matching needs, use a request matcher service -->
<rule role="ROLE_USER" request-matcher="App\Security\RequestMatcher\MyRequestMatcher"/>

<!-- require ROLE_ADMIN for 'admin' route. You can use the shortcut route="xxx" -->
<rule role="ROLE_ADMIN">
<attribute key="_route">admin</attribute>
</rule>
<rule route="admin" role="ROLE_ADMIN"/>
</config>
</srv:container>

Expand DownExpand Up@@ -144,6 +160,17 @@ Take the following ``access_control`` entries as an example:
->roles(['ROLE_USER'])
->requestMatcher('App\Security\RequestMatcher\MyRequestMatcher')
;

// require ROLE_ADMIN for 'admin' route. You can use the shortcut route('xxx') mehtod,
// instead of attributes(['_route' => 'xxx']) method
$security->accessControl()
->roles(['ROLE_ADMIN'])
->attributes(['_route' => 'admin'])
;
$security->accessControl()
->roles(['ROLE_ADMIN'])
->route('admin')
;
};

For each incoming request, Symfony will decide which ``access_control``
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp