【问题标题】:CXF generated WSDL doesn't contain WS-SecurityPolicy definitionCXF 生成的 WSDL 不包含 WS-SecurityPolicy 定义
【发布时间】:2011-10-13 13:18:58
【问题描述】:

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

本教程解释了在手动管理 WSDL 时如何将 WS-Security 与 CXF 一起使用:http://www.ibm.com/developerworks/java/library/j-jws13/index.html

但是,我使用 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();

【问题讨论】:

    标签: java soap jax-ws cxf ws-security


    【解决方案1】:

    目前不支持。

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

    http://cxf.apache.org/docs/ws-securitypolicy.html

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

    http://cxf.547215.n5.nabble.com/WS-Security-policy-in-wsdl-for-java-first-approach-td569052.html

    复制问题现已修复,将在 2.4.2 中发布(请参阅https://issues.apache.org/jira/browse/CXF-3668

    【讨论】:

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