EXPLANATION
Allowing user to switch to any other user is easy in Symfony2. My question is, how to allow certain user to switch only to certain other users? I’m using FOSUserBundle as my users provider.
EXAMPLE
There is 5 users, UserA, UserB, UserC, UserD, UserE, but only 3 of them are linked together.
UserA can switch to UserB and UserC
UserB can switch to UserA and UserC
UserC can switch to UserA and UserB
Thanks for your help!
You could possibly implement this type of thing by overriding the default SwitchUserListener.
The parameter you would override is:
security.authentication.switchuser_listener.class
For example, in parameters.yml:
Where, in your custom listener class, you’d implement
Symfony\Component\Security\Http\Firewall\ListenerInterfaceand use the existingSymfony\Component\Security\Http\Firewall\SwitchUserListenerclass as a basis for your custom implementation.