Skip to content

Commit 42ec547

Browse files
committed
[Security] add description and example for the special ROLE_PREVIOUS_ADMIN role
1 parent 9a0b4e1 commit 42ec547

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

book/security.rst

+18
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,24 @@ To switch back to the original user, use the special ``_exit`` username:
16441644
16451645
http://example.com/somewhere?_switch_user=_exit
16461646
1647+
During impersonation the user is provided with a special role called
1648+
``ROLE_PREVIOUS_ADMIN``. In a template, for instance, this role can decide
1649+
if a link to exit impersonation needs to be shown:
1650+
1651+
.. configuration-block::
1652+
1653+
.. code-block:: html+jinja
1654+
1655+
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
1656+
<a href="{{ path('homepage', {_switch_user: '_exit'}) }}">Exit impersonation</a>
1657+
{% endif %}
1658+
1659+
.. code-block:: html+php
1660+
1661+
<?php if ($view['security']->isGranted('ROLE_PREVIOUS_ADMIN')): ?>
1662+
<a href="<?php echo $view['router']->generate('homepage', array('_switch_user' => '_exit') ?>">Exit impersonation</a>
1663+
<?php endif; ?>
1664+
16471665
Of course, this feature needs to be made available to a small group of users.
16481666
By default, access is restricted to users having the ``ROLE_ALLOWED_TO_SWITCH``
16491667
role. The name of this role can be modified via the ``role`` setting. For

0 commit comments

Comments
 (0)