GSA API - Невозможно получить токен аутентификации - PullRequest
1 голос
/ 27 октября 2011

Я пытался получить ключ аутентификации для управления Google Search Appliance и изменить его списки контроля доступа (ACL).

Это мой код:

    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);
}

У меня естьследовал инструкциям здесь но я всегда получаю это исключение:

javax.net.ssl.SSLHandshakeException: удаленное соединение закрыло соединение во время рукопожатия на com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord (SSLSocketImpl.java:808) на com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake (SSLSocketImpl.java:1120) на com.sun.net.ssl.internal.ssl.SSo..startHandshake (SSLSocketImpl.java:1147) по адресу com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake (SSLSocketImpl.java:1131) по адресу sun.net.www.protocol.https.HttpsClient.afterConnecttt: 434) на sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect (AbstractDelegateHttpsURLConnection.java:166) на sun.net.www.protocol.http.HttpURLConnection.getOutputStream (HttpURLConnection.jt904) по адресу sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream (HttpsURLConnectionImpl.java:230) по адресу com.mycompany.gslisting.GetKeysTestCase.testGetAccessControlListKeys (getKeysmate.No.Oj.Oj.Oj.Text)Метод) в sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) в sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) в java.lanketo.j.jjjunit.framework.TestCase.runTest (TestCase.java:168) в junit.framework.TestCase.runBare (TestCase.java:134) в junit.framework.TestResult $ 1.protect (TestResult.java:110) в junit.framework.TestResult.runProtected (TestResult.java:128) в junit.framework.TestResult.run (TestResult.java:113) в junit.framework.TestCase.run (TestCase.java:124) в junit.framework.TestSuite.runTuest Test (.java: 243) в junit.framework.TestSuite.run (TestSuite.java:238) в org.junit.internal.runners.JUnit38ClassRunner.run (JUnit38ClassRunner.java:83) в org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (JUnit4TestReference.java:50) в org.eclipse.jdt.internal.junit.runner.TestExecution.run Test:38) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:467) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests: в удаленном режиме:.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.java:390) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner.java:19ava).EOFException: SSL-одноранговый узел некорректно завершил работу на com.sun.net.ssl.internal.ssl.InputRecord.read (InputRecord.java:333) на com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord (SSLSocketImpl.Java: 789) ... еще 27

Есть идеи?

1 Ответ

0 голосов
/ 28 октября 2011

Нашел!

Я просто следовал инструкциям на этом сайте .Я загрузил сертификат сайта (.cer) с помощью браузера (Chrome) и импортировал его в хранилище ключей по умолчанию, выполнив:

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