пятница, 8 декабря 2017 г.

Настройка NTLM и Basic аутентификации JAX-WS клиента в конфигурационном файле Spring

AllowChunking="false" в элементе http-conf:conduit/http-conf:client активизирует аутентификацию NTLM, если не указывать ее тип в http-conf:authorization . Без этой установки будет применяться аутентификация Basic.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/transports/http/configuration
        http://cxf.apache.org/schemas/configuration/http-conf.xsd">

    <beans>

        <!-- Setting AllowChunking="false" activates NTLM authentication.
        Basic authentication will be used without it -->
        <http-conf:conduit name="*.http-conduit"
            xmlns:sec="http://cxf.apache.org/configuration/security"
            xmlns="http://cxf.apache.org/transports/http/configuration">
            <http-conf:client
                    ConnectionTimeout="1000"
                    ReceiveTimeout="10000"
                    AllowChunking="false" />
            <http-conf:authorization>
                <sec:UserName>${auth.username}</sec:UserName>
                <sec:Password>${auth.password}</sec:Password>
            </http-conf:authorization>
        </http-conf:conduit>

        <!--WS Clients-->
        <jaxws:client id="ws-client-id"
                      serviceClass="com.microsoft.schemas.sharepoint.soap.XXXX"
                      address="${endpoints.someaddress}">
        </jaxws:client>

    </beans>

</beans>

Из доков CXF:

Finally, you need to setup the CXF client to turn off chunking. The reason is that the NTLM authentication requires a 3 part handshake which breaks the streaming.

//Turn off chunking so that NTLM can occur
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);