Reputation: 301
This is the security.yaml
:
security:
access_control:
- ...
- { path: ^/, roles: ROLE_USER }
- { path: ^/*, roles: ROLE_ADMIN }
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.
Allows every user (with role ROLE_USER
) to access any page (not mentioned in a previous access control) with a route like "/example"
/
is considered part of /*
in Symfony, and even though that explains the behavior. It still doesn't solve how to make the index page /
accessible by some users yet restrict access to pages like /example
./example
with - { path: ^/example, roles: ROLE_ADMIN }
, but that doesn't look clean since it may cause security vulnerabilities later on.Upvotes: 0
Views: 51
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