php Symfony 授予 security.yml 中多个角色的路径访问权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19453299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony granting path access to multiple roles in security.yml
提问by nmcilree
Hi I would like to be able to allow access to a path in security.yml
based on the user either having ROLE_TEACHER
, or ROLE_ADMIN
.
嗨,我希望能够允许访问security.yml
基于用户具有ROLE_TEACHER
, 或的路径ROLE_ADMIN
。
According to the question in Multiple roles required for same url in symfony 2the entry below should allow either role access.
根据symfony 2 中相同 url 所需的多个角色中的问题,下面的条目应该允许任一角色访问。
- { path: ^/admin, roles: ROLE_ADMIN}
- { path: ^/admin, roles: ROLE_TEACHER}
However, this will only allow the top role access. Is there a way of having multiple role access to a single path?
但是,这将只允许顶级角色访问。有没有办法让多个角色访问单个路径?
回答by Udan
This is the way to go and what i'm using:
这是要走的路和我正在使用的内容:
- { path: ^/admin, roles: [ROLE_ADMIN, ROLE_TEACHER] }
回答by Serge Kvashnin
You can use the role hierarchy in security.yml
:
您可以在security.yml
以下位置使用角色层次结构:
role_hierarchy:
ROLE_ADMIN: [ROLE_TEACHER]
#...
access_control:
- { path: ^/admin, roles: ROLE_TEACHER}
So all of this roles will have access to that path.
因此,所有这些角色都可以访问该路径。