I do not have knowledge on Spring Impersonating user.
I have gone through some sample code of configuration for impersonating user and noticed that SwitchUserFilter is used for this implementation.
How to implement impersonate user using Spring SwitchUserFilter Filter and how does it works ? What is the internal flow of impersonating user ?
In my application I am using spring security also.
Can anyone please help me with simple description or any sample example to achieve this ?
You first need to create an instance of
SwitchUserFilter
, like this:Then, you can add the filter this way:
Now, to switch, you can use
and to switch back
Note that it’s your job to ensure that existing user must have enough rights for the switch. A common practice could be to restrict
/login/impersonate
only to ADMINs, and and/logout/impersonate
to authenticated users, like this:See this for a complete example.