Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 and anonymous access to some route

Tags:

php

symfony

With this configuration:

firewalls:
    login:
        pattern:  ^/login$
        anonymous:  ~
        security: false

    foo:
        pattern:   ^/foo$
        anonymous: ~
        security: false

    secured_area:
        pattern:    ^/
        form_login:
            login_path: /login
            check_path: /login_check
        logout:
            path:   /logout
            target: /

access_control:
    - { path: ^/, roles: ROLE_ADMIN }
    - { path: ^/foo, roles: IS_AUTHENTICATED_ANONYMOUSLY }

I want to be able to make /foo anonymously accessible. However, when I try to go there even after clearing the cache it won't allow me to and redirects to login screen.

How do I make one route to be anonymously accessible while retaining the rest of the system to be secured?

like image 207
Tower Avatar asked Feb 27 '12 08:02

Tower


Video Answer


1 Answers

Replace

- { path: ^/foo, roles: IS_ANONYMOUS }

with

- { path: ^/foo, roles: IS_AUTHENTICATED_ANONYMOUSLY }

UPDATE

Also, I believe, you will have to add

- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

for authentication to work properly.

For more info check out Avoid Common Pitfalls section here.

like image 194
Molecular Man Avatar answered Sep 17 '22 16:09

Molecular Man