Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use regex in symfony2 access control?

Tags:

php

symfony

Can we use regex in access control in symfony2 security?

1) /foo/{id} -- [ROLE_ADMIN]
2) /foo/{id}/profile --  [IS_AUTHENTICATED_ANONYMOUSLY]

Another issue:

If I removed the access_control from my security, still it goes to the Security module and try to Authenticate from Security/Authentication/Provider/AuthProvide.

What should be the ideal behavior? I think it should not authenticate the resource if no access_control is in security.yml.

My firewall configuration is:

 firewalls:
    main:
            pattern: ^/
            anonymous: true
            myapp: true
like image 566
Tauquir Avatar asked Oct 12 '12 22:10

Tauquir


1 Answers

Yes, you can use regex.

But /foo/{id}/profile won't match what you want. As id is probably an integer, you'll have to use instead:

^/foo/[0-9]+/profile$

or

^/foo/[^/]+/profile$
like image 106
AdrienBrault Avatar answered Oct 31 '22 12:10

AdrienBrault