WebSphere Liberty中的SOAP客户端代理的基本身份验证

时间:2018-07-31 14:55:16

标签: http authentication client jax-ws websphere-liberty

我们正在尝试在以前在WebSphere Application Server 7上运行过的WebSphere Liberty上部署EAR。该应用程序调用外部SOAP服务。服务的WSDL使用http:BasicAuthentication xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http"/

定义了wsp:Policy

部署后,当我们向应用程序发送请求时,这将触发该SOAP调用,因此会出现错误:

None of the policy alternatives can be satisfied.

此外,我们收到以下警告:

[WARNING ] No assertion builder for type {http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication registered.

server.xml文件已添加此功能:

<feature>wsSecurity-1.1</feature>

服务获取

public IServiceFacade getBasicHttpBindingIServiceFacade() {
        return super.getPort(new QName("http://tempuri.org/", "BasicHttpBinding_IService"), IServiceFacade.class);
    }

我们以前在WAS 7上将基本身份验证设置如下:

  IServiceFacade proxy = service.getBasicHttpBindingIServiceFacade();
            Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext();
            ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

            /* Basic authentication */
            requestContext.put(BindingProvider.USERNAME_PROPERTY, user);
            requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);

以下代码已在WAS 7上运行,但在Liberty上失败。

更新1

这里的问题似乎是我们无法从内部自由提供的cxf客户端依赖项中访问cxf ClientProxy。经过一番挖掘,我发现自由不会暴露这些库。唯一的解决方案是,我需要排除jaxws-2.2并自己提供所有必需的依赖项,但是结果,我失去了自由提供的所有与jax-ws的内置功能。<​​/ p>

https://developer.ibm.com/answers/questions/236182/how-can-i-access-the-libertys-jaxrs-20-apache-cxf/

更新2

在提供了我自己的cxf jar并从Liberty中排除了jaxws-2.2功能之后。现在,我可以使用 ClientProxy(proxy).getConduit()来访问HTTPConduit。但是,现在的问题似乎是CXF不支持提供程序:http://schemas.microsoft.com/ws/06/2004/policy/http

它引发以下错误: DEBUG org.apache.cxf.ws.policy.PolicyEngineImpl - Alternative {http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication is not supported

我在pom上添加了以下部门:

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-client</artifactId>
      <version>3.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>3.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>3.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-ws-security</artifactId>
      <version>3.2.0</version>
    </dependency>

我也尝试添加以下内容,但是没有运气:

Endpoint endpoint = client.getEndpoint()
endpoint.getOutInterceptors().add(new WSS4JOutInterceptor())

更新3

在IBM支持人员的帮助下,我被指示遵循以下链接: https://www.ibm.com/support/knowledgecenter/SSAW57_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_sec_ws_basicauth.html

我们将ibm-ws-bnd.xml文件添加到了META-INF文件夹(根据第4节及以下部分),此外,我们使用@WebServiceRef访问了xml文件中的标记中定义的Web服务。该文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
                 version="1.0">
  <service-ref name="service/servicename">
    <port name="BasicHttpBinding"
          namespace="http://ibm.com/ws/jaxws/transport/security/"
          username="username"
          password="suchwowsecretpassword">
    </port>
  </service-ref>
</webservices-bnd>

Usign @WebServiceRef,我正在获取由ibm-ws-bnd.xml文件实例化的服务。但是,仍然不能满足基本身份验证WS策略。删除该策略声明后,我们可以看到外部服务失败,并显示401未经授权的错误。

此外,当我们检查处理程序链中的消息时,我们可以看到以下内容:

enter image description here

我们可以看到,管道属性上的username和pw值均为空。据我所知,哪个应该表明ibm-ws-bnd没有在我们的服务上设置实际的基本身份验证标头。

1 个答案:

答案 0 :(得分:1)

前段时间我们基本上遇到了相同的问题[1],但不幸的是无法解决此问题。

我的建议是使用普通的Java代码设置整个SOAP客户端内容,而不依赖于Application Server中的任何内容,因为这样您就可以像下面的代码片段一样设置Authentication了:

HTTPConduit http = (HTTPConduit) client.getConduit(); 
http.getAuthorization().setUserName("user");
http.getAuthorization().setPassword("pass");

注意:实际上,我们并没有解决这样的问题;我们寻求解决方法。我们对WebSphere Liberty的使用仅限于开发人员环境。在我们的集成测试,验收和生产服务器上,我们使用“真实的” WebSphere Application Server。

我们的解决方法是开始从WSDL中删除策略行,然后 不要在我们的开发人员测试中使用基本身份验证。 即使WSDL不再指定该策略,真实的WebSphere仍然会应用HTTP基本身份验证(即使已配置为这样做)。

希望您能找到合适的解决方案。

干杯,    马可

1:How to setup HTTP Basic Authentication for SOAP Client within WebSphere Liberty

删除意外编辑

相关问题