gpt4 book ai didi

C# LdapConnection 身份验证问题

转载 作者:太空狗 更新时间:2023-10-29 23:08:20 26 4
gpt4 key购买 nike

我们使用类似于以下的代码来设置到 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连接成功。
谢谢,

最佳答案

看起来连接已绑定(bind),但在发送实际请求之前未经过身份验证。

绑定(bind)连接后考虑以下发送请求...

 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));**
}

关于C# LdapConnection 身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18384797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com