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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line