Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default_target_path does not work with FOSUserBundle

I have installed FOSUserBundle and I am using it in my project. Its login page redirects to an unknown path /_wdt/50366043f414d. I changed the default_target_path under form_login in security.yml file, but it did not take effect.

How can I change the target path of the login page in FOSUserBundle?

like image 800
Dariush Jafari Avatar asked Aug 23 '12 17:08

Dariush Jafari


3 Answers

I must set the always_use_default_target_path to true, as shown in symfony documentation

#app/config/security.yml  

firewalls:
    main:
        pattern: ^/
        form_login:
            login_path: /login
            default_target_path: /my/desired/path
            always_use_default_target_path: true
like image 119
Dariush Jafari Avatar answered Sep 20 '22 17:09

Dariush Jafari


I had the same issue, and the reason I was having this problem was because Symfony was trying to load the Web Debug Toolbar (hence the "_wdt" bit in the error), which has its own routes that are called at the end of the page load. In my case, I had configured my security.yml like so:

app/config/security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/css, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/js, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, role: ROLE_USER }

This means that if the user is trying to open a page for anything behind the root "/", he is required to be logged in.

The way I fixed the problem was by adding the "_wdt" part and allowing it for anonymous users:

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/css, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/js, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, role: ROLE_USER }
like image 28
maurits Avatar answered Sep 18 '22 17:09

maurits


This may be an old issue but instead of changing the access_control the current Symfony2 config features an extra firewall for the debug toolbar:

    # Disabling the security for the web debug toolbar, the profiler and Assetic.
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
like image 24
webDEVILopers Avatar answered Sep 18 '22 17:09

webDEVILopers