CXF Web服务客户端不对SOAP请求XML消息进行加密
我正在学习Web服务安全性。我正在使用CXF框架。我已经开发了一个测试服务,它将使我们发送的任何数据的价值翻倍。基于本教程CXF Web服务客户端不对SOAP请求XML消息进行加密
我已经添加了用于XML加密和签名的WS-Policy。
然后我开发了这个服务的Web服务客户端作为使用CXF的eclipse项目。 以下是我的客户端配置文件
<jaxws:client id="doubleItClient" serviceClass="com.DoubleIt" address="http://localhost:8080/myencws/services/DoubleItPort?wsdl">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
<jaxws:properties>
<entry key="ws-security.callback-handler" value="com.ClientKeystorePasswordCallback"/>
<entry key="ws-security.encryption.properties" value="com/clientKeystore.properties"/>
<entry key="ws-security.signature.properties" value="com/clientKeystore.properties"/>
<entry key="ws-security.encryption.username" value="myservicekey"/>
</jaxws:properties>
我已经生成的所有密钥库文件,我创建了clientKeystore.properties文件,并放在我的项目的src目录。
但是,每当我运行这个客户端SOAP请求消息未加密。所以客栈服务器端我得到异常喜欢
这些政策方案不能满足: {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702} EncryptedParts和 {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}和SignedParts
以下是我的SOAP请求
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:doubleValue
xmlns:ns2="http://com/"><arg0>5</arg0></ns2:doubleValue></soap:Body></soap:Envelope>
我正在使用CXF2.7.3。我不知道什么是错的。请帮帮我。
我有一个类似的问题,我的代码之前,缺少什么是jar的依赖关系,当您的客户端从WSDL读取安全策略时进行实际加密。
我的修补程序是在您的POM中添加某些Maven依赖项以启用加密。检查这个网址:http://cxf.apache.org/docs/using-cxf-with-maven.html
又读“启用WS-安全”一节中的URL http://cxf.apache.org/docs/ws-securitypolicy.html
我希望这有助于
确保您使用的是正确的库。尽量只包括CXF包,删除其他CXF依赖 如果您正在使用Maven,这样的事情:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.18</version>
</dependency>
它不工作。我添加了所有必需的jar,例如cxf-rt-frontend-jaxws-2.7.3,cxf-rt-ws-policy-2.7.3,cxf-rt-ws-security-2.7.3。但仍然是同样的问题。 – Dilip 2013-03-25 07:05:58
尝试启用CXF日志记录,请点击此处http://cxf.apache.org/docs/debugging-and-logging.html#DebuggingandLogging-UsingLog4jInsteadofjava.util.logging 日志可能会给你一个提示。 – slbb 2013-03-25 11:19:53
我实际上使用JBoss,我用这篇文章作为参考https://docs.jboss.org/author/display/JBWS/WS-Security 另外,我注意到你没有“ws-security.signature”。用户名“在您的下巴:客户端属性。 – slbb 2013-03-25 11:31:15