I searched everywhere but it seems impossible thing to do.
I was able to catch SwitchEvent
coming from SwitchEventListener
and get both impersonator and target user objects (one being impersonated as) but I would really like, based on target user roles to redirect request to some other URL.
Example:
I have two restricted areas: "/basic" and "/elevated" where first one requires ROLE_BASIC
and the other one ROLE_ELEVATED
role. Now, if I am currently logged in as ROLE_ELEVATED
user and want to switch to some ROLE_BASIC
user using URL:
/basic/?_switch_user=some_basic_user
that would result in AccessDeniedException, and I'm forced to navigate first to:
/?_switch_user=some_basic_user.
Only after that I can navigate to /basic as token has been written to session.
Now, the question, as subject suggests: Is there any way to redirect user using SwitchEvent
(or any other) after doing user switching?