@@ -51,8 +51,9 @@ class SwitchUserListener extends AbstractListener
51
51
private ?LoggerInterface $ logger ;
52
52
private ?EventDispatcherInterface $ dispatcher ;
53
53
private bool $ stateless ;
54
+ private ?string $ targetUrl ;
54
55
55
- public function __construct (TokenStorageInterface $ tokenStorage , UserProviderInterface $ provider , UserCheckerInterface $ userChecker , string $ firewallName , AccessDecisionManagerInterface $ accessDecisionManager , LoggerInterface $ logger = null , string $ usernameParameter = '_switch_user ' , string $ role = 'ROLE_ALLOWED_TO_SWITCH ' , EventDispatcherInterface $ dispatcher = null , bool $ stateless = false )
56
+ public function __construct (TokenStorageInterface $ tokenStorage , UserProviderInterface $ provider , UserCheckerInterface $ userChecker , string $ firewallName , AccessDecisionManagerInterface $ accessDecisionManager , LoggerInterface $ logger = null , string $ usernameParameter = '_switch_user ' , string $ role = 'ROLE_ALLOWED_TO_SWITCH ' , EventDispatcherInterface $ dispatcher = null , bool $ stateless = false , ? string $ targetUrl = null )
56
57
{
57
58
if ('' === $ firewallName ) {
58
59
throw new \InvalidArgumentException ('$firewallName must not be empty. ' );
@@ -68,6 +69,7 @@ public function __construct(TokenStorageInterface $tokenStorage, UserProviderInt
68
69
$ this ->logger = $ logger ;
69
70
$ this ->dispatcher = $ dispatcher ;
70
71
$ this ->stateless = $ stateless ;
72
+ $ this ->targetUrl = $ targetUrl ;
71
73
}
72
74
73
75
/**
@@ -122,7 +124,7 @@ public function authenticate(RequestEvent $event)
122
124
if (!$ this ->stateless ) {
123
125
$ request ->query ->remove ($ this ->usernameParameter );
124
126
$ request ->server ->set ('QUERY_STRING ' , http_build_query ($ request ->query ->all (), '' , '& ' ));
125
- $ response = new RedirectResponse ($ request ->getUri (), 302 );
127
+ $ response = new RedirectResponse ($ this -> targetUrl ?? $ request ->getUri (), 302 );
126
128
127
129
$ event ->setResponse ($ response );
128
130
}
0 commit comments