Liferay6.1ポートレットからHTTPClient4.2.3を介してSharepoint2010へのREST呼び出しを使用しようとしています。
証明書をローカルMACのJVMcacertsにインポートし、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.1401 Unauthorized
ワイヤログにSSLハンドシェイクが表示されず、401の不正な応答が返されます。サンプルコードのさまざまな組み合わせを試しましたが、同じ結果になりました。
注-FireFoxとCURLを使用して、ここでプログラムで実行しようとしているのと同じことを実行しましたが、正常に動作します。したがって、サーバーは正しくセットアップされているように見えます。CURL冗長ログは、SSLハンドシェイクが最初に発生し、NTLMが次のステップとして成功することを示しています。
必要に応じてワイヤーログを添付できます。
どうもありがとうございました!
ヘルプとポインタに感謝します。