Login user using memory provider in Symfony

ziiweb picture ziiweb · Oct 27, 2011 · Viewed 9.9k times · Source

after installing FOSUserBundle, now Im trying to login with user/ userpass but I still get the "Bad credentials" message. This is my security.yml:

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        in_memory:
            users:
                user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
        fos_userbundle:
            id: fos_user.user_manager

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
            logout:       true
            anonymous:    true
            #anonymous: ~
            #http_basic:
            #    realm: "Secured Demo Area"

Any idea?

symfony 2.0.4

Answer

Steven Rosato picture Steven Rosato · Oct 30, 2011

Chain your providers like this:

providers:
    chain_provider:
        providers: [in_memory, fos_userbundle]
    in_memory:
        users:
            user:  { password: userpass, roles: [ 'ROLE_USER' ] }
            admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

    fos_userbundle:
        id: fos_user.user_manager

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: chain_provider
            logout:       true
            anonymous:    true
            switch_user:  true
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false