Skip to content

Commit

Permalink
Allow configuring a target url when switching user
Browse files Browse the repository at this point in the history
  • Loading branch information
94noni committed Sep 13, 2022
1 parent 9f55837 commit facbbb0
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions security/impersonating_user.rst
Expand Up @@ -244,6 +244,64 @@ also adjust the query parameter name via the ``parameter`` setting:
;
};
Redirecting to a specific target route
--------------------------------------

.. versionadded:: 6.2

The ``target_route`` configuration option was introduced in Symfony 6.2.

This feature allows you to control the redirection targe route via ``target_route``.
It works only in a statefull firewall.

.. configuration-block::

.. code-block:: yaml
# config/packages/security.yaml
security:
# ...
firewalls:
main:
# ...
switch_user: { target_route: app_user_dashboard }
.. code-block:: xml
<!-- config/packages/security.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<srv:container xmlns="http://symfony.com/schema/dic/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/security
https://symfony.com/schema/dic/security/security-1.0.xsd">
<config>
<!-- ... -->
<firewall name="main">
<!-- ... -->
<switch-user target-route="app_user_dashboard"/>
</firewall>
</config>
</srv:container>
.. code-block:: php
// config/packages/security.php
use Symfony\Config\SecurityConfig;
return static function (SecurityConfig $security) {
// ...
$security->firewall('main')
// ...
->switchUser()
->targetRoute('app_user_dashboard')
;
};
Limiting User Switching
-----------------------

Expand Down

0 comments on commit facbbb0

Please sign in to comment.