Skip to content

Commit 1a08823

Browse files
94nonichalasr
authored andcommitted
[Security] Allow configuring a redirect url via route name when switching user
1 parent 1b76bae commit 1a08823

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Add `Security::logout()` to logout programmatically
1212
* Add `security.firewalls.logout.enable_csrf` to enable CSRF protection using the default CSRF token generator
1313
* Add RFC6750 Access Token support to allow token-based authentication
14+
* Add `security.firewalls.switch_user.target_route` option to configure redirect target route on switch user
1415

1516
6.1
1617
---

DependencyInjection/MainConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
257257
->scalarNode('provider')->end()
258258
->scalarNode('parameter')->defaultValue('_switch_user')->end()
259259
->scalarNode('role')->defaultValue('ROLE_ALLOWED_TO_SWITCH')->end()
260-
->scalarNode('target_url')->defaultValue(null)->end()
260+
->scalarNode('target_route')->defaultValue(null)->end()
261261
->end()
262262
->end()
263263
->arrayNode('required_badges')

DependencyInjection/SecurityExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ private function createSwitchUserListener(ContainerBuilder $container, string $i
845845
if (!$userProvider) {
846846
throw new InvalidConfigurationException(sprintf('Not configuring explicitly the provider for the "switch_user" listener on "%s" firewall is ambiguous as there is more than one registered provider.', $id));
847847
}
848-
if ($stateless && null !== $config['target_url']) {
849-
throw new InvalidConfigurationException(sprintf('Cannot set a "target_url" for the "switch_user" listener on the "%s" firewall as it is stateless.', $id));
848+
if ($stateless && null !== $config['target_route']) {
849+
throw new InvalidConfigurationException(sprintf('Cannot set a "target_route" for the "switch_user" listener on the "%s" firewall as it is stateless.', $id));
850850
}
851851

852852
$switchUserListenerId = 'security.authentication.switchuser_listener.'.$id;
@@ -857,7 +857,7 @@ private function createSwitchUserListener(ContainerBuilder $container, string $i
857857
$listener->replaceArgument(6, $config['parameter']);
858858
$listener->replaceArgument(7, $config['role']);
859859
$listener->replaceArgument(9, $stateless);
860-
$listener->replaceArgument(10, $config['target_url']);
860+
$listener->replaceArgument(11, $config['target_route']);
861861

862862
return $switchUserListenerId;
863863
}

Resources/config/security_listeners.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@
151151
'ROLE_ALLOWED_TO_SWITCH',
152152
service('event_dispatcher')->nullOnInvalid(),
153153
false, // Stateless
154-
abstract_arg('Target Url'),
154+
service('router')->nullOnInvalid(),
155+
abstract_arg('Target Route'),
155156
])
156157
->tag('monolog.logger', ['channel' => 'security'])
157158

Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testFirewalls()
165165
[
166166
'parameter' => '_switch_user',
167167
'role' => 'ROLE_ALLOWED_TO_SWITCH',
168-
'target_url' => null,
168+
'target_route' => null,
169169
],
170170
[
171171
'csrf_parameter' => '_csrf_token',

0 commit comments

Comments
 (0)