在 Windows 应用程序中选择用于基于 AD 的授权的 API
我们正在构建一个富客户端应用程序 (WPF),它使用登录用户信息进行审核和授权。
我试图在三种不同的 API 之间做出决定来访问此信息:
System.Management
类(WMI 查询)System.Security.Principal
类(WindowsIdentity 等)System.DirectoryServices.AccountManagement
类(UserPrincipal 等)
用例有:
- 获取当前用户名 获取
- X 组中的所有用户
- 获取当前用户所属的所有组
- 当前用户是否在 X 组中?
- 用户 X 是否在组 Y 中?
我对每种方法都有一些概念证明,但我想要一些使用其中一种或另一种方法的客观理由。我希望了解以下方面的事实:
- 可测试性
- 性能
- 易于使用
- 易于部署
- 测试/生产中
- 在开发者的计算机中
We are building a rich-client app (WPF) that uses the logged-on user information for auditing and authorization.
I'm trying to decide between three different APIs for accessing this information:
System.Management
classes (WMI queries)System.Security.Principal
classes (WindowsIdentity, etc)System.DirectoryServices.AccountManagement
classes (UserPrincipal, etc)
The use cases are:
- Get the current username
- Get all the users in group X
- Get all the groups the current user belongs to
- Is the current user in group X?
- Is user X in group Y?
I have some proofs of concept for each method, but I'd like some objective reasons to use one or other. I'd appreciate facts on the following aspects:
- Testability
- Performance
- Ease of use
- Ease of deployment
- In test/production
- In developer's computers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WMI
在可测试性方面很好,因为有很多(本机/.NET/脚本...)可以用于相同的任务、结果比较等。
根据我的经验,有关安全/通信等的部署/设置可能相当困难。
System.DirectoryServices.AccountManagement
根据我的经验,非常容易使用和部署...对于开发人员的计算机,您可以(牺牲一些更微妙的方面)使用相同的代码,并在需要时使用本地用户/组进行测试。关于性能,这通常已经足够了,但可以根据您的需要进行一些调整(临时 AD 查询与永久连接等)。
如果不仅需要查询,还需要创建/更改用户/组等。这是一件很容易做的事情...
我没有经常使用System.Security.Principal,所以可以'不用多说....NET 的最新部分是 System.DirectoryServices.AccountManagement,并且工作得非常好:-)
WMI
is nice regarding testability because there are many (native/.NET/script...) out there whcih can be used for the same tasks, result comparison etc.
What in my experience can be rather difficult is deployment/setup regarding security/communication etc.
System.DirectoryServices.AccountManagement
In my exeperience very easy to use and deploy... for developer's computer you can (sacrificing some subtler aspects) use the same code and test it with the local User/Groups if need be. Regarding Performance this is usually more than sufficient but can be tweaked a bit depending of you needs (ad-hoc AD queries versus permanent conn etc.).
Should there ever be the need to not only query but create/change Users/Groups etc. this is an easy thing to do...
I didn't use System.Security.Principal alot so can't say much about it... the more current part of .NET is System.DirectoryServices.AccountManagement and works really well :-)