Allow anonymous access to specific URL in Symfony firewall protected bundle

不想你离开。 提交于 2019-12-21 11:54:10

问题


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 ?


回答1:


# 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



来源:https://stackoverflow.com/questions/22406764/allow-anonymous-access-to-specific-url-in-symfony-firewall-protected-bundle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!