【发布时间】:2021-06-21 19:39:28
【问题描述】:
我想从我们的 Domino LDAP 的一个大位置获取所有用户,总共大约 2000 个用户。由于 .NET Core 遗憾地没有独立于平台的 LDAP 库,因此我将 Novell.Directory.Ldap.NETStandard 与此 POC 一起使用:
var cn = new Novell.Directory.Ldap.LdapConnection();
cn.Connect("dc.internal", 389);
cn.Bind("user", "pw");
string filter = "location=MyLoc";
var result = cn.Search("", Novell.Directory.Ldap.LdapConnection.ScopeOne, filter, new string[] { Novell.Directory.Ldap.LdapConnection.AllUserAttrs }, typesOnly: false);
int count = 0;
while (result.HasMore()) {
var entry = result.Next();
count++;
Console.WriteLine(entry.Dn);
}
它打印了很多条目,但不是全部。当count = 1000 我得到一个Size Limit Exceeded 异常。我想这是因为我需要使用某种分页,所以并不是所有条目都会在一个请求中返回。有不同的问题,例如this 或this one。在 Java 中,.NET Core API 似乎有些不同。
方法 1:尝试了解 LdapSearchRequest 在 .NET Core 中的工作原理
byte[] resumeCookie = null;
LdapMessageQueue queue = null;
var searchReq = new LdapSearchRequest("", LdapConnection.ScopeOne, filter, new string[] { LdapConnection.AllUserAttrs },
LdapSearchConstraints.DerefNever, maxResults: 3000, serverTimeLimit: 0, typesOnly: false, new LdapControl[] { new SimplePagedResultsControl(size: 100, resumeCookie) });
var searchRequest = cn.SendRequest(searchReq, queue);
我试图弄清楚如何在 .NET Core 中使用 Java 示例。这看起来不错,但是我不知道如何获取 LDAP 条目。我只得到一个消息ID。 By looking into the source 看来我走对了,但他们使用的是MessageAgent,因为它是internal sealed,所以不能在外面使用。这大概就是为什么在源代码中搜索LdapRearchRequest 没有得到很多结果的原因。
方法二:使用SimplePagedResultsControlHandler
var opts = new SearchOptions("", LdapConnection.ScopeOne, filter, new string[] { LdapConnection.AllUserAttrs });
// For testing purpose: https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard/issues/163
cn.SearchConstraints.ReferralFollowing = false;
var pageControlHandler = new SimplePagedResultsControlHandler(cn);
var rows = pageControlHandler.SearchWithSimplePaging(opts, pageSize: 100);
这会引发Unavaliable Cricital Extension 异常。首先我认为这是 .NET 端口的问题,它可能还不支持原始 Java 库的所有功能。它看起来很完整,根据进一步的研究,它看起来像是一个 LDAP 错误代码。所以这一定是服务器必须支持的东西,但 Domino 不支持。
【问题讨论】:
-
方法 2 对我来说似乎不错,但似乎 domino 不支持定义扩展的 RFC-2696,@see RFCs supported by the LDAP service。
标签: c# asp.net-core ldap lotus-domino .net-5