Skip to content

Commit 8852084

Browse files
committed
Remove ambiguous usage of multiple roles in access_control
1 parent e905f32 commit 8852084

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

security.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ start with ``/admin``, you can:
513513
# require ROLE_ADMIN for /admin*
514514
- { path: '^/admin', roles: ROLE_ADMIN }
515515
516-
# or require multiple roles for /admin* (when defining multiple roles, the behavior depends on the strategy used in Access Decission Manager)
517-
- { path: '^/admin', roles: [IS_AUTHENTICATED_FULLY, ROLE_ADMIN] }
516+
# or provide an expression for /admin* (e.g. to require multiple roles)
517+
- { path: '^/admin', roles: 'is_granted("IS_AUTHENTICATED_FULLY") and is_granted("ROLE_ADMIN")' }
518518
519519
# the 'path' value can be any valid regular expression
520520
# (this one will match URLs like /api/post/7298 and /api/comment/528491)
@@ -540,10 +540,9 @@ start with ``/admin``, you can:
540540
<!-- require ROLE_ADMIN for /admin* -->
541541
<rule path="^/admin" role="ROLE_ADMIN"/>
542542
543-
<!-- require multiple roles for /admin* (when defining multiple roles, the behavior depends on the strategy used in Access Decission Manager) -->
543+
<!-- or provide an expression for /admin* (e.g. to require multiple roles) -->
544544
<rule path="^/admin">
545-
<role>ROLE_ADMIN</role>
546-
<role>IS_AUTHENTICATED_FULLY</role>
545+
<role>is_granted("IS_AUTHENTICATED_FULLY") and is_granted("ROLE_ADMIN")</role>
547546
</rule>
548547
549548
<!-- the 'path' value can be any valid regular expression
@@ -569,7 +568,7 @@ start with ``/admin``, you can:
569568
['path' => '^/admin', 'roles' => 'ROLE_ADMIN'],
570569
571570
// require multiple roles for /admin* (when defining multiple roles, the behavior depends on the strategy used in Access Decission Manager)
572-
['path' => '^/admin', 'roles' => ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY']],
571+
['path' => '^/admin', 'roles' => 'is_granted("IS_AUTHENTICATED_FULLY") and is_granted("ROLE_ADMIN")'],
573572
574573
// the 'path' value can be any valid regular expression
575574
// (this one will match URLs like /api/post/7298 and /api/comment/528491)

security/access_control.rst

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ Take the following ``access_control`` entries as an example:
4444
- { path: '^/admin', roles: ROLE_USER_IP, ip: 127.0.0.1 }
4545
- { path: '^/admin', roles: ROLE_USER_HOST, host: symfony\.com$ }
4646
- { path: '^/admin', roles: ROLE_USER_METHOD, methods: [POST, PUT] }
47-
# when defining multiple roles, the behavior depends on the strategy used in Access Decission Manager
48-
- { path: '^/admin', roles: [ROLE_MANAGER, ROLE_ADMIN] }
4947
5048
.. code-block:: xml
5149
@@ -63,8 +61,6 @@ Take the following ``access_control`` entries as an example:
6361
<rule path="^/admin" role="ROLE_USER_IP" ip="127.0.0.1"/>
6462
<rule path="^/admin" role="ROLE_USER_HOST" host="symfony\.com$"/>
6563
<rule path="^/admin" role="ROLE_USER_METHOD" methods="POST, PUT"/>
66-
<!-- when defining multiple roles, the behavior depends on the strategy used in Access Decission Manager -->
67-
<rule path="^/admin" roles="ROLE_ADMIN, ROLE_MANAGER"/>
6864
</config>
6965
</srv:container>
7066
@@ -95,11 +91,6 @@ Take the following ``access_control`` entries as an example:
9591
'roles' => 'ROLE_USER_METHOD',
9692
'methods' => 'POST, PUT',
9793
],
98-
[
99-
'path' => '^/admin',
100-
// when defining multiple roles, the behavior depends on the strategy used in Access Decission Manager
101-
'roles' => ['ROLE_MANAGER', 'ROLE_ADMIN'],
102-
],
10394
],
10495
]);
10596
@@ -156,13 +147,7 @@ options:
156147

157148
* ``roles`` If the user does not have the given role, then access is denied
158149
(internally, an :class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
159-
is thrown). If this value is an array of multiple roles, the user must have:
160-
161-
* at least one of them when using the default ``affirmative`` strategy.
162-
* more granted than denied roles when using the ``consensus`` strategy.
163-
* all of them when using the ``unanimous`` strategy.
164-
165-
For more details about different strategies, see :ref:`Access Decision Manager <components-security-access-decision-manager>`.
150+
is thrown).
166151

167152
* ``allow_if`` If the expression returns false, then access is denied;
168153

0 commit comments

Comments
 (0)