【发布时间】:2012-03-15 05:48:48
【问题描述】:
我正在尝试在使用 SSL 加密 (https) 以及 NTLM 身份验证的 Sharepoint 2010 服务器上执行简单的 REST 调用。当服务器设置为不需要 SSL(仅用于测试,服务器将在生产中需要 SSL),我的 NTLM 身份验证和后续 REST 调用使用 HttpClient 可以正常工作。但是,启用 SSL 后,身份验证将不再起作用。
这是 SSL 处理的代码(设置为接受所有证书):
SSLContext sslContext = SSLContext.getInstance("TLS");
// set up a TrustManager that trusts everything
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs,
String authType) { }
public void checkServerTrusted(X509Certificate[] certs,
String authType) { }
} }, new SecureRandom());
SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme httpsScheme = new Scheme("https", 443, sf);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(httpsScheme);
ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry);
接下来是执行 NTML 和 HTTP GET 调用的代码:
HttpParams params = new BasicHttpParams();
DefaultHttpClient httpclient = new DefaultHttpClient(cm, params);
// Set up the NTLM credentials
NTCredentials creds = new NTCredentials(USERNAME, PASSWORD, MACHINE, DOMAIN);
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
// Setup the HTTP GET and execute it
HttpHost target = new HttpHost(HOSTNAME, 443, "https");
HttpContext localContext = new BasicHttpContext();
HttpGet httpget = new HttpGet("/site/_vti_bin/ListData.svc/TestList");
HttpResponse response1 = httpclient.execute(target, httpget, localContext);
我总是得到的回应是:
HTTP/1.1 400 Bad Request
The server encountered an error processing the request. See server logs for more details.
请注意,我已经使用 FireFox Poster 和 CURL 来执行我在此处以编程方式尝试执行的相同操作,并且效果很好。所以服务器似乎设置正确。
感谢您的宝贵时间!
【问题讨论】:
-
那么您被引导查看的服务器日志中有什么内容?
标签: java ssl sharepoint-2010 httpclient ntlm