根据AD组成员身份限制对WPF视图的访问

Shi*_*iji 5 c# security wpf active-directory active-directory-group

我们有一个WPF应用程序.我们希望根据用户AD组成员身份重新获取对应用程序的访问权限.

我们可以将此作为每个视图的属性,还是作为用户启动应用程序时的检查?

任何代码示例将不胜感激.

mar*_*c_s 6

在.NET 3.5及更高版本上执行此操作的最简单方法是使用System.DirectoryServices.AccountManagement(S.DS.AM)命名空间.在这里阅读所有相关内容:

基本上,您可以定义域上下文并轻松查找AD中的用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// get your group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// check if current user is member of that group
UserPrincipal user = UserPrincipal.Current;

if(user.IsMemberOf(group))
{
   // do something here....     
}
Run Code Online (Sandbox Code Playgroud)

新的S.DS.AM使得在AD中与用户和群组玩游戏变得非常容易!