如何列出 WCF 服务中请求用户的角色?
刚刚开始掌握 WCF 安全性。 如何列出用户在服务中的角色?
例如
// Could use declarative security here, i.e. using PrincipalPermission attribute
public string MyService()
{
// Would like some code that does something like:
foreach( Role role in CurrentUser.Roles )
{
}
}
谢谢
Just started getting to grips with WCF security. How do I list a user's roles at the service?
E.g.
// Could use declarative security here, i.e. using PrincipalPermission attribute
public string MyService()
{
// Would like some code that does something like:
foreach( Role role in CurrentUser.Roles )
{
}
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理 Windows 组时,您可以使用以下代码:
When dealing with Windows groups you can use this code:
.NET 中基于角色的安全基础结构(即 IPrincipal)不允许获取所有用户的角色。 您只能查询用户是否处于特定角色(通过 IPrincipal.IsInRole("role-name"))。
但是,如果您不介意受特定身份验证/授权设置的束缚,可以使用一些解决方案。 例如,另一位发帖者指出了使用 Windows 身份验证时如何获取用户的角色。
The role-based security infrastructure in .NET (ie IPrincipal) doesn't allow fetching all of a user's roles. You can only inquire whether a user is in a specific role (via IPrincipal.IsInRole("role-name")).
However, there are solutions if you don't mind being tied to a particular authentication/authorization setup. For example, another poster pointed out how to get the user's roles when using Windows authentication.