-1

I want :

/p/{name} ==> in public access
/profile ==> in loggin access

I did this in security.yml

access_control:
    - { path: ^/[p]/* , role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/*, role: ROLE_CONNECT }

But, when I browse :

/profile => accessible in public ==> K.O.
/p/name-here => accessible in public ==> OK

Arleigh Hix
  • 9,990
  • 1
  • 14
  • 31
Greg
  • 826
  • 5
  • 21
  • 1
    Please format your question. "**K.O.**" is not an error message for us. Add your routing, your complete `security.yml`, and the error message you get when you go to `/profile`. If you could also add a tag that match your symfony version, that would be perfect. – Preciel Jun 05 '19 at 18:12
  • /profile is accessible in public so it KO (not good) because I want this route only when user is logged – Greg Jun 05 '19 at 19:21
  • It seemed to be pretty clear to me, and I think composer uses OK for success and KO as an error (KO is not OK). Besides, the problem is clearly stated immediately before that. – Arleigh Hix Jun 06 '19 at 05:19

1 Answers1

2

I'm pretty sure that ^/[p]/* is going to match any path that starts with /p, and you have it as the first rule, so it matches first and allows access.

The square brackets [] are defining a set of characters to match, you only want to match one so you don't need them. The * says to match zero or more / characters at the end, you know there will be one / after p so omit the star. The path is a prefix so you don't need to worry about the variable part of the path.

Try this:

- { path: ^/p/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/profile, role: ROLE_CONNECT }
Arleigh Hix
  • 9,990
  • 1
  • 14
  • 31