我想通過Liferay 6.1 portlet中的HTTPClient 4.2.3使用REST對Sharepoint 2010的調用。HttpClient 4.2.3同時使用SSL加密和NTLM身份驗證失敗
我已經將證書導入到本地MAC的JVM cacerts中,並試圖將cacerts作爲密鑰庫加載。
我的代碼是:
String opsCalendarURL1 = "https://hostname/sites/team-sites/operations/_vti_bin/owssvr.dll?";
String opsCalendarURL2 = "Cmd=Display&List={6E460908-D470-4F8A-AF76-CC279E25E0B1}&XMLDATA=TRUE";
String opsCalenderURLEncoded = opsCalendarURL1 + URLEncoder.encode(opsCalendarURL2 , "UTF8");
System.out.println(opsCalenderURLEncoded);
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
// SSL
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File("/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/security/cacerts"));
try {
trustStore.load(instream, "changeit".toCharArray());
} finally {
try { instream.close(); } catch (Exception ignore) {}
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", 443, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
System.out.println("----------------------------------------");
HttpHost targetHost = new HttpHost("hostname", 443, "https");
httpclient.getCredentialsProvider().setCredentials(
AuthScope.ANY,
new NTCredentials("username", "password","machine","domain"));
HttpGet httpget = new HttpGet(opsCalenderURLEncoded);
System.out.println("executing request: " + httpget.getRequestLine());
System.out.println("to target: " + targetHost);
HttpResponse response2 = httpclient.execute(targetHost, httpget);
HttpEntity entity = response2.getEntity();
System.out.println("----------------------------------------");
System.out.println(response2.getStatusLine());
System.out.println(response2.getProtocolVersion());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
EntityUtils.consume(entity);
} finally {
httpclient.getConnectionManager().shutdown();
}
的響應,我總是得到的回覆是: HTTP/1.1 401未經授權
我沒有看到電線日誌SSL握手,並得到一個401未經授權響應。我已經嘗試過各種樣本代碼的組合,結果相同。
請注意 - 我已經使用FireFox和CURL做同樣的事情,我試圖在這裏以編程方式做,並且它工作正常。所以服務器似乎設置正確。 CURL詳細日誌顯示SSL握手首先發生,NTLM成功作爲下一步。
如果需要,我可以附上電線日誌。
非常感謝您的時間!
我欣賞任何幫助和指針。
你有沒有試着用VM參數運行的客戶端... -Djavax.net.debug =所有 – helios 2013-02-14 22:16:22
@helios - 謝謝您的建議!是的,我剛剛嘗試過,我看到加密發生了。通過網絡日誌查看,我看到以下'2013/02/15 13:46:48:224 GMT [調試] DefaultHttpClient - 處理授權挑戰 2013/02/15 13:46:48:224 GMT [調試] DefaultHttpClient - 驗證失敗」 – VC1 2013-02-15 13:54:36
>嘗試更新的HttpClient [此處輸入鏈接的描述] [1] [1]:http://stackoverflow.com/questions/5917356/httpclient-4-1-1-returns- 401-時,認證與 - NTLM的瀏覽器工作精細/ 20047880#20047880 – 2013-11-18 13:05:06