[英]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. 我不知道如果用户没有此角色,为什么授予ROLE_CLIENT的返回值为true。 He has only ROLE_USER, AND ROLE_CHAT.
他只有ROLE_USER和ROLE_CHAT。
Thanks for help. 感谢帮助。
In your Roles' hierarchy you can see that ROLE_USER
is already have roles ROLE_CLIENT
and ROLE_CHAT
. 在您的角色层次结构中,您可以看到
ROLE_USER
已经具有角色ROLE_CLIENT
和ROLE_CHAT
。 This is the expected behaviour. 这是预期的行为。
If you want it to return false just change your role_hierarchy
block in security.yml
. 如果希望它返回false,只需在
security.yml
更改role_hierarchy
块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.