Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow anonymous access to specific URL in Symfony firewall protected bundle

I have a Symfony bundle which can only be accessible by using mydomain.com/box

To access /box you must be logged in, however i would like to enable anonymous access into mydomain.com/box/download

# Security.yml
access_control:
    - { path: ^/box , roles: ROLE_USER}

How can i do ?

like image 394
Fabien Papet Avatar asked Mar 14 '14 13:03

Fabien Papet


1 Answers

# security.yml
access_control:
    - { path: ^/box/download , roles: IS_AUTHENTICATED_ANONYMOUSLY}
    - { path: ^/box , roles: ROLE_USER}

Symfony2 firewalls are processed in order, and only first matching one will be applied. Therefore, if you put the /box/download before /box, the /box/download rule will be processed and the rest will be ignored.

http://symfony.com/doc/current/book/security.html

like image 146
Michael Yoo Avatar answered Sep 19 '22 08:09

Michael Yoo