拒绝访问 ROLE_ADMIN symfony
Deny access to ROLE_ADMIN symfony
我使用 Symfony 2.7 和 FOSUserBundle 2.0
我想要的是允许 ROLE_ADMIN
用户访问 /admin 但拒绝他的其他路径。
# app/security.yml
access_control:
- { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
- { path: ^/admin, roles: ROLE_SUPER_ADMIN }
role_hierarchy:
ROLE_USER: ROLE_USER
ROLE_ADMIN: ROLE_ADMIN
我考虑过 php app/console fos:user:demote admin ROLE_USER
,但 ROLE_USER
是 FOSUser 的默认角色,所以每次管理员连接时,除了 ROLE_ADMIN
之外,ROLE_USER
也会返回。
如何做到这一点?
在这种情况下,ROLE_ADMIN
无法访问 ROLE_MANAGER
access_control:
- { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/roles: ROLE_MANAGER }
- { path: ^/admin, roles: ROLE_ADMIN }
role_hierarchy:
ROLE_USER:
- ROLE_USER
ROLE_MANAGER:
- ROLE_USER
ROLE_ADMIN:
- ROLE_ADMIN
我使用 Symfony 2.7 和 FOSUserBundle 2.0
我想要的是允许 ROLE_ADMIN
用户访问 /admin 但拒绝他的其他路径。
# app/security.yml
access_control:
- { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_USER }
- { path: ^/admin, roles: ROLE_SUPER_ADMIN }
role_hierarchy:
ROLE_USER: ROLE_USER
ROLE_ADMIN: ROLE_ADMIN
我考虑过 php app/console fos:user:demote admin ROLE_USER
,但 ROLE_USER
是 FOSUser 的默认角色,所以每次管理员连接时,除了 ROLE_ADMIN
之外,ROLE_USER
也会返回。
如何做到这一点?
在这种情况下,ROLE_ADMIN
无法访问 ROLE_MANAGER
access_control:
- { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/roles: ROLE_MANAGER }
- { path: ^/admin, roles: ROLE_ADMIN }
role_hierarchy:
ROLE_USER:
- ROLE_USER
ROLE_MANAGER:
- ROLE_USER
ROLE_ADMIN:
- ROLE_ADMIN