Wcf 我如何在服务端指定索赔类型要求,以便客户请求遵守这些要求?
我有:Wcf 我如何在服务端指定索赔类型要求,以便客户请求遵守这些要求?,wcf,wif,claims-based-identity,Wcf,Wif,Claims Based Identity,我有: 也是身份提供者的被动STS“登录应用程序” 可以接受和处理ActAs令牌的活动STS WCF服务 网站依赖方 网站调用的WCF服务依赖方 所有这些都是使用Windows身份基础和自定义STS代码组合在一起的。不涉及Active Directory(ADFS) 我现在的工作是: 用户尝试访问网站RP 用户被重定向到被动STS 用户登录,获得颁发的令牌,重定向回web站点 Web站点RP向WCF RP发出服务调用,并传递ActAs令牌,以便进行委派 活动STS看到ActAs令牌进入并正确
- 也是身份提供者的被动STS“登录应用程序”
- 可以接受和处理ActAs令牌的活动STS WCF服务
- 网站依赖方
- 网站调用的WCF服务依赖方
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_FederatedService">
<security
authenticationMode="IssuedTokenForCertificate"
messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10">
<issuedTokenParameters tokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1">
<issuer address="http://localhost:38901/ActiveSts.svc/IWSTrust13" />
<issuerMetadata address="http://localhost:38901/ActiveSts.svc/mex" />
</issuedTokenParameters>
</security>
<textMessageEncoding>
<readerQuotas maxArrayLength="32767" />
</textMessageEncoding>
<httpTransport />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
如果我在调用web站点上更改配置以在issuedTokenParameters部分指示claimTypeRequirements,那么活动STS实际上会在RST中看到所需声明的列表。。。但这是在呼叫网站上,这对我来说是个问题
如何使WCF RP能够指定其需要的其他声明,而无需在呼叫网站上复制该配置?
如果这确实是一个绑定问题,那么如果您能向我展示上面给出的等效配置,这会有所帮助。我可以用适当的更改来更新网站和WCF服务,但我同样需要服务(或服务上的行为,或服务上的配置)来控制它所需的声明列表。服务不应接受缺少必需索赔的请求。事实证明,您必须这样做,即
CreateChannelActingGas(令牌)
扩展方法,而是使用WSTrustChannelFactory
手动请求ActAs令牌(或新令牌)WSTrustChannelFactory
和WSTrustChannel
的合理解释。我的解决方案就是基于此
简而言之,没有所有的错误处理等,代码基本上如下所示:
// You need the channel factory so you can get info about the endpoint.
var factory = new ChannelFactory<IService>();
// Get the issuedTokenParameters information from the binding.
// You see this in the XML config but it's painful to access.
var tokenParameters = factory.Endpoint.Binding
.CreateBindingElements()
.OfType<SecurityBindingElement>().First()
.EndpointSupportingTokenParameters
.Endorsing.OfType<IssuedSecurityTokenParameters>().First();
// Prepare the RST.
var trustChannelFactory = new WSTrustChannelFactory(tokenParameters.IssuerBinding, tokenParameters.IssuerAddress);
var trustChannel = (WSTrustChannel)trustChannelFactory.CreateChannel();
var rst = new RequestSecurityToken(RequestTypes.Issue);
rst.AppliesTo = factory.Endpoint.Address;
// If you're doing delegation, set the ActAs value.
var principal = Thread.CurrentPrincipal as IClaimsPrincipal;
var bootstrapToken = principal.Identities[0].BootstrapToken;
rst.ActAs = new SecurityTokenElement(bootstrapToken);
// Here's where you can look up claims requirements dynamically.
rst.Claims.Add(new RequestClaim("http://dynamically-added-claim"));
// Get the token and attach it to the channel before making a request.
RequestSecurityTokenResponse rstr = null;
var issuedToken = trustChannel.Issue(rst, out rstr);
var fccParameters = new FederatedClientCredentialsParameters();
fccParameters.IssuedSecurityToken = issuedToken;
var channel = factory.CreateChannel();
((IChannel)channel).GetProperty<ChannelParameterCollection>().Add(fccParameters);
// NOW you can make the request.
channel.DoWork();
//您需要通道工厂,以便获取有关端点的信息。
var factory=新的ChannelFactory();
//从绑定中获取issuedTokenParameters信息。
//您可以在XML配置中看到这一点,但是访问它很痛苦。
var tokenParameters=factory.Endpoint.Binding
.CreateBindingElements()
.OfType().First()
.EndpointSupportingTokenParameters
.背书.of type().First();
//准备RST。
var trustChannelFactory=new WSTrustChannelFactory(tokenParameters.IssuerBinding,tokenParameters.issueAddress);
var trustChannel=(WSTrustChannel)trustChannelFactory.CreateChannel();
var rst=新的RequestSecurityToken(RequestTypes.Issue);
rst.AppliesTo=factory.Endpoint.Address;
//如果要执行委派,请设置ActAs值。
var principal=Thread.CurrentPrincipal作为IClaimsPrincipal;
var bootstrapToken=主体。标识[0]。bootstrapToken;
rst.ActAs=新的SecurityTokenElement(bootstrapToken);
//在这里,您可以动态查找索赔要求。
rst.Claims.Add(新的RequestClaim(“http://dynamically-added-claim"));
//在发出请求之前,获取令牌并将其附加到通道。
RequestSecurityTokenResponse rstr=null;
var issuedToken=信任渠道。问题(rst,out rstr);
var fccParameters=新的FederatedClientCredentialsParameters();
fccParameters.IssuedSecurityToken=issuedToken;
var channel=factory.CreateChannel();
((IChannel)channel.GetProperty().Add(fccParameters);
//现在你可以提出请求了。
道工();
如果您希望优化某些通信流,这还允许您缓存已发布的令牌