5

我们使用类似于以下的代码来设置到 LDAP 目录的安全连接:

using (LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier(ConfigReader.ADServer, 636)))
{
    con.SessionOptions.SecureSocketLayer = true;
    con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
    con.Credential = new NetworkCredential(UserDN, UserPwd);
    con.AuthType = AuthType.Basic;
    con.Bind();
}

在测试期间,我们注意到以下预期行为:

  • 有效的 UserDN 和有效的 UserPwd 导致成功的 Bind()
  • 具有有效 UserPwd 的无效 UserDN 会导致 Bind() 错误(提供的凭据无效。)
  • 具有无效(非空白)UserPwd 的无效 UserDN 导致 Bind() 错误(提供的凭据无效。)

不幸的是,我们还注意到以下意外行为:

  • 有效的 UserDN 和空白的 UserPwd 导致成功的 Bind()
  • 无效的 UserDN 和空白的 UserPwd 导致成功的 Bind()

请告知为什么 LDAP 连接成功但密码为空。
谢谢,

4

1 回答 1

6

似乎连接已绑定,但在发送实际请求之前未进行身份验证。

考虑以下在绑定连接后发送请求...

 using (LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier(ConfigReader.ADServer, 636)))
{
    con.SessionOptions.SecureSocketLayer = true;
    con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
    con.Credential = new NetworkCredential(UserDN, UserPwd);
    con.AuthType = AuthType.Basic;
    con.Bind();
    **con.SendRequest(new SearchRequest(targetLocation, "(objectClass=*)", System.DirectoryServices.Protocols.SearchScope.Subtree, null));**
}
于 2013-08-28T18:30:14.430 回答