【问题标题】:OpenLDAP The LDAP server is unavailableOpenLDAP LDAP 服务器不可用
【发布时间】:2012-07-16 15:02:49
【问题描述】:

过去四天我一直在尝试从 asp.net 连接到我们的 OpenLDAP 服务器,但没有成功。就在我脱掉头发之前,任何人都可以有一个可行的解决方案(即使用 c# asp.net 连接到 OpenLDAP 服务器)。显然我可以从 putty.exe 访问 ldap 服务器并进行搜索。此外,我可以使用 LDAP 服务器在本地安装 Drupal CMS 进行身份验证,而不会出现任何问题——因为我已经添加了 LDAP 模块。 我的问题是在 asp.net 中做同样的事情。具体内容如下:

Ldap 服务器托管在 sun solaries 上。 我的开发机器正在运行 Win XP Service Pack 3。 当我尝试使用已在 putty 中成功使用的用户名和密码调用 bind 时出现错误。

    string hostNameAndSSLPort = "ipaddress";
    string userName = "username";
    string password = "password";

    // establish a connection
    LdapConnection connection = new LdapConnection(hostNameAndSSLPort);

    // create an LdapSessionOptions object to configure session
    // settings on the connection.
    LdapSessionOptions options = connection.SessionOptions;

    options.ProtocolVersion = 3;


    options.SecureSocketLayer = true;

    connection.AuthType = AuthType.Basic;

    connection.Credential =
    new NetworkCredential(userName , password );

    try
    {
        connection.Bind();
    }
    catch(Exception e){
         lblSecurity.Text = e.Message;
    }

我什至尝试过使用 options.StartTransportLayerSecurity(null); 在通过相同的错误调用绑定之前仍然存在。我可能做错了什么?请帮忙!!!!!!!!!

【问题讨论】:

  • 您是否尝试过不使用 SSL 只是为了看看您是否可以这样连接?
  • 另外,在这篇文章中:stackoverflow.com/questions/8904832/… 似乎他们使用 DN 而不仅仅是用户名......也许在他们的示例中 bindDN 等于用户名(uid?),但这可能是一个开始的地方。我也遇到了一些问题,因为 LDAP 的配置方式,我不得不简单地连接到 SSL 的非标准端口(或者那里的一些奇怪的防火墙规则......)
  • 您的 LDAP 服务器证书是自签名的还是由证书颁发机构签名的?如果它是由证书颁发机构签署的,它是公共的还是私人的?您可能有信任链问题。另外,您遇到了什么具体的例外情况?
  • 也尝试指定 ipAddress:portNumber。

标签: c# asp.net solaris openldap su


【解决方案1】:

我遇到了同样的问题。我的修复与上面的答案非常相似。问题是 LDAP 服务器发回了证书,而客户端(我们的代码)不接受它。因此,通过添加以下代码行,让我庆祝并撕破衬衫!

connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);

或者用vb术语:

connection.SessionOptions.VerifyServerCertificate = New VerifyServerCertificateCallback(Function(con, cer) True)

【讨论】:

    【解决方案2】:

    有关一些有效的示例代码,请参阅此答案。 How do I connect to a locally installed OpenLDAP service?

    您提到使用 XP。我相信有一个修补程序可以解决 XP 上 winldap 的 TLS 实现中的问题。您必须在 microsoft 网站上进行一些搜索。我记得它被埋在某处的技术网页面中。

    也不要将 TLS 与 .net/winldap 一起使用。您会想知道为什么您的网站会随机锁定 cpu 直到它被杀死。上面的答案有解释。只需使用 SSL。

    【讨论】:

    • 我尝试跟踪问题,我可以在自动窗口中看到问题立即开始我调用 new LdapConnection(hostNameAndSSLPort) 因为当我检查会话选项中的连接变量时,已经有一个错误 + SecurityContext “connection.SessionOptions.SecurityContext”在“安全上下文”和 + SendTimeout 中引发了“System.DirectoryServices.Protocols.DirectoryOperationException”对象 {System.DirectoryServices.Protocols.DirectoryOperationException} 类型的异常
    • 感谢大家花时间帮助我。我同样尝试使用完整的 dn,但没有成功。正如我上面提到的,当我调用新连接时问题就开始了。但是,我已经检查了主机是否可以从 connection.options 变量中访问。
    【解决方案3】:

    这样的代码:

    LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier(this._domain,     Convert.ToInt32(this._port)));
    connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);
    connection.SessionOptions.ProtocolVersion = 3;
    connection.AuthType = AuthType.Basic;       
    connection.SessionOptions.SecureSocketLayer = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多