There is no user provider for user "Symfony\Component\Security\Core\User\User"

10,839

Solution 1

Had the same problem. It seems that this works. I will only use it in the development process later on i will find a solution.!

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


    providers:
        chain_provider:
            providers: [in_memory, user_db]
        in_memory:
            users:
                cheese: { password: olo, roles: ROLE_ADMIN }
        user_db:
            entity: { class: Abc\BaseBundle\Entity\User, property: username }


    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        Abc\BaseBundle\Entity\User: plaintext

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

        panel:
            pattern:    ^/(panel|login_check)
            anonymous: ~
            form_login:
                login_path:  /login
                check_path:  /login_check
                default_target_path: /panel/
            logout:
                path:   /logout
                target: /

Solution 2

I had this problem once.

It was because I was logged with a user from the previous provider (in_memory). Had to restore the in_memory part, logout and then put the new provider.

My guess:

The info of the user was in the session and it couldn't acces it since we took it off the security.yml

Share:
10,839
Tony Bogdanov
Author by

Tony Bogdanov

Updated on June 04, 2022

Comments

  • Tony Bogdanov
    Tony Bogdanov almost 2 years

    After struggling all day with a simple taks for Symfony 2 with no luck, I decided to ask you guys for a solution.

    Here is the problem: I would like to make a http_basic authentication using doctrine, so users would be prompted to enter username/password which are kept in a database.

    So, I followed these steps:

    1) Created a new entity called User with the interactive console generator.

    This is how it looks like:

    http://pastebin.com/3RzrwFzL

    2) As stated in the documentation I have implemented UserInterface and added the 4 missing methods. Now the entity looks like this:

    http://pastebin.com/Epw3YrwR

    3) I have modified the security.yml as little as possible to make it work, and it looks like this:

    http://pastebin.com/tp6Gd7t7

    I cleared the cache and tried to access app_dev.php/admin and of course I get the same error all day:

    There is no user provider for user "Symfony\Component\Security\Core\User\User".

    500 Internal Server Error - RuntimeException

    Can anyone tell me where is the problem? I have tried this thousand different ways and weirdly it worked for a moment, but when I tried to add sha1 as encoder algorithm instead of plaintext, and cleared the cache, I came back to the same error.. since then I get nothing else but it. It is like if there is a hidden cache that is being erased whenever symfony decides :D

    I think the error might also be in the 4 methods of the entity, but I cannot fix them since there is no documentation about what should they do.

    I am currently using RC4.

    Thanks in advance, hope someone will help.

  • Giovanni Toraldo
    Giovanni Toraldo over 11 years
    Good gotcha, always clean cache.
  • David
    David over 11 years
    To be fair the did great work with FOSUserBundle but it may cause you other headache if you prefer either a slim or highly customizable solution.
  • ReynierPM
    ReynierPM almost 9 years
    What about if cache is clean and error still? I am running the same issue after try to get this working, any advice? I am stuck