user_impersonation.rst 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. .. index::
  2. single: User Impersonation
  3. User Impersonation
  4. ==================
  5. To enable the user impersonation links you must first enable the impersonation feature in your
  6. firewall. Once you have enabled the feature, you will need to ensure that the user that you wish
  7. to role switch from has the ``ROLE_ALLOWED_TO_SWITCH`` role.
  8. .. code-block:: yaml
  9. role_hierarchy:
  10. ...
  11. ROLE_SUPER_ADMIN: [ROLE_SONATA_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  12. firewalls:
  13. main:
  14. ...
  15. admin:
  16. ...
  17. switch_user: true
  18. Please note that sessions are not shared by default over different firewalls (for example, if you
  19. are trying to switch to a user who is authenticated on another firewall, such as ``main`` given in
  20. the example above). To enable this feature please refer to the
  21. `Symfony Documentation <http://symfony.com/doc/current/reference/configuration/security.html#reference-security-firewall-context>`_.
  22. Then is it simply a case of providing the route name to redirect to once the user has been impersonated
  23. in the ``SonataUserBundle`` configuration:
  24. .. code-block:: yaml
  25. sonata_user:
  26. ...
  27. impersonating:
  28. route: sonata_admin_dashboard
  29. Here we have used the admin dashboard route, but you can supply any named route in your application.