我正在编写一个 JAXWS-RI 客户端,它必须调用使用 WS-Security 的 .NET Web 服务。该服务的 WSDL 不包含任何 WS-Security 信息,但我有来自该服务作者的示例肥皂消息,并且知道我必须包含 wsse:Security header ,包括 X:509 token 。
我一直在研究,并且看到过人们从 Axis 和 CXF(与 Rampart 和/或 WSS4J 结合)调用此类 Web 服务的示例,但没有看到关于使用普通 JAXWS-RI 本身的情况。然而,我(不幸的是)被我的政府客户限制使用 JAXWS-RI。有人有 JAXWS-RI 执行此操作的示例/文档吗?
我需要最终生成一个类似于下面的 SOAP header - 这是服务作者编写的来自 .NET 客户端的示例soap:header。 (注意:我已将“VALUE_HERE”字符串放在需要提供自己的值的位置)
<soapenv:Envelope xmlns:iri="http://EOIR/IRIES" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<soapenv: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">
<xenc:EncryptedKey Id="VALUE_HERE">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference>
<wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">
VALUE_HERE
</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>VALUE_HERE</xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#EncDataId-8"/>
</xenc:ReferenceList>
</xenc:EncryptedKey>
</wsse:Security>
最佳答案
尝试使用以下命令配置您的端口
com.sun.xml.ws.api.security.CallbackHandlerFeature
使用自定义实现
javax.security.auth.callback.CallbackHandler
接受
java.security.PrivateKey
和
java.security.cert.X509Certificate
您从类路径上的资源加载。我刚刚在这里写了一篇博客:http://upthescala.blogspot.com/2010/03/essential-sources-for-jax-ws-x509.html .
有关配置端口的示例(包括从文件加载私钥和 X.509 证书),请参阅 com.sun.xml.ws.commons.EC2(在上述博客条目中链接的源下载中) .
我会发布更多代码,但我没有带开发盒,所以我无法真正测试。
祝你好运!
关于java - 从 JAXWS-RI 调用 .NET Web 服务(WSE 3.0、WS-Security),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2366698/