Sunday, July 19, 2015

Symfony granting path access to multiple roles in security.yml

Method 1:

# vim app/config/security.yml

# app/config/security.yml
security:
    access_control:
        - { path: ^/admin, roles: [ROLE_ADMIN, ROLE_TEACHER] }

Method 2:

Use the role hierarchy in security.yml

# vim app/config/security.yml

# app/config/security.yml
security:
    role_hierarchy:
        ROLE_ADMIN: [ROLE_TEACHER]

    access_control:
        - { path: ^/admin, roles: ROLE_TEACHER}

So all of this roles will have access to that path.

Reference:

http://stackoverflow.com/questions/19453299/symfony-granting-path-access-to-multiple-roles-in-security-yml

No comments: