【发布时间】:2018-02-15 10:58:46
【问题描述】:
我需要创建一个使用 .NET Core 在 linux 上工作的 LDAP 客户端。我搜索了互联网,唯一支持 .Net 标准的库是 Novell.Directory.Ldap(开源,iei - https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard)。目录服务库在 .Net Core for Linux 中不支持,仅在 Windows 上支持。
我查看了文档并成功创建了一个基本的 Ldap 客户端应用程序。
现在的问题:我需要同步很多用户(10.000、200.000 个用户),默认情况下我的 ldap 服务器的最大页面大小为 1000(我不想更改它) )。我使用 VirtualListControl 来创建页面,它适用于 10k 用户。
对于 200k 用户,它会因错误 53 而崩溃 - 不愿意对 LdapSortControl 响应执行。 Novell 库需要一个 LdapSortControl 来执行分页操作(用于索引),我认为我的 ldap 无法对 200k 进行排序。我使用的代码:
int startIndex = 1;
int contentCount = 0;
int afterIndex = 10;
int count = 0;
do
{
LdapVirtualListControl ctrl = new LdapVirtualListControl(startIndex, 0, afterIndex, contentCount);
LdapSortKey[] keys = new LdapSortKey[1];
keys[0] = new LdapSortKey("sn");
LdapSortControl sort = new LdapSortControl(keys, true);
LdapSearchConstraints constraints = _ldapConnection.SearchConstraints;
constraints.setControls(new LdapControl[] { ctrl, sort});
_ldapConnection.Constraints = constraints;
LdapSearchResults lsc = _ldapConnection.Search(searchBase, searchScope, searchFilter, attributes, typesOnly, cons);
while (lsc.HasMore())
{
try
{
LdapEntry nextEntry = lsc.Next();
Console.WriteLine( nextEntry.DN);
}
catch (LdapException e)
{
Console.WriteLine($"Error: {e.LdapErrorMessage}");
//Exception is thrown, go for next entry
continue;
}
}
LdapControl[] controls = lsc.ResponseControls;
if (controls == null)
{
Console.Out.WriteLine("No controls returned");
}
else
{
foreach (LdapControl control in controls)
{
if (control.ID == "2.16.840.1.113730.3.4.10")
{
LdapVirtualListResponse response = new LdapVirtualListResponse(control.ID, control.Critical, control.getValue());
startIndex += afterIndex + 1;
contentCount = response.ContentCount;
count += afterIndex;
}
}
}
Console.WriteLine(i);
} while (count <= contentCount);
文档很小,没有足够的信息,我不知道如何以更好的方式使用 Novell 库进行分页。 这里有没有人使用 Novell Ldap 库并且有任何分页经验并且也可以帮助我?我分散了
谢谢
【问题讨论】:
标签: c# active-directory ldap .net-core