3

我正在寻找一些关于在使用如下 WCF 绑定进行消息交换期间实际用户名 + 密码(凭据)存储位置的技术细节。

<bindings>
    <wsHttpBinding>
        <binding name="wsHttp">
            <security mode="TransportWithMessageCredential">
                <transport/>
                <message clientCredentialType="UserName" 
                         negotiateServiceCredential="false" 
                         establishSecurityContext="true" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

然后在客户端应用程序中,我调用此服务传递一组有效的凭据,如下所示

using (SupplierServiceClient client = new SupplierServiceClient()) {
            client.ClientCredentials.UserName.UserName = "admin";
            client.ClientCredentials.UserName.Password = "password";

            SupplierList = client.GetSupplierCollection();
}

起初,我假设 WCF 正在获取这些数据并将其放入 SOAP 标头中,但从 WSDL 中看起来并不是这样……有什么帮助吗?

编辑

以下是客户端的安全配置在生产中的样子

<security mode="TransportWithMessageCredential">
    <transport clientCredentialType="None" />
    <message clientCredentialType="UserName" establishSecurityContext="false" />
</security>
4

2 回答 2

3

通过设置 UserNameCredentials,您实际上是在利用 Username Token Profile。这会导致将令牌作为 SOAP 标头添加到消息中。SOAP 标头看起来像这样:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
        xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <env:Header>
        <wsse:UsernameToken>
            <wsse:Username>jdoe</wsse:Username>
            <wsse:Password>passw0rd</wsse:Password>
            <wsse:Nonce><!-- optional nonce here --></wsse:Nonce>
        </wsse:UsernameToken>
    </env:Header>
    <env:Body>
        <!-- body here -->
    </env:Body>
</env:Envelope>

现在,我不确定您为什么要提到 WSDL。令牌不会出现在 WSDL 中,尽管 WSDL 应该包含有关操作的正确 WS-Policy 注释。这将使 WSDL 的使用者发现他们实际上需要将 UsernamePasswordToken 发送到请求中。

最后,有人提出了 RequestSecurityToken (RST),但如果您只是使用简单的 UsernameToken 身份验证,则不应该(不需要)涉及 RST。唯一需要涉及 RST 的情况是,如果您正在使用 WS-Trust 与安全令牌服务器 (STS) 进行令牌交换。

于 2009-10-28T23:00:08.503 回答
0

以下是示例 SOAP 消息的样子:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
    <a:MessageID>urn:uuid:01d3a7d2-dc5a-42cf-acf0-3dd6bd50230e</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">http://localhost:9999/Service1.svc</a:To>
  </s:Header>
  <s:Body>
    <t:RequestSecurityToken Context="uuid-7c240c06-c14b-42af-82dd-10f44f423928-1" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
      <t:TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</t:TokenType>
      <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
      <t:KeySize>256</t:KeySize>
      <t:BinaryExchange ValueType="http://schemas.xmlsoap.org/ws/2005/02/trust/spnego" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">YGsGBisGAQUFAqBhMF+gJDAiBgorBgEEAYI3AgIKBgkqhkiC9xIBAgIGCSqGSIb3EgECAqI3BDVOVExNU1NQAAEAAAC3shjiBgAGAC8AAAAHAAcAKAAAAAUBKAoAAAAPU0cyMjA1Nk1BVE1VVA==</t:BinaryExchange>
    </t:RequestSecurityToken>
  </s:Body>
</s:Envelope>
于 2009-10-28T14:04:34.633 回答