当用户冒充另一个用户时,我正在尝试进行重定向。
为此,我注册了一项服务:
ACME_listener.security_switch_user:
class: ACME\CustomerLoginBundle\Listener\SecuritySwitchUserListener
arguments: [@service_container, @router, @security.context]
tags:
- { name: kernel.event_listener, event: security.switch_user, method: onSecuritySwitchUser }
我的侦听器类如下所示:
namespace ACME\CustomerLoginBundle\Listener;
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
class SecuritySwitchUserListener implements ListenerInterface {
public function __construct($appContainer, $router) {
$this->router = $router;
$this->appContainer = $appContainer;
}
public function onSecuritySwitchUser(SwitchUserEvent $event) {
echo "im in here!";
// this does get called
}
public function handle(GetResponseEvent $event) {
echo "but not here :(";
// this does not get called!
}
}
现在的问题是我无法从onSecuritySwitchUser
方法中重定向用户。返回 aRedirectResponse
不起作用,并且 theSwitchUserEvent
没有setResponse()
方法。
我该怎么做handle()
才能调用该方法?