I want to be able to impersonate a user in my app, so I followed the tutorial from the website
If I try to change my user from user "A" to user "B", it works, but if I try to change to user "C" while I'm already impersonating user "B", the attemptSwitchUser method throws this excepcion:
You are already switched to "B" user.
500 Internal Server Error - LogicException
This is because this method checks wether the current user name (B) equals the user name we want to impersonate (C)
$token = $this->securityContext->getToken();
$originalToken = $this->getOriginalToken($token);
if (false !== $originalToken) {
if ($token->getUsername() === $request->get($this->usernameParameter)) {
return $token;
} else {
throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
}
}
But obviously this can't never be the case, so I don't know if this is a bug in Symfony's code or if there's something else I'm missing.
Is this really a bug? Can I achieve this functionality without commenting out this block of code?
Switched user cannot switch to other. Before you can do that you need to switch back to the original user ( ?_switch_user=_exit )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With