带有 NTLM 到 SharePoint 的 CXF SOAP 客户端 [英] CXF SOAP Client with NTLM to SharePoint

查看:23
本文介绍了带有 NTLM 到 SharePoint 的 CXF SOAP 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CXF 框架(版本:2.7.8)为 SharePoint 2007 编写 SOAP 客户端.我已按照在线文档添加 NTLM 支持 这里.我让客户端工作并且跟踪 HTTP 会话显示正在发送 NTLM 凭据,但是,我仍然收到 401 未经授权的响应.

I am writing a SOAP client using CXF Framework (version: 2.7.8) for SharePoint 2007. I have followed the online documentation for adding NTLM support here. I have the client working and tracing the HTTP session shows that NTLM credentials are being sent, however, I am still receiving a 401 Unauthorized response.

代码:

Lists listService = new Lists();
ListsSoap port = listService.getListsSoap();

BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put("use.async.http.conduit", Boolean.TRUE);
Credentials creds = new NTCredentials(USER, PASS, "", DOMAIN);
bp.getRequestContext().put(Credentials.class.getName(), creds);

Client client = ClientProxy.getClient(proxy);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAutoRedirect(true);
http.setClient(httpClientPolicy);

// Build request and execute

有趣的是,我使用 HTTP PUT 为 WebDAV 编写了一个类似的客户端,以使用 Apache HTTPClient 库上传文档,并且能够使用 NTLM 成功进行身份验证.此外,我还能够使用 SOAPUI 调用相同的 Lists Web 服务,我正在尝试为其构建 Java 客户端,并且它也成功地使用 NTLM 进行了身份验证.

Interestingly, I wrote a similar client using HTTP PUT for WebDAV to upload documents using Apache HTTPClient library, and was able to successfully authenticate using NTLM. Also, I was able to use SOAPUI to invoke the same Lists web service I am trying to build the Java client for and it successfully authenticated using NTLM as well.

我假设 CXF 和 HTTPClient 的 NTLM 实现不同.对我的 CXF 实现有什么问题有什么想法吗?或者我怎样才能让它镜像 HTTPClient 实现?

I'm assuming the implementation of NTLM is different between CXF and HTTPClient. Any thoughts on what is wrong with my CXF implementation? Or how I can get it to mirror the HTTPClient implementation?

推荐答案

请试试这个方法!

HTTPConduit http = (HTTPConduit)client.getConduit();
AsyncHTTPConduit conduit = (AsyncHTTPConduit)http;
DefaultHttpAsyncClient defaultHttpAsyncClient;
defaultHttpAsyncClient = conduit.getHttpAsyncClient();
defaultHttpAsyncClient.getCredentialsProvider().setCredentials( AuthScope.ANY,
 new NTCredentials( USER,PWD, "", DOM ) );
conduit.getClient().setAllowChunking( false );
conduit.getClient().setAutoRedirect( true );

这篇关于带有 NTLM 到 SharePoint 的 CXF SOAP 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆