wcf - 使用 STS 和 WCF 时遇到不安全或安全错误异常的问题

标签 wcf wif sts-securitytokenservice

我正在使用几个 WCF 服务,所有服务均使用 WIF 和 STS 提供程序进行保护(均使用开箱即用的 Microsoft 代码和示例)。这些服务都是使用 .NET 3.5 构建的,并且最近全部更新到 .NET 4.0。与服务相关的所有 .dll 也已更新至 4.0。这些服务多年来一直按原样运行,直到我更新框架版本。

现在的问题是,当调用由 STS WCF 服务保护的 WCF 服务时,在将 token 传递回调用由 STS 保护的 WCF 服务的客户端应用程序后,会生成错误:

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

HResult -2146233087

{"An error occurred when processing the security tokens in the message."}

Server stack trace: at System.ServiceModel.Channels.SecurityChannelFactory1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory1.SecurityRequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at MyProject.IMyService.GetInfo() at MyProject.Proxy.GetInfo() in c:\Projects\Proxy.cs:line 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 说的:“嘿,您已通过身份验证,我们通过了您并生成了 token ,现在我们就完成了!”看来调用客户端不喜欢该 token 。然而,这已经工作了很长时间,直到我更改了框架版本。据我所知,从 3.5 到 4.0,WIF 没有任何重大变化,但最大的变化是在 4.5 中,WIF 集成到了框架中。

所以所有授权都有效,只是我认为客户端接受 token 存在问题?

最佳答案

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

我在使用 STS 并将 java 客户端与 .net 服务器集成时遇到了非常类似的错误。 这是我解决这个问题的方法。

  1. 为该服务构建一个新客户端并将其连接到服务器。使用Fiddler监控消息
  2. 对当前客户端执行相同的操作
  3. 比较发送的消息。我知道您可以从 WCF 跟踪日志中获取它们,但我更喜欢 fiddler。

我的案例将跟踪与消息检查相结合,使我能够找到错误(Java 客户端上的策略错误,以及服务自定义安全策略上的愚蠢代码错误)

希望这有帮助!

编辑

这里是设置除 system.servicemodel.activation 之外的所有跟踪事件的链接。 可能会派上用场

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

关于wcf - 使用 STS 和 WCF 时遇到不安全或安全错误异常的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20378081/

相关文章:

c# - 如何在不重启的情况下生成服务模型元数据

c# - WCF + EF6 防止引用程序集中的枚举被序列化

c# - 配置和启动 WCF 服务时出现问题

c# - System.IdentityModel.Policy.IAuthorizationPolicy 过时了吗?

wcf - 使用安全 token 服务时的身份验证

java - 无法使用 IAM 用户的访问 key 代入第三方 AWS 账户的角色

c# - 传递大字节[]时WCF服务错误413 "Entity Too Large"

active-directory - ADFS 2.0 - 如何调试 "401 - Unauthorized"

asp.net-mvc - 如何将Azure ACS与本地(自定义)STS集成?

c# - 如何使 SecurityTokenServiceConfiguration 从 app.config 加载配置信息?