2011-10-27 48 views
1

我一直在嘗試獲取用於管理Google Search Appliance的身份驗證密鑰並修改其訪問控制列表(ACL)。GSA API - 無法獲取身份驗證令牌

這是我的代碼:

SocketAddress proxyAddress = new InetSocketAddress(PROXY_HOST,PROXY_PORT); 
    Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); 
    URL clientLoginUrl = new URL("https://my.server.com:8443/accounts/ClientLogin"); 
    HttpURLConnection clientLoginSecureConnection = 
     (HttpURLConnection)clientLoginUrl.openConnection(proxy); 
    clientLoginSecureConnection.setDoInput(true); 
    clientLoginSecureConnection.setDoOutput(true); 
    clientLoginSecureConnection.setUseCaches(false); 
    clientLoginSecureConnection.setRequestProperty("Content-Type",   
     "application/x-www-form-urlencoded"); 
    StringBuilder content = new StringBuilder(); 
    content.append("Email=").append(
    URLEncoder.encode(Constants.GSA_AUTH_USER, "UTF-8")); 
    content.append("&Passwd=").append(
    URLEncoder.encode(Constants.GSA_AUTH_PASSWORD, "UTF-8")); 
    OutputStream outputStream = clientLoginSecureConnection.getOutputStream(); 
    outputStream.write(content.toString().getBytes("UTF-8")); 
    outputStream.close(); 
    // Retrieve the output 
    int responseCode = clientLoginSecureConnection.getResponseCode(); 
    System.out.println("Response code: " + responseCode); 
    InputStream inputStream; 
    if (responseCode == HttpURLConnection.HTTP_OK) { 
     inputStream = clientLoginSecureConnection.getInputStream(); 
    } else { 
     inputStream = clientLoginSecureConnection.getErrorStream(); 
    } 
    String postOutput = toString(inputStream); 
    StringTokenizer tokenizer = new StringTokenizer(postOutput, "=\n "); 
    String key = null; 
    while (tokenizer.hasMoreElements()) { 
     if (tokenizer.nextToken().equalsIgnoreCase("Auth")) { 
      if (tokenizer.hasMoreElements()) { 
       key = tokenizer.nextToken(); 
      } 
      break; 
     } 
    } 
    if (key == null) { 
    System.out.println("Error response from server:\n" + postOutput); 
    } else { 
     System.out.println("Key found: " + key); 
} 

我也跟着指示here,但我總是得到這樣的例外:

javax.net.ssl.SSLHandshakeException:遠程主機握手期間關閉連接 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketI mpl.java:1120)com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1147) 在 ( SSLSocketImpl.java:1131) 在 sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434) 在 sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:在 sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream 166) (HttpsURLConnectionImpl.java:230) 在 com.mycompany.gslisting.GetKeysTestCase.testGetAccessControlListKeys(GetKeysTestCase.java:90) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597)at junit.framework.TestCase.runTest(TestCase.java:168)at junit.framework.TestCase.runBare(TestCase.java:134)在 junit.framework.TestResult $ 1.protect(TestResult.java:110)在 junit.framework.TestResult.runProtected(TestResult.java:128)在 Ĵ unit.framework.TestResult.run(TestResult.java:113)at junit.framework.TestCase.run(TestCase.java:124)at junit.framework.TestSuite.runTest(TestSuite.java:243)at junit。 framework.TestSuite.run(TestSuite.java:238)at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)(JUnit4TestReference.java:50) (RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit。 runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在 org.eclipse.jdt.internal.junit。 Runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 引起:java.io.EOFException:SSL對端關閉不正確 com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333 ) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl。java:789) ... 27更多

任何想法?

回答

0

發現它!

我只是按照this site中的說明操作。 我所做的是使用瀏覽器(Chrome)下載站點證書(.cer)並通過運行將其導入到默認密鑰存儲區:

#keytool -import -alias GSAAPI -file ./GSA.cer