java - 403 禁止将 wss4jOutInterceptor 与 Camel 和 cxf 一起使用

标签 java apache-camel cxf wss4j

首先要做的事情:

  • 与 Camel 和 cxf 的 war (尝试了最新版本,实际上分别尝试了 2.12.0 和 2.7.6)。
  • 一个简单的 Camel 路线,没有过程,只是从 - 日志 - 到。
  • 最终目标是将 WS-Security 添加到 SOAP 消息。

配置:

应用程序上下文.xml

<!-- Import for camel config and beans -->    
<import resource="./cxf-beans-testws.xml" />
<import resource="./camel-testws.xml" />

Camel -testws.xml

<!-- CAMEL CONTEXT -->
<camelContext id="camelContextTest" xmlns="http://camel.apache.org/schema/spring">
    <!-- CAMEL ROUTE -->
    <route id="TestWSRoute">
        <description>
            Camel route for testws
        </description>
        <from uri="cxf:bean:serviceTestProvider" />
        <log message="Process" loggingLevel="DEBUG" />
        <to uri="cxf:bean:serviceTestClient" />
    </route>
</camelContext>

cxf-beans-testws.xml(只是相关部分)

<bean id="wss4JOutInterceptorRea" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
    <constructor-arg>
        <map>
            <entry key="action" value="Encrypt Signature"/>
            <entry key="useSingleCertificate" value="true" />
            <entry key="user" value="xxxx" />
            <entry key="signaturePropRefId" value="signaturePropertiesBean" />
            <entry key="signaturePropertiesBean" value-ref="signaturePropertiesTest" />
            <entry key="signatureUser" value="${test.signature.certificate.alias}" />
            <entry key="passwordCallbackRef" value-ref="clientCallbackTest" />
            <entry key="signatureAlgorithm" value="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
            <entry key="signatureKeyIdentifier" value="DirectReference" />
            <entry key="signatureParts" value="{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body" />
            <entry key="encryptionUser" value="${test.encryption.certificate.alias}" />
            <entry key="encryptionPropRefId" value="encryptionPropertiesBean" />
            <entry key="encryptionPropertiesBean" value-ref="encryptionPropertiesTest" />
        </map>
    </constructor-arg>
</bean>

当我调用公开的 Web 服务 (serviceTestProvider) 时,将出现 SOAP 消息、出现日志并放置 WSS 配置。然后消息被发送到endPoint...并且总是返回:

HTTP response '403: Forbidden' when communicating with http://...

如果我删除 wss4jOutInterceptor,则响应是没有 wss 安全性(预期响应)。

但是,如果我将日志级别设置为 DEBUG,则在所有拦截器链处理之后从日志中取出出站消息,并从 REST 控制台或 SoapUI 手动发送它...然后工作正常,没有 403。所以看起来消息格式良好。这两个调用都是从同一台计算机发出的,没有代理或类似的代理。

2016-06-17 08:59:12 INFO  WSTestCXFService:234 - Outbound Message
---------------------------
ID: 4
Address: http://correct-ws-url
Http-Method: POST
Content-Type: text/xml;charset=UTF-8
Headers: {Accept=[text/xml;charset=UTF-8], accept-encoding=[gzip,deflate], breadcrumbId=[ID-MACHINENAME-55387-1466145154908-1-4], Cache-Control=[No-Cache], Connection=[Keep-Alive], host=[correct-host], SOAPAction=[method], User-Agent=[Apache-HttpClient/4.1.1 (java 1.5)]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1">...</wsse:Security></SOAP-ENV:Header><soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-5"><xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="ED-4" Type="http://www.w3.org/2001/04/xmlenc#Content">...</xenc:EncryptedData></soap:Body></soap:Envelope>

没有 https,只有 http 端点。尝试使用管道添加 header 以匹配 REST 控制台或 SoapUI 原始消息,但没有成功。有什么猜测吗?

最佳答案

最后,这是 Windows/网络问题。几天后(2-3),根本没有任何变化......它开始工作。

关于java - 403 禁止将 wss4jOutInterceptor 与 Camel 和 cxf 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37875327/

相关文章:

java - 调用对象中的方法?

java - 什么是 NullPointerException,我该如何解决?

java - 使用 CXF JAX-RS 下载多个文件

java - 从 cxf 消息中获取 Http 请求正文

java - 我能知道 JBoss 在运行时使用了多少内存吗?

java - 如果 JMeter 中的 While Controller 中的 Controller

java - Apache camel 和 kafka 集成

java - 使用 Apache Camel 和 spring-ws 组件调用基于 SOAP 的服务

jms - 从 Camel Route 向 Weblogic JMS 队列发送消息

java - JAX-RS 与 CXF 不使用 Spring