Java CXF错误:需要声明加密用户名

时间:2017-03-28 16:09:21

标签: java

我有一个java Web服务客户端,它是针对用.NET WCF编写的服务的新版WSDL编译的。当我们尝试执行客户端发送测试请求和响应时,我们遇到错误:

 Mar 28, 2017 3:30:10 PM org.apache.cxf.phase.PhaseInterceptorChain 
 doDefaultLogging WARNING: Interceptor for 
 {http://EMVS.EU/20161/}ProductService#
 {http://EMVS.EU/20161/}ProcessProductServiceSubscription has thrown 
 exception, unwinding now
 org.apache.cxf.ws.policy.PolicyException: A encryption username needs to be 
 declared.
    at org.apache.cxf.ws.security.wss4j.policyhandlers.AbstractBindingBuilder.policyNotAsserted(AbstractBindingBuilder.java:315)
    at org.apache.cxf.ws.security.wss4j.policyhandlers.AbstractBindingBuilder.setEncryptionUser(AbstractBindingBuilder.java:1643)
    at org.apache.cxf.ws.security.wss4j.policyhandlers.AsymmetricBindingHandler.doEncryption(AsymmetricBindingHandler.java:432)
    at org.apache.cxf.ws.security.wss4j.policyhandlers.AsymmetricBindingHandler.doEncryptBeforeSign(AsymmetricBindingHandler.java:272)
    at org.apache.cxf.ws.security.wss4j.policyhandlers.AsymmetricBindingHandler.handleBinding(AsymmetricBindingHandler.java:96)
    at org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:176)
    at org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:90)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:572)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:481)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:136)
    at com.sun.proxy.$Proxy61.processProductServiceSubscription(Unknown Source)
    at DemoOrganisation.emvs.client.ProductServiceMAHTester.sendProcessProductServiceSubscriptionMessage(ProductServiceMAHTester.java:403)
    at DemoOrganisation.emvs.client.ProductServiceMAHClient.main(ProductServiceMAHClient.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:291)
    at java.lang.Thread.run(Thread.java:745)

似乎在抱怨clientdotnet.properties文件中的以下属性: mah.enc.alias = 12345678901234567890

这指向密钥存储区中的加密证书。

当我们运行maven构建以使用2013版本的WSDL合同测试Web服务客户端时,现有属性可以正常工作。但是它不适用于2016年最新版本的重新生成的类!

我试图了解邮件正在寻找的属性。根据CXF文档,我们可以将加密用户名的属性添加到spring客户端xml,如下所示:

<jaxws:client name="{http://cxf.apache.org}MyPortName"
  createdFromAPI="true">
  <jaxws:properties>
     <entry key="security.callback-handler"
         value="interop.client.KeystorePasswordCallback"/>
     <entry key="security.signature.properties"
         value="etc/client.properties"/>
     <entry key="security.encryption.properties"
         value="etc/service.properties"/>
     <entry key="security.encryption.username"
         value="servicekeyalias"/>
  </jaxws:properties>

但是当我查看我们的弹簧文件时,我只能看到:

<jaxws:client address="#{systemProperties['mah.epurl']}"
        name="{http://EMVS.EU/20161/}CustomBinding_IProductServiceMahV20161"
        createdFromAPI="true"/>

属性都在名为的文件中定义: clientDotNet.properties

此致

Romeel

1 个答案:

答案 0 :(得分:0)

很可能是因为您没有在创建Web服务客户端的端口的上下文中设置以下属性:

  • WS-security.encryption.username
  • ws-security.encryption.properties
  • WS-security.username
  • ws-security.password
  • WS-security.signature.username
  • ws-security.signature.properties
  • WS-security.callback处理程序

我遇到了同样的问题,我设置了上面的属性和webservice的客户端代码。