【问题标题】:C# LdapConnection Authentication IssueC# LdapConnection 身份验证问题
【发布时间】:2013-12-20 19:58:25
【问题描述】:

我们使用类似于以下的代码来设置到 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() 错误(The 提供的凭据无效。)
  • 带有无效(非空白)UserPwd 的无效 UserDN 导致 Bind() 错误(提供的凭据无效。)

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

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

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

【问题讨论】:

  • 您的 LDAP 服务器是否设置为允许匿名绑定?请参阅此链接,technet.microsoft.com/en-us/library/cc816788(v=ws.10).aspx
  • 感谢您的想法...但我们的网络管理员确认尚未启用匿名 LDAP 绑定。
  • 根据我们的研究,无需密码即可成功绑定到 LDAP(即使“允许匿名 LDAP 绑定”设置被禁用)似乎是 LDAP 的一项“功能”。因此,事后看来,作为一种普遍的良好做法,我们实施了一个简单的检查来以编程方式处理空白密码条件,而不是依赖于 LDAPConnection。
  • @Seymour @gpmurthy 你能帮忙把连接字符串的格式以及用户名和密码放在一个例子中。我确定我的连接字符串不正确,我处于同样的情况。我正在尝试通过 ssl 连接LDAP://192.168.1.100:389/ou=People,dc=company,dc=com 我需要指定端口号吗?我需要用 ldap 作为前缀吗?
  • 我认为最好的方法是在密码为空的情况下返回正确设置的 con.Bound 属性。

标签: c# .net authentication service ldap


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-29
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 2015-08-25
    • 2010-11-17
    相关资源
    最近更新 更多