0
votes

My website is running with Symfony 3.4 and I just install the FOSUserBundle to manage login/authentification. I followed this tutorial but all isn't working perfectly. For the record I can access my homepage view (/app_dev.php/) and my login page view (/app_dev.php/login) but in my security.yml :

  • In the "main" firewall if "anonymous" is set to "true" : everybody can access all the pages.

  • In the "main" firewall if "anonymous" is set to "false" :

enter image description here

I don't figure out why this path is making a infinite loop. Below is my security yaml config :

security:

    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    providers:
        fos_userbundle:
                id: fos_user.user_provider.username

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager

            logout:       true
            anonymous:    false

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

And in my dev.log, these lines are looped :

[2018-01-15 10:54:24] request.INFO: Matched route "fos_user_security_login". {"route":"fos_user_security_login","route_parameters":{"_controller":"FOS\UserBundle\Controller\SecurityController::loginAction","_route":"fos_user_security_login"},"request_uri":"http://www.mycompany.com/app_dev.php/login","method":"GET"} [] [2018-01-15 10:54:24] security.INFO: An AuthenticationException was thrown; redirecting to authentication entry point. {"exception":"[object] (Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): A Token was not found in the TokenStorage. at /var/www/custom_pim/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php:51)"} [] [2018-01-15 10:54:24] security.DEBUG: Calling Authentication entry point. [] []

3

3 Answers

2
votes

You have to change anonymous:

anonymous: true
2
votes

I solved my problem with the following code :

firewalls:

main:
    pattern: ^/
    form_login:
        provider: fos_userbundle
        default_target_path: /
        csrf_token_generator: security.csrf.token_manager
    logout:
        target: fos_user_security_login
    anonymous:    true

access_control:

- { path: ^/$, role: ROLE_USER }
0
votes

I have checked my settings with yours, and the only thing you have different is

anonymous: false

which I have set to true (which is the default I think). Maybe try changing that and report back, I have a pretty fresh FOSUserBundle project on my hand to check