简体   繁体   中英

Symfony2 and anonymous firewall

I have a site running with Symfony2 which requires a login. There's a firewall set like that :

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    admin:
        pattern:    ^/
        entry_point: security_user.authentication.entry_point
        ntlm: ~
        fr3d_ldap:  ~
        form_login:
            check_path: /login_check
            login_path: /login
            #always_use_default_target_path: true
            use_referer: true
            success_handler: security_user.login.success_handler
            default_target_path: /
        logout:
            path:   /logout
            target: /
            success_handler: security_user.logout.handler
            invalidate_session: true
        anonymous:  ~

I'd like to open access to specific pages without login. I tried adding that firewal :

    my_firewall:
        context: my_context
        pattern: ^/url-to-open.*$
        anonymous: true

But I still get redirected to the login page. What am I missing ? Thanks

You don't need a new firewall but to set access_control. In the following exemple all routes wich path contains "/some_path" expression can be reach by unauthenticated users. You should have to Symfony doc about Security and How access_controll works

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    admin:
        pattern:    ^/
        entry_point: security_user.authentication.entry_point
        ntlm: ~
        fr3d_ldap:  ~
        form_login:
            check_path: /login_check
            login_path: /login
            #always_use_default_target_path: true
            use_referer: true
            success_handler: security_user.login.success_handler
            default_target_path: /
        logout:
            path:   /logout
            target: /
            success_handler: security_user.logout.handler
            invalidate_session: true
        anonymous:  ~

access_control:
        - { path: /some_path, role: IS_AUTHENTICATED_ANONYMOUSLY }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM