semsem semsem - 1 year ago 205
PHP Question

symfony2 access control restrict ROLE_SUPER_ADMIN

I want to restrict some routes from being accessed by all roles (SUPER_ADMIN, ADMIN included) except for (ROLE_CUSTOM)

Where ROLE_CUSTOM is a custom role created for specified route.

The only role can access this route is (ROLE_CUSTOM)

I want to control this from security.access_control.yml or from firewall configuration.

I know i can use is_granted function but i want to control it from security.access_control.yml or from firewall configuration.

How can i achieve this?

Answer Source

Roles are simple, and are basically strings that you invent and use as needed, so ROLE_SUPER_ADMIN and ROLE_ADMIN are already custom roles created by you. Then everything depends on your role hierarchy (Reference):

        ROLE_ADMIN:       ROLE_USER

To allow you to protect URL patterns for users with ROLE_CUSTOM just do the following (Reference):

        - { path: ^/exclusive-path$, role: ROLE_CUSTOM }

Ready! only users with ROLE_CUSTOM can access to /exclusive-path paths.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download