通过LDAPS检索可访问的外部Active Directory服务器上的所有用户帐户

本文关键字:用户 服务器 Active 检索 LDAPS 访问 通过 外部 Directory | 更新日期: 2023-09-27 18:22:42

我需要连接到一个可以访问但只能通过LDAPS访问的外部LDAP服务器。

我有可用的信息是用户名,服务器,密码。我需要查询和检索所有用户的列表。我有详细信息的格式是

  • 用户名:域''用户名
  • 密码:{Password}
  • 域:远程。{domain}.net.au

我写的以下代码将成功验证我的用户帐户,但我现在需要枚举所有用户,这就是我遇到问题的地方。理想情况下,这将是目录中的所有用户,而不是来自特定OU中的用户。同样,我没有该服务器的任何OU的完全限定路径。服务器有一个自签名证书,这就是为什么在我的示例中我特别告诉它接受证书的原因。

        int port = secured ? 636 : 389;
        LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier(ldapServer, port, false, false));
        if (secured)
        {
            connection.SessionOptions.ProtocolVersion = 3;
            connection.SessionOptions.SecureSocketLayer = true;
        }

        connection.Credential = new NetworkCredential(username, password);
        connection.AuthType = AuthType.Basic;
        connection.SessionOptions.VerifyServerCertificate += (conn, cert) => { return true; };
        connection.Bind();
        return connection;

通过LDAPS检索可访问的外部Active Directory服务器上的所有用户帐户

因此,答案在使用执行System.DirectoryServices.Protocols简介(S.DS.p)的简单搜索示例中

// create a search filter to find all objects
string ldapSearchFilter = "(&(objectCategory=person)(objectClass=user))";
相关文章: