Omar Trkzi
Omar Trkzi

Reputation: 301

Allow different roles to access the index page

This is the security.yaml :

security:
  access_control:
    - ...
    - { path: ^/, roles: ROLE_USER }
    - { path: ^/*, roles: ROLE_ADMIN }

Expected behavior:

Allowing every user (isGranted('ROLE_USER') upon creation) to access the index page routed in @Route("/","index"), and denying them from accessing any page (not mentioned in a previous access control) with a route like "/example", unless they have the ROLE_ADMIN role.

Actual behavior:

Allows every user (with role ROLE_USER) to access any page (not mentioned in a previous access control) with a route like "/example"

Notes

Upvotes: 0

Views: 51

Answers (1)

Omar Trkzi
Omar Trkzi

Reputation: 301

As @A.L said in his comment, this worked for me:

security:
  access_control:
    - ...
    - { path: ^/$, roles: ROLE_USER }
    - { path: ^/*, roles: ROLE_ADMIN }

However, if you think there is a better way to achieve the same result, your answer would be appreciated.

Upvotes: 1

Related Questions