Skip to content

[Security] Allow configuring a target url when switching user #17024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions security/impersonating_user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,67 @@ 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.

.. note::

It works only in a stateful firewall.

This feature allows you to control the redirection target route via ``target_route``.

.. 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