【问题标题】:How to create a .NET client for a wso2 Secure Token Service如何为 wso2 安全令牌服务创建 .NET 客户端
【发布时间】:2014-11-10 09:29:47
【问题描述】:

我需要为 wso2 安全令牌服务创建一个 .NET 客户端。

通常我会创建一个简单的控制台或 WinForm 项目,向其添加服务引用。公开的 WSDL 将转换为一组类,我可以使用这些类来查询服务并正确管理其响应。

不幸的是,生成的请求和响应类是空的:只是没有任何属性或方法的类声明。这类似于另一个(未回答的)堆栈溢出问题 https://stackoverflow.com/q/22049080/2131913

中描述的行为

我在此论坛帖子中找到了该服务的示例请求:http://cxf.547215.n5.nabble.com/Sample-STS-Client-tp4643980p4664175.html,我使它与 SOAP UI 一起使用。

是否有适当的并且可能是自动化的方法来重新创建查询安全令牌服务所需的复杂数据结构?

编辑

好的,经过多次尝试,我已将上述论坛帖子中的 SOAP 请求减少到仍能从 STS 服务获取 RequestSecurityTokenResponse 所需的最小结构。

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <wsse:UsernameToken wsu:Id="UsernameToken-6D35592DCDDA26FFF3141578725699577">
        <wsse:Username>USERNAME HERE</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD HERE</wsse:Password>
      </wsse:UsernameToken>
      <wsu:Timestamp wsu:Id="TS-6D35592DCDDA26FFF3141578725699576">
        <wsu:Created>2014-11-12T10:14:16.995Z</wsu:Created>
        <wsu:Expires>2014-11-12T10:16:16.995Z</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
    <wsa:Action soap:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT</wsa:Action>
    <wsa:MessageID soap:mustUnderstand="1">uuid:6d4eab69-77f9-42b7-8d6b-1f710020fb0b</wsa:MessageID>
    <wsa:To soap:mustUnderstand="1">STS ENDPOINT ADDRESS HERE</wsa:To>
  </soap:Header>
  <soap:Body>
    <wst:RequestSecurityToken xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust">
      <wst:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</wst:RequestType>
      <wst:TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</wst:TokenType>
      <wst:Claims>
        <wsid:ClaimType Uri="http://wso2.org/claims/userid" xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity"/>
      </wst:Claims>
    </wst:RequestSecurityToken>
  </soap:Body>
</soap:Envelope>

我在项目的 app.config 中定义了一个单一的 wsHttpBinding,如下所示:

  <wsHttpBinding>
    <binding name="SendUsername"  messageEncoding="Text">
      <security mode ="TransportWithMessageCredential">
        <message clientCredentialType ="UserName"/>
        <transport clientCredentialType ="Basic" />
      </security>
    </binding>
  </wsHttpBinding>

添加或不添加 CustomBinding,如下所示:

<customBinding>
     <binding name="wso2carbon-stsSoap12Binding">
      <security defaultAlgorithmSuite="Default" authenticationMode="IssuedToken"
        requireDerivedKeys="true" securityHeaderLayout="Lax" includeTimestamp="true">
        <localClientSettings detectReplays="false" />
        <localServiceSettings detectReplays="false" />
        <issuedTokenParameters keyType ="SymmetricKey" tokenType ="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0">
          <issuer address =STS ENDPOINT ADDRESS HERE binding ="wsHttpBinding" bindingConfiguration ="SendUsername"/>
          <claimTypeRequirements>
            <add claimType ="http://wso2.org/claims/userid"/>
          </claimTypeRequirements>
        </issuedTokenParameters>
      </security>
      <textMessageEncoding messageVersion="Soap12" />
      <httpsTransport />
    </binding>
  </customBinding>

然而,在这两种情况下,请求都会引发超时异常,并且使用 WCF 跟踪发出的请求进行检查,我可以看到它缺少 Claims 元素。有什么提示吗?

【问题讨论】:

    标签: vb.net wcf wso2 soapui wso2is


    【解决方案1】:

    【讨论】:

    • 感谢您的链接,但他们无法帮助我有两个原因。第一个是我无权访问服务配置,第二个是示例是 Java 的,我需要一个 .NET 客户端
    【解决方案2】:

    在使用 WCF 配置选项挣扎了很多天之后,我取得了部分成功。

    让我从安全令牌服务获得响应的关键是我意识到,从长远来看,我需要在联合安全场景中操作。我不需要令牌本身,但我需要它来获得对其他服务进行身份验证的方法。

    考虑到这个选项,我开始探索 WCF 必须为这种场景提供什么,并构建了以下配置选项:

      <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 address here --> binding ="customBinding" bindingConfiguration ="StsBinding"/>
              <claimTypeRequirements>
                <add claimType="http://wso2.org/claims/userid" />
              </claimTypeRequirements>
            </message>
          </security>
        </binding>
      </wsFederationHttpBinding>
    

    上述绑定用于联系需要令牌认证的服务,而以下添加了有关如何联系安全令牌颁发者的进一步说明:

      <customBinding>
        <binding name="StsBinding">
          <textMessageEncoding messageVersion="Soap12WSAddressingAugust2004"/>
          <useManagedPresentation/>
          <security authenticationMode="UserNameOverTransport" includeTimestamp ="true" keyEntropyMode ="ServerEntropy" securityHeaderLayout ="Lax"   
                    messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" >
          </security>
          <httpsTransport authenticationScheme ="Basic"/>
        </binding>
      </customBinding>
    

    使用此配置,并在 Fiddler 和 WCF 跟踪的帮助下,我可以看到我从 STS 颁发者那里获得了安全令牌响应。

    但是,正如我所说,在开始时,这只是部分成功,因为 WCF 基础架构在处理令牌时说它有错误的操作......但这可能是另一个问题的主题 ;-)

    我希望这可以被认为是一个有效的答案,尽管我对令牌身份验证的追求尚未结束

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多