【发布时间】:2016-04-04 20:40:50
【问题描述】:
我试图在 C# 中列出来自 Active Directory 的角色列表,但到目前为止我发现的唯一答案是绑定到特定用户的角色列表,而不是域明智的所有角色列表。
这是我找到的sn-p here
// set up domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
// get the authorization groups - those are the "roles"
var groups = user.GetAuthorizationGroups();
foreach(Principal principal in groups)
{
// do something with the group (or role) in question
}
}
}
如您所见,获取角色列表的唯一方法是使用绑定到用户的UserPrincipal 对象。我想列出可以分配给来自特定域的用户的所有可能角色。
顺便说一句,我不太了解 Active Directory 中的用户/组/角色层次结构,因此在考虑该结构的工作原理时我可能会出错,假设角色只是一种特殊的组。
【问题讨论】:
标签: c# dns active-directory roles