【问题标题】:Adldap2 authentication always returns true - Yii2Adldap2 身份验证始终返回 true - Yii2
【发布时间】:2017-03-06 16:14:19
【问题描述】:

我在 Yii2 中使用 Adldap 扩展程序在此处找到:https://github.com/Adldap2/Adldap2

当我尝试在我的 ldap 服务器上对用户进行身份验证时遇到了问题。我可以成功建立连接并检索用户数据,但是在尝试验证用户的用户名和密码是否正确时,即使凭据错误,它也始终返回 true。下面是我的代码 sn-p(当然没有显示配置数组):

    $ad->addProvider($config);

    try {
        // If a successful connection is made to your server, the provider will be returned.
        $provider = $ad->connect();

        //User below does return the correct information from the ldap server
        $user = $provider->search()->users()->find('quillin');

       try{
          $provider->auth()->attempt("wrongUsername","wrongPassword");
          die("WIN");
        }catch( Exception $e ){
          die("Exception " . $e);
        }


     }catch (\Adldap\Auth\BindException $e) {

       die( "There was an issue binding / connecting to the server. <br />" . $e);

    }

无论我在用户名和密码字段中输入什么,它总是返回 true 并命中 die("WIN");线。在我的 composer.json 文件中,我使用的是 "adldap2/adldap2": "v7.0.*"

我还尝试使用以下方法绑定用户:

       try{
          $provider->auth()->attempt("wrongUsername","wrongPassword", $bindAsUser = true);
          die("WIN");
        }catch( Exception $e ){
            die("lose :(");
          die("Exception " . $e);
        }

这也总是返回 true;

【问题讨论】:

    标签: yii2 ldap adldap


    【解决方案1】:

    我想通了,并会在这里解释任何其他人有同样的问题。

    1) $provider->auth()->attempt() 应该被包裹在一个 IF 中,而不是一个 try/catch。 2) 第一个参数 $username 实际上是在寻找 userprincipalname,文档让它听起来像是在寻找用户名。

    之后,我就可以成功地验证用户身份了。

    【讨论】:

      猜你喜欢
      • 2012-03-09
      • 1970-01-01
      • 2014-02-10
      • 2021-04-12
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多