我目前正在使用以下方法实现联合身份验证解决方案:用于发行令牌的被动STS,用于托管Silverlight应用程序的网站以及用于Silverlight应用程序的WCF服务.
到目前为止,我能够:
HttpContext.Current.User.Identity as IClaimsIdentity;在网站的web.config上,我添加了所需的两个WIF模块(在IIS 7下)
<modules runAllManagedModulesForAllRequests="true">
<add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
<add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
</modules>
Run Code Online (Sandbox Code Playgroud)
我还配置了web.config的Microsoft.IdentityModel部分,以使用我自己的ClaimsAuthenticationManager和ClaimsAthorizationManager实现.
<service name="Rem.Ria.PatientModule.Web.WebService.PatientService">
<claimsAuthenticationManager type ="Rem.Infrastructure.WIF.RemClaimsAuthenticationManager"/>
<claimsAuthorizationManager type ="Rem.Infrastructure.WIF.RemClaimsAuthorizationManager"/>
</service>
Run Code Online (Sandbox Code Playgroud)
我的ClaimsAuthenticationMAnager只是设置Thread.CurrentPrincipal是一个有效的Principal提供.
class RemClaimsAuthenticationManager : ClaimsAuthenticationManager
{
public override IClaimsPrincipal Authenticate ( string resourceName, IClaimsPrincipal incomingPrincipal )
{
if ( incomingPrincipal.Identity.IsAuthenticated )
{
Thread.CurrentPrincipal = incomingPrincipal;
}
return incomingPrincipal;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我的ClaimsAuthorizationManager被调用时,context.Principal.Identity不包含与Claims有效的Identity,Thread.CurrentPrincipal也不包含.
有任何想法吗?
小智 5
您不需要设置Thread.CurrentPrincipal,因为会话模块将为您执行此操作.您需要通过HttpContext.Current.User访问它,因为Thread.Principal通常设置在与访问您的服务的线程不同的线程上,因为它是IIS中的两个不同模块.我们在即将出版的书中有一个例子,您可以在我们的Codeplex网站上查看.
HTH
| 归档时间: |
|
| 查看次数: |
4867 次 |
| 最近记录: |