gpt4 book ai didi

Symfony2 中的身份验证以静默方式失败

转载 作者:行者123 更新时间:2023-12-04 12:42:57 25 4
gpt4 key购买 nike

我在进行身份验证时遇到问题,但它似乎只发生在非常特定的情况下。身份验证是通过第三方 API 完成的,因此我编写了自己的用户提供程序类,该类内部是一些代码,用于在 API 和 Symfony 之间同步数据,作为同步过程的一部分,它确定用户应该具有哪些角色。
执行此操作后,它通过多对多关系建立角色和用户之间的关系。

我的 User 对象中的 getRoles() 方法从数据库中获取角色对象并将其转换为字符串数组,角色名称来自我的数据库并且都以 ROLE_ 开头。

如果我使用一个不应该有额外角色的帐户登录它可以正常工作,但是如果我登录到一个应该有角色的帐户我只会被发送回登录屏幕而没有错误消息。

我检查了日志并看到了这些条目:

security.INFO: User "test105@example.com" has been authenticated successfully [] []
event.DEBUG: Notified event "security.interactive_login" to listener "Pogo\MyBundle\Listener\LoginListener::onSecurityInteractivelogin". [] []
event.DEBUG: Listener "Symfony\Component\Security\Http\Firewall::onKernelRequest" stopped propagation of the event "kernel.request". [] []
event.DEBUG: Listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener" was not called for event "kernel.request". [] []
event.DEBUG: Listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener" was not called for event "kernel.request". [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse". [] []
security.DEBUG: Write SecurityContext in the session [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\SecurityBundle\EventListener\ResponseListener::onKernelResponse". [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener::onEarlyKernelRequest". [] []
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
security.INFO: Populated SecurityContext with an anonymous Token [] []
event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException". [] []
security.DEBUG: Access denied (user is not fully authenticated); redirecting to authentication entry point [] []
security.DEBUG: Calling Authentication entry point [] []

我不明白它是如何在顶部进行身份验证的,然后一旦它检查防火墙,它就会发现自己带有一个匿名 token ,这就是它可能将我送回登录屏幕的原因。

我的防火墙/access_control 设置是:
firewalls:
public:
pattern: /.*
anonymous: true
tessitura_login:
login_path: /account/login
check_path: /secure/login_check
logout:
path: /secure/logout
target: /
access_control:
- { path: ^/secure/.*, role: ROLE_USER }
- { path: ^/admin.*, role: ROLE_ADMIN }
- { path: ^/account/login/?, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }

对此的任何帮助将不胜感激,我现在​​已经花了几个小时并且完全被难住了。

最佳答案

使用电话号码作为用户名且未在 refreshUser() 中指定用户名属性时遇到此静默失败问题方法,应该是:

public function refreshUser(UserInterface $customer)
{
$class = get_class($customer);

if( !$this->supportsClass($class) ) {
throw new UnsupportedUserException("Instances of \"{$class}\" are not supported");
}

return $this->loadUserByUsername($customer->getPhoneNumber()); // <-- This is it!
}

我想我不是唯一错过它的人,可能会有所帮助。

关于Symfony2 中的身份验证以静默方式失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7516787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com