填充在WCF的PrimaryIdentityWCF、PrimaryIdentity

由网友(勿挽旧人)分享简介:我使用的是简单的HTTP头令牌传递到身份验证WCF服务(WCF服务,需要使用basicHttpBinding的,所以我很遗憾不能使用罐头的WS-Security实现)。我想填充PrimaryIdentity对象,这样的WCF服务,可以检查它来确定身份验证的用户。I'm using simple HTTP header...

我使用的是简单的HTTP头令牌传递到身份验证WCF服务(WCF服务,需要使用basicHttpBinding的,所以我很遗憾不能使用罐头的WS-Security实现)。我想填充PrimaryIdentity对象,这样的WCF服务,可以检查它来确定身份验证的用户。

I'm using simple HTTP headers to pass a token to a WCF service for authentication (The WCF service is required to use the basicHTTPBinding, so I unfortunately cannot use the canned ws-security implementation). I would like to populate the PrimaryIdentity object so the WCF services can examine it to determine the authenticated user.

问题是, OperationContext.Current.ServiceSecurityContext.PrimaryIdentity 属性是只读的,当时我想填充它。我已经使用SecurityTokenAuthenticators和IAuthorizationPolicy对象设置身份信息试过,但是这条路似乎需要使用消息级安全(如经常给一个用户名和密码),这不是我想要的。

The issue is that the OperationContext.Current.ServiceSecurityContext.PrimaryIdentity property is read-only at the time I'm trying to populate it. I've tried using SecurityTokenAuthenticators and IAuthorizationPolicy objects to set the identity info, but that route seems to require the use of message-level security (such as always sending in a username and password), which isn't what I want.

任何人都可以阐明如何我可以设置PrimaryIdentity领域?

Can anyone shed light on how I could set the PrimaryIdentity field?

推荐答案

PrimaryIdentity 是不是要填充的你 - 这是WCF运行时的工作,以确定谁在呼叫,并设置 PrimaryIdentity 相应。

PrimaryIdentity is not intended to be populated by you - it's the WCF runtime's job to determine who's calling, and set the PrimaryIdentity accordingly.

所以,如果你调用Windows凭据,那么你会得到一个的WindowsIdentity 保存在那里;如果你正在使用ASP.NET成员资格提供者,你会得到来电存储到 PrimaryIdentity

So if you're calling with Windows credentials, then you'll get a WindowsIdentity stored there; if you're using ASP.NET membership providers, you'll get that caller stored into the PrimaryIdentity.

您可以实际设置的唯一方法是通过创建自己的自定义服务器端的认证机制,并把它插入到WCF。

The only way you could actually set this is by creating your own custom server-side authentication mechanism and plug that into WCF.

请参阅:

WCF身份验证服务概述 WCF安全的基础 - 认证,授权,身份 WCF自定义身份验证和模拟 WCF Authentication Service Overview Fundamentals of WCF Security - Authentication, Authorization, Identities WCF Custom Authentication and Impersonation
阅读全文

相关推荐

最新文章