我使用DirectoryService和查询LDAP来获取用户所属的组名 假设我在一个团队中,并且#34; Test100"和这个小组" Test100"在另一个团体里面说"测试" 当我在LDAP服务器上查询"测试"因为它在Test100内部并且我在Test100内部而没有被返回
如何解决这个问题..请帮忙
Dim LDAPpath As String = <LDAP String>
entry = New DirectoryEntry(LDAPpath, <App ID>, <Password>)
Dim search As New DirectorySearcher(entry)
search.PropertiesToLoad.Add([property])
search.Filter = "sAMAccountName=" & FilterOutDomain(userName)
Dim result As SearchResult = search.FindOne()
Return result
答案 0 :(得分:0)
使用Active Directory作为LDAP提供程序,这是有效的(至少在小范围内 - 我没有使用大型目录进行测试):
class Program {
HashSet<string> foundGroups = new HashSet<string>();
Queue<string> toProcess = new Queue<string>();
void Run(string startingPoint) {
ExpandMembership(startingPoint);
while (toProcess.Count > 0) {
var name = toProcess.Dequeue();
if (foundGroups.Contains(name)) {
// Have already handled this group
continue;
}
foundGroups.Add(name);
ExpandMembership(name);
}
Console.WriteLine("Found {0} groups:", foundGroups.Count);
foreach (var group in foundGroups.OrderBy(s => s)) {
Console.WriteLine(group);
}
}
private void ExpandMembership(string name) {
var entry = new DirectoryEntry("LDAP://" + name);
var memberOf = entry.Properties["memberOf"];
foreach (string groupName in memberOf) {
toProcess.Enqueue(groupName);
}
}
static void Main(string[] args) {
var userPath = "CN=User Name,CN=Users,DC=ad,DC=example,DC=net";
var p = new Program();
p.Run(userPath);
}
}
NB。
Queue
来避免递归。HashSet
以避免再次处理同一组,否则如果A属于B,B属于A将导致无限循环。