Skip to content

Commit 06103c9

Browse files
committed
Allow configuring a target url when switching user
1 parent 3e1a5e2 commit 06103c9

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

security/impersonating_user.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,64 @@ also adjust the query parameter name via the ``parameter`` setting:
244244
;
245245
};
246246
247+
Redirecting to a specific target url
248+
------------------------------------
249+
250+
.. versionadded:: 6.2
251+
252+
The ``target_url`` configuration option was introduced in Symfony 6.2.
253+
254+
This feature allows you to control the redirection url via ``target_url``.
255+
It works only in a statefull firewall.
256+
257+
.. configuration-block::
258+
259+
.. code-block:: yaml
260+
261+
# config/packages/security.yaml
262+
security:
263+
# ...
264+
265+
firewalls:
266+
main:
267+
# ...
268+
switch_user: { target_url: /dasboard }
269+
270+
.. code-block:: xml
271+
272+
<!-- config/packages/security.xml -->
273+
<?xml version="1.0" encoding="UTF-8" ?>
274+
<srv:container xmlns="http://symfony.com/schema/dic/security"
275+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
276+
xmlns:srv="http://symfony.com/schema/dic/services"
277+
xsi:schemaLocation="http://symfony.com/schema/dic/services
278+
https://symfony.com/schema/dic/services/services-1.0.xsd
279+
http://symfony.com/schema/dic/security
280+
https://symfony.com/schema/dic/security/security-1.0.xsd">
281+
<config>
282+
<!-- ... -->
283+
284+
<firewall name="main">
285+
<!-- ... -->
286+
<switch-user target_url="/dasboard"/>
287+
</firewall>
288+
</config>
289+
</srv:container>
290+
291+
.. code-block:: php
292+
293+
// config/packages/security.php
294+
use Symfony\Config\SecurityConfig;
295+
296+
return static function (SecurityConfig $security) {
297+
// ...
298+
$security->firewall('main')
299+
// ...
300+
->switchUser()
301+
->targetUrl('/dasboard')
302+
;
303+
};
304+
247305
Limiting User Switching
248306
-----------------------
249307

0 commit comments

Comments
 (0)