C#LdapConnection身份验证问题

Sey*_*our 5 .net c# authentication service ldap

我们使用类似于以下的代码来建立到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();
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

请使用空密码告知LDAP连接成功的原因.
谢谢,

gpm*_*thy 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));**
}
Run Code Online (Sandbox Code Playgroud)