使用STS和WCF遇到不安全或错误安全的故障异常问题

时间:2013-12-04 14:34:38

标签: wcf wif sts-securitytokenservice

我正在处理几个使用WIF和STS提供商保护的WCF服务(所有这些服务都使用开箱即用的Microsoft代码和示例)。这些服务都是使用.NET 3.5构建的,并且最近都已更新到.NET 4.0。 所有。与服务相关联的.dll也已更新为4.0。在我更新框架版本之前,这些服务已按原样运行多年。

现在问题是当对由STS WCF服务保护的WCF服务进行调用时,在将令牌传递回调用STS保护的WCF服务的客户端应用程序之后会产生错误:

  

从另一方收到了不安全或不正确安全的故障   派对。请参阅内部FaultException以获取故障代码和详细信息。

     

HResult -2146233087

     

{“处理安全令牌时发生错误   消息。“}

     

服务器堆栈跟踪:at   System.ServiceModel.Channels.SecurityChannelFactory 1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory 1.SecurityRequestChannel.Request(消息   消息,TimeSpan超时)at   System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation   operation,EndpointAddress目标,Uri via,SecurityToken   currentToken,TimeSpan超时)at   System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(时间跨度   超时)at   System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(时间跨度   超时)at   System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(时间跨度   超时)at   System.ServiceModel.Channels.CommunicationObject.Open(时间跨度   超时)at   System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
  在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan   超时)at   System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel   频道,TimeSpan超时)at   System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(时间跨度   超时,CallOnceManager级联)at   System.ServiceModel.Channels.ServiceChannel.EnsureOpened(时间跨度   System.ServiceModel.Channels.ServiceChannel.Call(String。)   action,Boolean oneway,ProxyOperationRuntime操作,Object [] ins,   对象[]出局,TimeSpan超时)at   System.ServiceModel.Channels.ServiceChannel.Call(String action,   Boolean oneway,ProxyOperationRuntime操作,Object [] ins,   对象[]出局)   System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage   methodCall,ProxyOperationRuntime operation)at   System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天   消息)

     

在[0]处重新抛出异常:at   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天   reqMsg,IMessage retMsg)at   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培;   msgData,Int32类型)at   MyProject.IMyService.GetInfo()   在MyProject.Proxy.GetInfo()中   C:\项目\ Proxy.cs:线   36

深入挖掘也表明:

InvalidSecurityToken ,作为InnerException.Code.Subcode.Name属性值。

所以我看了下面的内容,这些都暗示了系统上的时钟问题,但没有一个有效:

http://blogs.msdn.com/b/dhrubach/archive/2009/12/14/9936037.aspx
An unsecured or incorrectly secured fault was received from the other party.(When working with SAML )
http://blogs.msdn.com/b/xiaowen/archive/2009/03/26/tip-add-a-clock-skew-to-prevent-some-security-faults.aspx?Redirected=true

我已经在这些服务中附加调试器并尝试遍历代码,但我找不到罪魁祸首。有谁知道我可能会对此感到不满?

编辑:有趣的是STS服务中WIF的艰难部分正在进行身份验证工作!我已启用日志记录并捕获以下内容:

Service authorization succeeded.  
Service: http:// localhost:4068 /MyID/MyID.svc  
Action: http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue  
ClientIdentity: Domain\allen; S-1-5-21-1234567890-1234567895-0987654321-45678 
AuthorizationContext: uuid-22fad22a-22fe-123c-9b69-a22c23f569ce-99 
ActivityId: <null>  
ServiceAuthorizationManager: <default>

我还在.config中启用了WCF日志记录来查看.svc文件,但他们没有提供任何错误信息来查明问题。这就像STS说:“嘿,你经过身份验证,我们通过你并生成令牌,现在我们完成了!”看来调用客户端不喜欢令牌。然而,这已经成功了,直到我改变了框架版本。据我所知,没有任何重大的WIF变化来自3.5 - &gt; 4.0,但是在4.5中,WIF被整合到框架中的重大变化。

所以所有授权都有效,只是客户接受令牌被接受了?

2 个答案:

答案 0 :(得分:1)

可能是客户端仍然安装了这两个版本的框架。

由于类的名称在两者中都是相同的,因此客户端可能正在从框架的“错误”版本运行代码。

要修复它,您可以完全限定类名。

请参阅:http://msdn.microsoft.com/en-us/library/jj157089.aspx

答案 1 :(得分:1)

首先,您的跟踪选项在哪里?仅跟踪System.ServiceModel可能无法产生足够的信息。至少你应该添加System.ServiceModel.Activation,可能还有一些与WIF相关的附加功能(我会添加System.Security)。

我使用STS并将java客户端与.net服务器集成时出现了类似的错误。 以下是我如何解决它。

  1. 为服务构建新客户端并将其连接到服务器。使用Fiddler监控消息
  2. 对当前客户端执行相同的操作
  3. 比较发送的消息。我知道你可以从WCF跟踪日志中获取它们,但我更喜欢fiddler。
  4. 我将跟踪与消息检查相结合的情况允许我找到错误(java客户端上的策略错误,以及服务自定义安全策略上的愚蠢代码错误)

    希望这有帮助!

    修改

    这是一个设置除system.servicemodel.activation之外的所有跟踪活动的链接。 它可能派上用场了

    http://msdn.microsoft.com/en-us/library/ee517292.aspx