1
votes

I've problem with my hierarchical role in security.yml

role_hierarchy

    ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    ROLE_ADMIN: [ROLE_PILOT, ROLE_EXPERT]
    ROLE_PILOT: ROLE_PRODIVER
    ROLE_PROVIDER: ROLE_PROVIDER_EXTERNAL
    ROLE_PROVIDER_EXTERNAL: ROLE_USER

When i'm using *is_granted* in TWIG :

{% if is_granted('ROLE_PROVIDER_EXTERNAL') %}
 <li class="dropdown">[...]</li>
{% endif %}

Normally the ROLE_PILOT should be able to view this HTML element with the inheritance of roles. But if user is connected in ROLE_PILOT, HTML element cannot display for him...

Anyone have an idea for my problem ?
Thx

1
I think the rules must be written top to bottom, so that the weakest rule is on the top, not at the bottom. - Flask
I tried, however, no change. The PILOT is inherited rights PROVIDER with my hierarchy no ?! - RudySkate
what does var_dump($this->getContainer()->getParameter('security.role_hierarchy.roles')) (in a controller) returns? - Flask
I've the same hierarchy but in Php instead of Yaml. Array of 5 Roles : (...Simplified array...) ROLE_PROVIDER_EXTERNAL => ["ROLE_USER"] ROLE_PROVIDER => ["ROLE_PROVIDER_EXTERNAL"] ROLE_PILOT =>["ROLE_PRODIVER"] ROLE_ADMIN => ["ROLE_PILOT", "ROLE_EXPERT"] ROLE_SUPER_ADMIN ["ROLE_ADMIN", "ROLE_ALLOWED_TO_SWITCH"] - RudySkate

1 Answers

2
votes

Your code shows:

ROLE_PILOT: ROLE_PRODIVER

Try changing it to:

ROLE_PILOT: ROLE_PROVIDER