2009-10-28 46 views
3

我正在寻找一些技术细节,在使用像下面这样的WCF绑定进行消息交换期间,实际用户名和密码(证书)的存储位置。WCF消息证书实现细节

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

然后客户端应用程序中我把这种服务通过一组有效的creds像这样

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> 

回答

3

通过设置UserNameCredentials,您实际上可以利用用户名令牌配置文件。这会导致将令牌作为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 annontations。这将让WSDL的消费者发现他们实际上需要将UsernamePasswordToken发送到请求。

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

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> 
+0

优秀 - 所以在“请求安全令牌”下的身体中,您是否还会看到用户名+密码或? –

+0

我不确定RequestSecurityToken与这个有关UsernameTokens ...的问题有什么关系? –

+0

这只是用于建立安全上下文的WS-Trust握手的第一部分(请求)。你可以在这里阅读更多关于它的细节:http://specs.xmlsoap.org/ws/2005/02/trust/ws-trust.pdf –