我有一个调用WCF服务的ASP.NET应用程序。
在ASP.NET应用程序中,我调用ADFS进行身份验证,并且可以在CurrentPrincipal中看到用户的所有声明。然后,我执行WCF服务(wsHttpBinding)的调用,但是声明列表为空。
可能是什么原因?
最佳答案
如果我没记错的话,可以使用其他方法在WCF中获得Claims。
Thread.CurrentPrincipal -简单易用,但需要在配置中进行一些设置,这是最被忽略的设置。
<behaviors>
<serviceBehaviors>
<behavior name="Test.Services.WifBehavior">
<serviceCredentials useIdentityConfiguration="true" />
<!---Set principalPermissionMode to always to pass the ClaimsIdentity info to the Thread.CurrentPrincipal-->
<serviceAuthorization principalPermissionMode="Always"/>
</behavior>
<serviceBehaviors>
</behaviors>
OperationContext.Current.ClaimsPrincipal -我不记得是否需要一些配置,但是我想您可以直接从调用的方法中获取它。
OperationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets -Create a Custom Authorization Manager for a Service,需要在配置中添加。
请注意,我使用了Windows Identity Foundation(WIF)。