8000 Minor tweaks · ThomasLandauer/symfony-docs@7853ec0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7853ec0

Browse files
committed
Minor tweaks
1 parent 876257b commit 7853ec0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

security/impersonating_user.rst

Original file line numberDiff line numberDiff line change
@@ -190,13 +190,14 @@ also adjust the query parameter name via the ``parameter`` setting:
190190
Limiting User Switching
191191
-----------------------
192192

193-
If you need more control over user switching, but don't require the complexity
194-
of a full ACL implementation, you can use a security voter. For example, you
195-
may want to allow employees to be able to impersonate a user with the
196-
``ROLE_CUSTOMER`` role without giving them the ability to impersonate a more
193+
If you need more control over user switching, but don't require the complexity
194+
of a full ACL implementation, you can use a security voter. For example, you
195+
may want to allow employees to be able to impersonate a user with the
196+
``ROLE_CUSTOMER`` role without giving them the ability to impersonate a more
197197
elevated user such as an administrator.
198198

199199
.. versionadded:: 4.1
200+
200201
The target user was added as the voter subject parameter in Symfony 4.1.
201202

202203
Create the voter class::
@@ -223,7 +224,7 @@ Create the voter class::
223224
return false;
224225
}
225226

226-
if (in_array('ROLE_CUSTOMER', $subject->getRoles())
227+
if (in_array('ROLE_CUSTOMER', $subject->getRoles())
227228
&& $this->hasSwitchToCustomerRole($token)) {
228229
return true;
229230
}
@@ -238,16 +239,19 @@ Create the voter class::
238239
return true;
239240
}
240241
}
241-
242+
242243
return false;
243244
}
244245
}
245246

246-
Thanks to service autoconfiguration and autowiring, this new voter is automatically
247-
registered as a service and tagged as a security voter.
247+
To enable the new voter in the app, register it as a service and
248+
:doc:`tag it </service_container/tags>` with the ``security.voter``
249+
tag. If you're using the
250+
:ref:`default services.yaml configuration <service-container-services-load-example>`,
251+
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
248252

249-
Now a user who has the ``ROLE_SWITCH_TO_CUSTOMER`` role can switch to a user who explicitly has the
250-
``ROLE_CUSTOMER`` role, but not other users.
253+
Now a user who has the ``ROLE_SWITCH_TO_CUSTOMER`` role can switch to a user who
254+
has the ``ROLE_CUSTOMER`` role, but not other users.
251255

252256
Events
253257
------