【问题标题】:CXF Web service client not encrypting the SOAP Request XML messageCXF Web 服务客户端未加密 SOAP 请求 XML 消息
【发布时间】:2013-03-22 12:35:25
【问题描述】:

我正在学习 Webservice 安全性。我正在为此使用 CXF 框架。我开发了一项测试服务,无论我们发送什么,它都会使价值翻倍。基于本教程

我已经为 XML 加密和签名添加了 WS-Policy。

然后,我使用 CXF 将此服务的 Web 服务客户端开发为 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>

我已经生成了所有的keystore文件,我创建了clientKeystore.properties文件并放在了我项目的src目录中。

但是每当我运行这个客户端时,SOAP 请求消息都没有加密。所以旅馆服务器端我得到了像

这样的异常

无法满足以下备选政策: {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}加密部分 {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。我不知道怎么了。请帮帮我。

【问题讨论】:

    标签: cxf xml-encryption


    【解决方案1】:

    我之前的代码也有类似的问题,缺少的是当您的客户端从 WSDL 读取安全策略时执行实际加密的 jar 依赖项。

    我的解决方法是在您的 POM 中添加某些 maven 依赖项以启用加密。检查这个网址:http://cxf.apache.org/docs/using-cxf-with-maven.html

    另请阅读 url http://cxf.apache.org/docs/ws-securitypolicy.html 中的“启用 WS-SecurityPolicy”部分

    希望对你有帮助

    【讨论】:

    • 它不工作。我已经添加了所有必要的 jar,例如 cxf-rt-frontend-jaxws-2.7.3、cxf-rt-ws-policy-2.7.3、cxf-rt-ws-security-2.7.3。但仍然是同样的问题。
    • 尝试启用 CXF 日志记录,查看这里cxf.apache.org/docs/… 日志可能会给您提示。
    • 我实际上使用的是 JBoss,我使用这篇文章作为参考 docs.jboss.org/author/display/JBWS/WS-Security 另外,我注意到您的下巴:客户端属性中没有“ws-security.signature.username”。跨度>
    【解决方案2】:

    确保您使用的是正确的库。尝试仅包含 cxf 包,删除其他 cxf 依赖项 如果您使用的是 maven,则如下所示:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle</artifactId>
        <version>2.7.18</version>
    </dependency>
    

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,经过大量实验,以下指南每次都有帮助。

      1. 构建您的 cxf 客户端配置 xml 以导入 META-INF cxf.xml。
      2. 定义 cxf 总线功能(用于记录)
      3. 定义 http 管道(如果需要 TLS 握手等)
      4. jaxws:名称属性为 {targetNameSpaceWSDL)/PortName 且 createdFromAPI=true 和 abstract=true 的客户端 bean
      5. 使客户端标签包含 jaxws 功能。请记住使用最新的“安全”而不是“ws-security”
      6. 在你的java客户端类中,使用SpringBus加载cxf客户端配置xml.SVN Link for SpringBus Client Config
      7. 确保 WS 策略处理所需的所有依赖项都存在于类路径中,如 cxf-rt-ws-policy 和 cxf-rt-ws-security.jar 以及 bouncycastle 提供程序(如果需要)

      注意: security.signature.properties 和 security.encryption.properties 也可以外化,直接用 xml 值中的绝对路径引用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多