当我已经在模拟另一个用户时模拟一个用户? [英] Impersonate a user when I'm already impersonating another user?
问题描述
我希望能够在我的应用程序中模拟用户,所以我遵循了 来自网站的教程
I want to be able to impersonate a user in my app, so I followed the tutorial from the website
如果我尝试将我的用户从用户A"更改为用户B",它可以工作,但是如果我尝试更改为用户C"而我已经在模拟用户B",尝试SwitchUser
方法抛出这个异常:
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
这是因为此方法检查当前用户名 (B) 是否等于我们要模拟的用户名 (C)
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()));
}
}
但显然不可能永远如此,所以我不知道这是 Symfony 代码中的错误还是我遗漏了其他东西.
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?
推荐答案
切换用户无法切换到其他用户.在此之前,您需要切换回原始用户 ( ?_switch_user=_exit
)
Switched user cannot switch to other. Before you can do that you need to switch back to the original user ( ?_switch_user=_exit
)
这篇关于当我已经在模拟另一个用户时模拟一个用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!