刚开始掌握WCF安全。我如何列表用户的角色的服务?

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 )
    {
    }
}

感谢

有帮助吗?

解决方案

在使用Windows组处理您可以使用此代码:

foreach (IdentityReference idRef in WindowsIdentity.GetCurrent().Groups)
{
    Console.WriteLine(idRef.Translate(typeof(NTAccount)).Value);
}

其他提示

基于角色的安全基础设施。网(即IPrincipal)不允许获取所有的用户的角色。你只能查询的用户是否是在一个具体的作用(通过IPrincipal.IsInRole("的角色名称")).

然而,也有解决方案如果你不介意被绑在一个特定的认证/授权设置程序。例如,另一种海报,指出如何获得的用户的角色时,采用Windows认证。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top