拒绝访问ROLE_ADMIN symfony

时间:2015-09-12 10:32:38

标签: php security symfony yaml fosuserbundle

我使用Symfony 2.7和FOSUserBundle 2.0

我想要的是允许{/ 1}}用户访问/ admin,但拒绝其他路径。

ROLE_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是FOSUser的默认角色,因此每次管理员连接时,ROLE_USER都会在ROLE_USER之后返回。

怎么做呢?

PS:我现在只要主持人看到它就会被删除但是...... 在此先感谢:)!

1 个答案:

答案 0 :(得分:1)

在这种情况下,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