首页 > 解决方案 > Camel CXF 对调用者的响应消息 - 重复的 WS-Security 部件

问题描述

我定义了一个 Camel CxfEndpoint 服务。消息的接收工作正常,但我生成的响应/确认消息有问题。消息中的 WS-Security 部分/操作被保留,因此在响应中我有我自己的 WS-Security 部分(签名时间戳)以及来自调用者/原始消息的 WS-Security 部分。原始调用者不接受消息确认,我怀疑这是问题所在(我有他们的带有 BinarySecuritySessionToken 和我们自己的签名)。

尝试解决问题的骆驼路线相当简单:

from("myEndpoint")
    .transacted()
    .process(new PreProcessor())
    .to("mock:end")

我已将路线中的 Camel CxfEndpoint 定义为:

CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setAddress("http://0.0.0.0:8888/services/Service");
cxfEndpoint.setWsdlURL("Service.wsdl");
cxfEndpoint.setCamelContext(camelContext);
....

问题示例时间戳:

<wsu:Timestamp wsu:Id="TS-6757512FE17DCDC903153191998160526">                                   
  <wsu:Created>2018-07-18T13:19:41.605Z</wsu:Created>
  <wsu:Expires>2018-07-18T13:24:41.605Z</wsu:Expires>                                           
</wsu:Timestamp>
<u:Timestamp xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" u:Id="uuid-b2a1c0b2-8263-4afc-bc99-f8a46da80ce7-693">
  <u:Created>2018-07-18T13:19:42.905Z</u:Created>
  <u:Expires>2018-07-18T13:24:42.905Z</u:Expires>
</u:Timestamp>

响应消息的一般结构似乎很好,但我需要从消息中剥离 WS-Security Action Parts。有没有办法剥离这些部分或者我需要构建一个全新的消息?如果您需要更多信息,请告诉我,谢谢。

标签: javaapache-camelcxf

解决方案


所以我通过添加另一个拦截器来删除安全标头来修复它。我想知道这是否是一种可接受的方法,或者是否有更好的解决方案。

public class RemoveSecurityHeadersOutInterceptor extends AbstractSoapInterceptor
{    
  public RemoveSecurityHeadersOutInterceptor(String phase) {
    super(Phase.PRE_PROTOCOL);
  }

public void handleMessage(SoapMessage message) throws Fault
{
  List<Header> headers = message.getHeaders(); 
  headers.removeIf(h -> h.getName().getLocalPart().equals("Security"));
  }
}

推荐阅读