没有用户“Symfony\Component\Security\Core\User\User”的用户提供程序
在 Symfony 2 的简单任务上挣扎了一整天但没有成功后,我决定向你们寻求解决方案。
问题是:我想使用学说进行 http_basic 身份验证,因此系统会提示用户输入保存在数据库中的用户名/密码。
因此,我按照以下步骤操作:
1)使用交互式控制台生成器创建了一个名为 User 的新实体。
它看起来像这样:
2)如文档中所述,我已经实现了 UserInterface 并添加了4 个缺失方法。现在实体看起来像这样:
3)我已经尽可能少地修改了 security.yml让它工作,它看起来像这样:
我清除了缓存并尝试访问 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:
2) As stated in the documentation I have implemented UserInterface and added the 4 missing methods. Now the entity looks like this:
3) I have modified the security.yml as little as possible to make it work, and it looks like this:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我曾经遇到过这个问题。
这是因为我是用以前的提供商(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
有同样的问题。看来这可行。我只会在开发过程中使用它,稍后我会找到解决方案。!
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.!
对我来说问题发生在开发环境中。发生这种情况是因为我有其他项目的活动会话。
清理浏览器cookie 很有帮助。
for me problem occured in dev environment. It happened because I has active session from other project.
Cleaning browser cookies helped.
你可以试试 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.