[英]Error with PrincipalPermission authentication in WCF
I am following a Pluralsight video on Authentication . 我正在观看有关Authentication的Pluralsight视频 。
I am trying to add simple PrinciplePermission authentication to my web service: 我试图将简单的PrinciplePermission身份验证添加到我的Web服务:
[PrincipalPermission(SecurityAction.Demand, Role = "Computer\\Group")]
public String testDBConnection()
{
return "success";
}
In my WCF client I am sending: 在WCF客户端中,我正在发送:
client.ClientCredentials.UserName.UserName = "Alice";
client.ClientCredentials.UserName.Password = "alice";
I have created the group and added Alice to it as per the video, but now.... 我已经创建了该组,并根据视频将爱丽丝添加到了该组,但是现在。
I keep getting the error: 我不断收到错误:
"Request for principal permission failed." “请求主体权限失败。”
Any idea what's wrong? 知道有什么问题吗?
You need some code to create the IPrincipal
on the server when the request arrives. 您需要一些代码来在请求到达时在服务器上创建
IPrincipal
。
The easiest way to do this is probably to use an ASP.NET RoleProvider
, for which you need to configure a behaviour, eg: 最简单的方法可能是使用ASP.NET
RoleProvider
,您需要为其配置行为,例如:
<system.serviceModel>
...
<behaviors>
<serviceBehaviors>
<behavior name=...>
...
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="MyRoleProvider" />
</behavior>
</serviceBehaviors>
...
and: 和:
<system.web>
...
<roleManager enabled="true" defaultProvider="MyRoleProvider">
<providers>
<clear/>
<add name="MyRoleProvider"
...
If you configure a RoleProvider
correctly in this way, then Thread.CurrentPrincipal
will be set automagically, and it should work. 如果以这种方式正确配置
RoleProvider
,则Thread.CurrentPrincipal
将自动设置,并且应该可以正常工作。
The principle object is a read only object that gets set as part of the security settings for your application upon loading. 主对象是只读对象,在加载时将其设置为应用程序安全性设置的一部分。 The way I was able to get around it was to create a class that inherits IPrincipal.
我能够解决的方法是创建一个继承IPrincipal的类。 You would need to do this in your WCF application.
您需要在WCF应用程序中执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.