我正在尝试使用symfony2实现登录页面,并且我正在使用自己的自定义用户提供程序。symfony不承认已通过身份验证的用户
问题是当用户输入他的凭证时,他不会被识别。那么,我的意思是底部的调试栏显示“您没有通过身份验证”。而$request->getUser()
将返回null。但奇怪的是,用户仍然被允许访问需要他登录的页面。
我认为问题不在于身份验证,因为当我输入错误的密码时,会收到警告关于它,但是当我输入正确的一个,我被重定向到第一页(但它仍然说“你没有通过身份验证”。)
你知道我应该在哪里寻找问题吗?
我已将security.yml
文件附加在this pastebin和routing.yml
的this one中。
Here是我的自定义用户提供程序的代码。
和This是用户类定义。
编辑:这是我的get('security.context')->getToken()
的var_dump。有趣的是authenticated
是真的,但getUser()
仍然是空的,调试栏说我没有通过身份验证。
object(Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken)#46 (6) {
["credentials":"Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken":private]=>
NULL
["providerKey":"Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken":private]=>
string(11) "system_area"
["user":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=>
NULL
["roles":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=>
array(2) {
[0]=>
object(Symfony\Component\Security\Core\Role\Role)#45 (1) {
["role":"Symfony\Component\Security\Core\Role\Role":private]=>
string(10) "ROLE_ADMIN"
}
[1]=>
object(Symfony\Component\Security\Core\Role\Role)#44 (1) {
["role":"Symfony\Component\Security\Core\Role\Role":private]=>
string(9) "ROLE_USER"
}
}
["authenticated":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=>
bool(true)
["attributes":"Symfony\Component\Security\Core\Authentication\Token\AbstractToken":private]=>
array(0) {
}
}
$ this-> get('security.context') - > getToken() - > getUser()为空 – Untitled
您是否检查过您的会话已启动? $ this-> get('session') - > isStarted()?如果用户在加载页面时加载,请检查您的app/logs/dev.log。 – nifr
是的。它开始了。 – Untitled