得到一個用戶名,我怎麼會去寫的LDAP查詢將返回所有組用戶中的一員?LDAP查詢列出所有組用戶是的成員?
3
A
回答
4
你在.NET 3.5?
如果是這樣,看看這個優秀的MSDN文章Managing Directory Security Principals in the .NET Framework 3.5它顯示了在.NET 3.5的用戶和組管理的新功能。
在這種情況下,你需要一個主要方面(例如,您的域名):
PrincipalContext domainContext =
new PrincipalContext(ContextType.Domain, "YourDomain");
,然後你可以很容易地找到用戶:
UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, "username");
和「UserPrincipal」對象有稱爲「GetAuthorizationGroups」的方法,其返回用戶所屬的所有組:
PrincipalSearchResult<Principal> results = user.GetAuthorizationGroups();
// display the names of the groups to which the
// user belongs
foreach (Principal result in results)
{
Console.WriteLine("name: {0}", result.Name);
}
P retty容易,呵?
它在.NET很多工作3.5之前,或者在其他語言(PHP,德爾福等)的「直」 LDAP。
馬克
1
這裏是另一種方式來獲得組信息:
確保您的System.DirectoryServices添加引用。
DirectoryEntry root = new DirectoryEntry("LDAP://OU=YourOrganizationOU,DC=foo,DC=bar");
DirectoryEntry user = GetObjectBySAM("SomeUserName", root);
if (user != null)
{
foreach (string g in GetMemberOf(user))
{
Console.WriteLine(g);
}
}
以下方法獲取用戶條目並返回一個字符串列表,它是用戶所屬的組。
public List<string> GetMemberOf(DirectoryEntry de)
{
List<string> memberof = new List<string>();
foreach (object oMember in de.Properties["memberOf"])
{
memberof.Add(oMember.ToString());
}
return memberof;
}
public DirectoryEntry GetObjectBySAM(string sam, DirectoryEntry root)
{
using (DirectorySearcher searcher = new DirectorySearcher(root, string.Format("(sAMAccountName={0})", sam)))
{
SearchResult sr = searcher.FindOne();
if (!(sr == null)) return sr.GetDirectoryEntry();
else
return null;
}
}
相關問題
- 1. LDAP查詢列出某個組的所有用戶
- 2. 組羣成員ldap查詢
- 3. 查詢ldap檢索組用戶是(在sharepoint中)的成員
- 4. 如何列出ldap組的所有組成員?
- 5. Ldap查詢特定於某個組的所有成員
- 6. 查詢LDAP組的其他域成員
- 7. 遞歸查詢LDAP組成員資格
- 8. 檢查用戶是否爲組的成員(ldap)
- 9. LDAP:檢查用戶是否爲組的成員
- 10. LDAP Perl腳本查看用戶是什麼組的成員
- 11. LDAP查詢,檢索用戶有權訪問的所有組
- 12. 如何編寫LDAP查詢以測試用戶是否爲組的成員?
- 13. POWERSHELL:列出特定AD OU組中的所有用戶/成員
- 14. 是否有用戶的LDAP標準組成員身份屬性?
- 15. 從LDAP查詢用戶組
- 16. 用於檢查屬性和組成員資格的LDAP查詢
- 17. C#LDAP查詢檢索組織單位中的所有用戶
- 18. 使用LDAP顯示特定組的所有嵌套組成員?
- 19. LDAP用戶在WebSphere嵌套組成員
- 20. LDAP - 列出特定組中的所有用戶
- 21. 春天LDAP,檢查用戶的成員指定的組
- 22. 獲取Ldap上的所有成員
- 23. 如何查詢所有組和組成員的Active Directory?
- 24. 與子域的組成員的LDAP查詢
- 25. 查詢用戶是否爲組的成員
- 26. LDAP:獲取組的成員
- 27. LDAP查詢以顯示所有具有嵌套組的組
- 28. 列出組中的用戶LDAP python
- 29. PHP LDAP查詢以獲取特定安全組的成員
- 30. 列出來自指定羣組的成員的所有羣組
偉大的作品!非常感謝。 – Donut 2009-09-08 13:37:35