I'm following the Symfony docs and using the following twig helper function to determine if a user is switching roles for impersonation. The problem is, it always returns true for ROLE_ADMIN.
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
<a href="{{ path('homepage', {'_switch_user': '_exit'}) }}">Exit impersonation</a>
{% endif %}
Oddly enough, when I inspect the security token via the debug toolbar for admins, I see the following roles:
[ROLE_ADMIN, ROLE_SHAWMUT, ROLE_USER]
And the following inherited:
[ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
So why does is_granted('ROLE_PREVIOUS_ADMIN') return true if the above are the roles available to this security token?
=====
This is what I have to do to get this to work, which involves using the depreciated app.security.token variable:
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
{% for role in app.security.token.roles %}
{% if role.role == 'ROLE_PREVIOUS_ADMIN' %}
<span class="imp-designation">{impersonating}</span>
{% endif %}
{% endfor %}
{% endif %}
=====
Here is my security.yml file: http://pastebin.com/f04ZG4K8