SSL暗号化(https)とNTLM認証を使用するSharepoint 2010サーバーで簡単なREST呼び出しを実行しようとしています。サーバーがSSLを必要としないように設定されている場合(テストの場合のみ、サーバーにはSSLが必要です)、NTLM認証とその後のREST呼び出しはHttpClientを使用して正常に動作します。ただし、SSLを有効にすると、認証が機能しなくなります。SSL暗号化とNTLM認証の両方を使用するHttpClientが失敗する
ここで(すべての本命を受け入れるセット)取扱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);
応答を、私はいつもIS取り戻す:私は彼女をやろうとしている同じことを行うためにFireFoxのポスターやCURLを使用しました
HTTP/1.1 400 Bad Request
The server encountered an error processing the request. See server logs for more details.
注意をeプログラムで、それは正常に動作します。したがって、サーバーが正しくセットアップされているように見えます。
ありがとうございました!
サーバーログには何が表示されるように指示されていますか? – EJP