2014-11-21 101 views
0

這個問題接收的令牌是一種的跟進這個:How to create a .NET client for a wso2 Secure Token ServiceWCF錯誤處理來自安全令牌服務

簡單地說,我想實現一個客戶端在聯邦安全方案的網絡服務。我的客戶端應該調用給定Web服務的方法,使用另一個Web服務提供的安全令牌對自身進行身份驗證(兩種服務都使用wso2平臺實現)。

正如我在上述問題的答案中所述,通過正確的綁定配置,客戶端能夠接收請求的令牌。以下是我綁定配置:

<wsFederationHttpBinding> 
    <binding name="fs"> 
     <security mode="TransportWithMessageCredential"> 
     <message issuedKeyType="SymmetricKey" issuedTokenType ="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0"> 
      <issuer address =<!-- STS URL HERE--> binding ="customBinding" bindingConfiguration ="StsBinding"/> 
      <claimTypeRequirements> 
      <add claimType="http://wso2.org/claims/userid" /> 
      </claimTypeRequirements> 
     </message> 
     </security> 
    </binding> 
    </wsFederationHttpBinding> 
    ... 
    <customBinding> 
    <binding name="StsBinding"> 
     <textMessageEncoding messageVersion="Soap12WSAddressing10"/> 
     <useManagedPresentation/> 
     <security authenticationMode="UserNameOverTransport" includeTimestamp ="true" keyEntropyMode ="ServerEntropy" securityHeaderLayout ="Lax" 
       messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" > 
     </security> 
     <httpsTransport authenticationScheme ="Basic"/> 
    </binding> 
    </customBinding> 

然而,當我的客戶過程中收到令牌失敗與SecurityNegotiationException,指出「甕:IssueTokenResponse」行動是錯誤的。這個例外是什麼意思?應該採取什麼正確的行動?

我無法訪問這兩種服務的任何細節,所以我需要知道我是否只能在客戶端執行某些操作。

我曾試圖按照包含在該論壇上發帖https://social.msdn.microsoft.com/Forums/vstudio/en-US/6c838f7e-f72f-4fdd-827d-b29c61522aa0/wrong-action-httpdocsoasisopenorgwssxwstrust200512rstrissue?forum=wcf的建議,但我不認爲它適用於我的情況,因爲沒有一個單一的messageSecurityVersion值似乎工作

回答

0

我終於找到工作解決方案,至少對於「錯誤行爲」錯誤。

通過WCF文檔挖我發現說明如何建立一個安全令牌服務(MSDN address here

參考文件

文件的最intresting的部分是這個小短語,似乎表明了預期的作用由STS發送的響應:

另外,它定義了關聯的動作統一資源 標識符(URI)。與 RequestSecurityToken消息關聯的動作URI是 http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue。與RequestSecurityTokenResponse消息相關聯的動作URI 是 http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue

由WCF框架,我發現約IClientMessageInspector一個有前途的參考,允許自定義客戶端行爲發送請求,或者接收應答時,當所提供的extensbility機制提出了一些進一步的研究之後。

以下是行爲的簡單代碼:

Public Class ChangeReplyActionMessageInspector 
    Implements IClientMessageInspector 

    Public Sub AfterReceiveReply(ByRef reply As Message, correlationState As Object) Implements IClientMessageInspector.AfterReceiveReply 
     If reply.Headers.Action = "urn:IssueTokenResponse" Then 
      reply.Headers.Action = "http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue" 
     End If 
    End Sub 

    Public Function BeforeSendRequest(ByRef request As Message, channel As ServiceModel.IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest 
     Return Nothing 
    End Function 
End Class 

附上這個自定義行爲負責交談的安全令牌服務的客戶對象,我需要一個IEndpointBehavior像這樣的:

Public Class ChangeReplyActionEndpointBehavior 
    Implements IEndpointBehavior 

    Public Sub AddBindingParameters(endpoint As ServiceEndpoint, bindingParameters As BindingParameterCollection) Implements IEndpointBehavior.AddBindingParameters 

    End Sub 

    Public Sub ApplyClientBehavior(endpoint As ServiceEndpoint, clientRuntime As ClientRuntime) Implements IEndpointBehavior.ApplyClientBehavior 
     clientRuntime.ClientMessageInspectors.Add(New ChangeReplyActionMessageInspector) 
    End Sub 

    Public Sub ApplyDispatchBehavior(endpoint As ServiceEndpoint, endpointDispatcher As EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior 

    End Sub 

    Public Sub Validate(endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate 

    End Sub 
End Class 

它是編程方式連接到客戶端用下面的代碼:

Dim endpointBehaviorCollection As New System.Collections.Generic.KeyedByTypeCollection(Of IEndpointBehavior) 
    endpointBehaviorCollection.Add(New ChangeReplyActionEndpointBehavior) 
    client.ClientCredentials.IssuedToken.IssuerChannelBehaviors.Add(New Uri("STS URL HERE"), endpointBehaviorCollection) 

以這種方式,發出的安全令牌被髮送回具有最終請求的目標服務。儘管如此,我仍然在爲最終請求發現錯誤,但需要進一步調查。