ユーザーが別のユーザーになりすますときにリダイレクトを実行しようとしています。
このために、サービスを登録しました:
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
メソッド内からユーザーをリダイレクトできないことです。を返すことRedirectResponse
は機能せず、 にはメソッドSwitchUserEvent
がありませんsetResponse()
。
handle()
メソッドが呼び出されるようにするにはどうすればよいですか?