没有用户“Symfony\Component\Security\Core\User\User”的用户提供程序

发布于 2024-11-18 20:38:14 字数 988 浏览 1 评论 0原文

在 Symfony 2 的简单任务上挣扎了一整天但没有成功后,我决定向你们寻求解决方案。

问题是:我想使用学说进行 http_basic 身份验证,因此系统会提示用户输入保存在数据库中的用户名/密码。

因此,我按照以下步骤操作:

1)使用交互式控制台生成器创建了一个名为 User 的新实体。

它看起来像这样:

http://pastebin.com/3RzrwFzL

2)如文档中所述,我已经实现了 UserInterface 并添加了4 个缺失方法。现在实体看起来像这样:

http://pastebin.com/Epw3YrwR

3)我已经尽可能少地修改了 security.yml让它工作,它看起来像这样:

http://pastebin.com/tp6Gd7t7

我清除了缓存并尝试访问 app_dev.php/admin 当然我一整天都遇到同样的错误:

用户“Symfony\Component\Security\Core\User\User”没有用户提供程序。

500 内部服务器错误 - RuntimeException

谁能告诉我问题出在哪里? 我已经尝试了这一千种不同的方法,奇怪的是它工作了一段时间,但是当我尝试添加 sha1 作为编码器算法而不是纯文本,并清除缓存时,我又回到了同样的错误..从那以后我什么也没得到,除了它。这就好像有一个隐藏的缓存,每当 symfony 决定时就会被删除:D

我认为错误也可能出现在实体的 4 个方法中,但我无法修复它们,因为没有关于它们应该做什么的文档。

我目前使用的是RC4。

预先感谢,希望有人能提供帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁的新欢旧爱 2024-11-25 20:38:14

我曾经遇到过这个问题。

这是因为我是用以前的提供商(in_memory)的用户登录的。必须恢复 in_memory 部分,注销然后放入新的提供程序。

我的猜测:

用户的信息位于会话中,并且无法访问它,因为我们将其从 security.yml 中删除

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

错爱 2024-11-25 20:38:14

有同样的问题。看来这可行。我只会在开发过程中使用它,稍后我会找到解决方案。!

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: /

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: /
年少掌心 2024-11-25 20:38:14

对我来说问题发生在开发环境中。发生这种情况是因为我有其他项目的活动会话。

清理浏览器cookie 很有帮助。

for me problem occured in dev environment. It happened because I has active session from other project.

Cleaning browser cookies helped.

脱离于你 2024-11-25 20:38:14

你可以试试 symfony 的朋友 UserBundle 来避免头痛。

至少查看该包将帮助您学习和修复自己的代码。它有大量编写良好的代码/示例。

You could save yourself the headache and try the friends of symfony UserBundle.

At the very least looking at that bundle will help you learn and fix your own code. It has plenty of well written code/examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文