Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 650
Tony Bogdanov Avatar asked Jul 05 '11 19:07

Tony Bogdanov


2 Answers

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

like image 184
Ascander Avatar answered Sep 19 '22 21:09

Ascander


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: /
like image 42
Tor Avatar answered Sep 22 '22 21:09

Tor