duanmiao6695 2019-08-09 16:17
浏览 124
已采纳

无法刷新令牌,因为用户已更改 - Syfmony 4 - LDAP

I'm trying to authenticate against a ldap server using symfony 4.2 and its LdapUserProvider but I get the following error

[2019-08-09 17:40:52] security.DEBUG: Cannot refresh token because user has changed. {"username":"admin","provider":"Symfony\\Component\\Security\\Core\\User\\LdapUserProvider"} []
[2019-08-09 17:40:52] security.DEBUG: Token was deauthenticated after trying to refresh it. [] []
[2019-08-09 17:40:52] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-08-09 17:40:52] security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. 

I found that the refreshed user password is hard coded to null in the ldapProvider. This refreshed user is then evaluated not equal to the token user and this results in the deauthentification of the user.

vendor/symfony/security-core/User/LdapUserProvider.php:

    public function refreshUser(UserInterface $user)
    {
        if (!$user instanceof User) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
        }

        return new User($user->getUsername(), null, $user->getRoles());
    }

vendor/symfony/security-http/Firewall/ContextListener.php:

try {
                $refreshedUser = $provider->refreshUser($user);
                $newToken = clone $token;
                $newToken->setUser($refreshedUser);
...
}

How can I solve this issue ?

Thanks

  • 写回答

1条回答 默认 最新

  • dsy48837 2019-08-12 09:37
    关注

    This issue has been fixed in symfony 4.4, in symfony/src/Symfony/Component/Ldap/Security/LdapUserProvider.php

    the password is not set to null anymore

    public function refreshUser(UserInterface $user)
        {
            if (!$user instanceof LdapUser) {
                throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
            }
            return new LdapUser($user->getEntry(), $user->getUsername(), $user->getPassword(), $user->getRoles());
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么