简体   繁体   中英

Loop Redirect after login Symfony2

I'm trying to create a login form in symfony2

When enter correct information, the redirect enter in loop and a message: "No data received" or "Connect Reset" is showed. if i enter with wrong information, the message: Bad Credencial is showed.

My security.yml

Segue o security.yml que criei

 dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login_firewall:
        pattern:  ^/login$
        anonymous: ~

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

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

The user IS ROLE_USER in $user->getRoles()

Thanks!

Sorry by my English!

In cookbook http://symfony.com/doc/current/cookbook/security/form_login_setup.html firewall containing login form and check path (which is the same in example) are defined in firewall which can be accessed by anonymous users.

In your config only /login is accessible (line: pattern: ^/login$).

尝试将anonymous: ~更改为security: false login_firewall部分中的 security: false

Your login and login_check routes should be under the firewall you are using. In other words, you have to remove/comment those 3 lines:

    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    #login_firewall:
    #    pattern:  ^/login$
    #    anonymous: ~

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

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

This line - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - is enough for users being able to use login form without having a redirection loop.

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