使用Spring的Apache CXF Async Conduit和NTLM?(Apache CXF Async Conduit and NTLM using Spring?)

编程入门 行业动态 更新时间:2024-10-24 06:30:47
使用Spring的Apache CXF Async Conduit和NTLM?(Apache CXF Async Conduit and NTLM using Spring?)

我试图找出将以下代码移动到spring .xml配置文件的最佳方法:(强制异步并禁用chunkng以便NTLM正常工作)

final WSSoap port = new WS().getWSSoap(); final Client client = ClientProxy.getClient(port); final HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); final HTTPClientPolicy httpClientPolicy = httpConduit.getClient(); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setAutoRedirect(true); final BindingProvider bindingProvider = (BindingProvider) port; final Map<String, Object> requestContext = bindingProvider.getRequestContext(); final Credentials credentials = new NTCredentials("username", "password", "workstation", "domain"); requestContext.put(Credentials.class.getName(), credentials); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.example.com/"); requestContext.put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);

我查看了CXF配置页面(这里: http : //cxf.apache.org/docs/configuration.html ),但我没有看到任何方法来做我需要的。

有没有一种干净的方法来使用spring处理CXF的NTLM身份验证?

更新:我已经弄清楚如何使用以下方法强制执行异步管道:

<cxf:bus name="asyncBus"> <cxf:properties> <entry key="use.async.http.conduit" value="true"/> </cxf:properties> </cxf:bus> <http-conf:conduit name="{http://www.webserviceX.NET}GlobalWeatherSoapPort.http-conduit"> <http-conf:client AllowChunking="false" Connection="Keep-Alive"/> </http-conf:conduit> <jaxws:client id="weatherClient" bus="asyncBus" address="http://www.webservicex.com/globalweather.asmx" serviceClass="net.webservicex.GlobalWeatherSoap"/>

但是我仍然无法访问请求上下文,因此我可以添加我的NTLM凭据。

I am trying to figure out the best way to move the following bit of code into a spring .xml configuration file: (force async and disable chunkng so NTLM works)

final WSSoap port = new WS().getWSSoap(); final Client client = ClientProxy.getClient(port); final HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); final HTTPClientPolicy httpClientPolicy = httpConduit.getClient(); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setAutoRedirect(true); final BindingProvider bindingProvider = (BindingProvider) port; final Map<String, Object> requestContext = bindingProvider.getRequestContext(); final Credentials credentials = new NTCredentials("username", "password", "workstation", "domain"); requestContext.put(Credentials.class.getName(), credentials); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.example.com/"); requestContext.put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);

I've looked over the CXF configuration page (here: http://cxf.apache.org/docs/configuration.html), but I don't see any way to do what I need.

Is there a clean way to handle NTLM authentication for CXF using spring?

Update: I've figured out how to force an async conduit, using the following:

<cxf:bus name="asyncBus"> <cxf:properties> <entry key="use.async.http.conduit" value="true"/> </cxf:properties> </cxf:bus> <http-conf:conduit name="{http://www.webserviceX.NET}GlobalWeatherSoapPort.http-conduit"> <http-conf:client AllowChunking="false" Connection="Keep-Alive"/> </http-conf:conduit> <jaxws:client id="weatherClient" bus="asyncBus" address="http://www.webservicex.com/globalweather.asmx" serviceClass="net.webservicex.GlobalWeatherSoap"/>

However I am still having trouble accessing the request context so I can add my NTLM credentials.

最满意答案

我想回答我自己的问题。 经过许多小时的调试和单步执行Apache CXF代码后,我找到了一个解决方案。 以下spring配置将通过异步管道启用NTLM身份验证:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/core" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.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"> <!-- ~ ~ create an asynchronous-only bus for NTLM requests ~ --> <cxf:bus name="asyncBus"> <cxf:properties> <entry key="use.async.http.conduit" value="true"/> </cxf:properties> </cxf:bus> <!-- ~ ~ configure conduit for NTLM request ~ --> <http-conf:conduit name="{http://www.webserviceX.NET}GlobalWeatherSoapPort.http-conduit"> <http-conf:client AllowChunking="false" AutoRedirect="true" Connection="Keep-Alive"/> </http-conf:conduit> <!-- ~ ~ create service stub ~ --> <jaxws:client id="weatherClient" bus="asyncBus" address="http://www.webservicex.com/globalweather.asmx" serviceClass="net.webservicex.GlobalWeatherSoap"> <jaxws:properties> <entry key="org.apache.http.auth.Credentials"> <bean class="org.apache.http.auth.NTCredentials"> <constructor-arg value="DOMAIN/USER:PASSWORD"/> </bean> </entry> </jaxws:properties> </jaxws:client> </beans>

如有必要,还可以在NTCredentials构造函数中指定用户名,密码,域和工作站。

I wanted to answer my own question. After many, many hours debugging and stepping through Apache CXF code, I have found a solution. The following spring configuration will enable NTLM authentication over an async conduit:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:cxf="http://cxf.apache.org/core" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.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"> <!-- ~ ~ create an asynchronous-only bus for NTLM requests ~ --> <cxf:bus name="asyncBus"> <cxf:properties> <entry key="use.async.http.conduit" value="true"/> </cxf:properties> </cxf:bus> <!-- ~ ~ configure conduit for NTLM request ~ --> <http-conf:conduit name="{http://www.webserviceX.NET}GlobalWeatherSoapPort.http-conduit"> <http-conf:client AllowChunking="false" AutoRedirect="true" Connection="Keep-Alive"/> </http-conf:conduit> <!-- ~ ~ create service stub ~ --> <jaxws:client id="weatherClient" bus="asyncBus" address="http://www.webservicex.com/globalweather.asmx" serviceClass="net.webservicex.GlobalWeatherSoap"> <jaxws:properties> <entry key="org.apache.http.auth.Credentials"> <bean class="org.apache.http.auth.NTCredentials"> <constructor-arg value="DOMAIN/USER:PASSWORD"/> </bean> </entry> </jaxws:properties> </jaxws:client> </beans>

It is also possible to specify the username, password, domain, and workstation in the NTCredentials constructor, if necessary.

更多推荐

本文发布于:2023-08-06 23:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CXF   Apache   Spring   NTLM   Conduit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!