@@ -190,13 +190,14 @@ also adjust the query parameter name via the ``parameter`` setting:
190
190
Limiting User Switching
191
191
-----------------------
192
192
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
197
197
elevated user such as an administrator.
198
198
199
199
.. versionadded :: 4.1
200
+
200
201
The target user was added as the voter subject parameter in Symfony 4.1.
201
202
202
203
Create the voter class::
@@ -223,7 +224,7 @@ Create the voter class::
223
224
return false;
224
225
}
225
226
226
- if (in_array('ROLE_CUSTOMER', $subject->getRoles())
227
+ if (in_array('ROLE_CUSTOMER', $subject->getRoles())
227
228
&& $this->hasSwitchToCustomerRole($token)) {
228
229
return true;
229
230
}
@@ -238,16 +239,19 @@ Create the voter class::
238
239
return true;
239
240
}
240
241
}
241
-
242
+
242
243
return false;
243
244
}
244
245
}
245
246
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 >`.
248
252
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.
251
255
252
256
Events
253
257
------
0 commit comments