Rax
Rax

Reputation: 11

FOSUserBundle InvalidConfigurationException after basic configuration through symfony cookbook

I configured the FOSUserBundle for my symfony bundle (following the cookbook http://symfony.com/doc/1.3.x/bundles/FOSUserBundle/index.html). When I try to access the login page I get this error:

You are not allowed to define new elements for path "security.firewalls". Please define all elements for this path in one config file.

my seurity.yml file is:

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

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: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
        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: ^/admin/, role: ROLE_ADMIN }

I can't understand what's the problem, any suggestion? Thanks in advance

Upvotes: 1

Views: 608

Answers (1)

NoX
NoX

Reputation: 573

the first problem I see is an indentation problem in your yaml security file :

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

    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: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
            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: ^/admin/, role: ROLE_ADMIN }

Check carefully documentation available at https://symfony.com/doc/master/bundles/FOSUserBundle/index.html, check routes, clear cache and you're normally done ;)

Feel free to come back here if any other problems is encountered.

Best Regards.

Upvotes: 0

Related Questions