문제

I'm using FosUserBundle for my Symfony2 project. I've added a rule for the custom ROLE_VALIDE to restrict the paths like /user. It works for the users having this role.

The problem is that I also want the admins to be able to access this path. I've tested with both roles ROLE_ADMIN and ROLE_ADMIN + ROLE_VALIDE but I have the 403 error page.

Is there a way to add more than one role in the access_control ?

access_control:
    - { path: ^/admin, role: ROLE_ADMIN }
    - { path: ^/user, role: ROLE_VALIDE }
도움이 되었습니까?

해결책

What about role hierarchy in your security.yml ?

doc : http://symfony.com/doc/current/book/security.html#hierarchical-roles

role_hierarchy:
    ROLE_USER:        [ROLE_USER]
    ROLE_VALIDE:      [ROLE_USER, ROLE_VALIDE]
    ROLE_ADMIN:       [ROLE_USER, ROLE_VALIDE, ROLE_ADMIN]

With this, if route is waiting for ROLE_VALIDE, ROLE_ADMIN is ok because is has ROLE_VALIDE inside it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top