Java CXF生成的WSDL不';不包含WS-SecurityPolicy定义

Java CXF生成的WSDL不';不包含WS-SecurityPolicy定义,java,soap,jax-ws,cxf,ws-security,Java,Soap,Jax Ws,Cxf,Ws Security,我想使用WS-Security来保护我的web服务。我使用CXF公开我的端点,并使用Java代码生成WSDL(也称为CXF代码优先服务) 本教程解释在手动管理WSDL时如何将WS-Security与CXF结合使用: 但是,我使用CXF自动生成WSDL生成的WSDL并不表示客户端应该使用WS-Security。我希望WSDL中有类似的内容: <wsp:Policy wsu:Id="UsernameToken" xmlns:wsu= "http://docs.oasis-open.org/w

我想使用WS-Security来保护我的web服务。我使用CXF公开我的端点,并使用Java代码生成WSDL(也称为CXF代码优先服务)

本教程解释在手动管理WSDL时如何将WS-Security与CXF结合使用:

但是,我使用CXF自动生成WSDL生成的WSDL并不表示客户端应该使用WS-Security。我希望WSDL中有类似的内容:

<wsp:Policy wsu:Id="UsernameToken" xmlns:wsu=
 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
  xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
  xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
<wsp:ExactlyOne>
  <wsp:All>
    <sp:TransportBinding/>
    <sp:SupportingTokens>
      <wsp:Policy>
        <sp:UsernameToken sp:IncludeToken=".../IncludeToken/AlwaysToRecipient"/>
      </wsp:Policy>
    </sp:SupportingTokens>
  </wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>

我没有使用Spring,但我使用了嵌入式Jetty。以下是我连接所有内容的方式:

CXFNonSpringServlet cxfServlet = new CXFNonSpringServlet() {
  private static final long serialVersionUID = 1L;

  @Override
  protected void loadBus(ServletConfig sc) {
    super.loadBus(sc);

    Map<String, Object> inProps = new HashMap<String, Object>();
    inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    inProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    inProps.put(WSHandlerConstants.PW_CALLBACK_REF, new TestCallback());

    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new MyServiceEndpointImpl());
    factory.setAddress("/myservice");
    factory.getInInterceptors().add(new WSS4JInInterceptor(inProps));
    factory.create();
  }
};

Server server = new Server(8080);
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletContextHandler rootContext = new ServletContextHandler(contexts, "/");
rootContext.addServlet(new ServletHolder(cxfServlet), "/soap/*");
server.start();
CXFNonSpringServlet cxfServlet=new CXFNonSpringServlet(){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void加载总线(ServletConfig sc){
超级负载总线(sc);
Map inProps=newhashmap();
inProps.put(WSHandlerConstants.ACTION,WSHandlerConstants.USERNAME\u令牌);
inProps.put(WSHandlerConstants.PASSWORD\u类型,WSConstants.PW\u文本);
inProps.put(WSHandlerConstants.PW_CALLBACK_REF,new TestCallback());
JaxWsServerFactoryBean工厂=新的JaxWsServerFactoryBean();
工厂.立波士(公共汽车);
setServiceBean(新的MyServiceEndpointImpl());
factory.setAddress(“/myservice”);
factory.getInInterceptors().add(新的WSS4JInInterceptor(inProps));
factory.create();
}
};
服务器=新服务器(8080);
ContextHandlerCollection contexts=新建ContextHandlerCollection();
setHandler(上下文);
ServletContextHandler rootContext=新的ServletContextHandler(上下文“/”;
addServlet(新的servlet持有者(cxfServlet),“/soap/*”;
server.start();

现在不支持它

注意:此时,WS-SecurityPolicy支持仅适用于“WSDL优先”场景。WS-SecurityPolicy片段只能从WSDL中提取。将来,我们还计划启用各种代码优先的场景,但目前只有WSDL优先可用

有人在这里解释了同样的问题,并用@Policy公开了一个解决方案。但是,CXF的解决方案很难实现