简体   繁体   中英

Symfony 2, return true for bad roles

role_hierarchy:
        ROLE_USER: [ROLE_CLIENT, ROLE_CHAT]
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

My view returns:

array:2 [▼
  0 => Role {#333 ▼
    -role: "ROLE_CHAT"
  }
  1 => Role {#334 ▼
    -role: "ROLE_USER"
  }
]
You  cant't see this.

My view:

{% block content %}
    <h1>Client panel</h1>
    {{ dump(app.security.token.roles) }}


{% if is_granted('ROLE_CLIENT') %} You can't see this. {% endif %}


{% endblock %}

I don't know why is granted return true for ROLE_CLIENT, if the user has not this role. He has only ROLE_USER, AND ROLE_CHAT.

Thanks for help.

In your Roles' hierarchy you can see that ROLE_USER is already have roles ROLE_CLIENT and ROLE_CHAT . This is the expected behaviour.

If you want it to return false just change your role_hierarchy block in security.yml .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM