Symfony2和匿名访问某些路由

时间:2022-10-16 15:03:35

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.

我希望能够匿名访问/ foo。但是,当我尝试去清除缓存后,它将不允许我重定向到登录屏幕。

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

如何在保留系统的其余部分以保护安全的同时,使一条路由匿名访问?

1 个解决方案

#1


13  

Replace

更换

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

with

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

UPDATE

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.

有关更多信息,请查看此处的“避免常见陷阱”部分。

#1


13  

Replace

更换

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

with

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

UPDATE

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.

有关更多信息,请查看此处的“避免常见陷阱”部分。