GSA API - 无法获取身份验证令牌

发布于 2024-12-12 09:26:12 字数 5059 浏览 0 评论 0原文

我一直在尝试获取用于管理 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.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1147) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1131) 在 sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434) 在 sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166) 在 sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(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) 在 java.lang.reflect.Method.invoke(Method.java:597) 处 junit.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.runTest(TestSuite.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(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 在 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) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789) ... 27 更多

有什么想法吗?

I have been trying to get an Authentication Key for managing a Google Search Appliance and modify its Access Control Lists (ACLs).

This is my code:

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

I have followed the instructions here but I always get this exception:

javax.net.ssl.SSLHandshakeException: Remote host closed connection
during handshake at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1120)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1147)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1131)
at
sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at
com.mycompany.gslisting.GetKeysTestCase.testGetAccessControlListKeys(GetKeysTestCase.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
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) at
junit.framework.TestResult$1.protect(TestResult.java:110) at
junit.framework.TestResult.runProtected(TestResult.java:128) at
junit.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(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.io.EOFException: SSL peer shut down incorrectly at
com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333)
at
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
... 27 more

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2024-12-19 09:26:12

找到了!

我只是按照此网站中的说明进行操作。
我所做的是使用浏览器 (Chrome) 下载站点证书 (.cer) 并通过运行以下命令将其导入到默认密钥库:

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

Found it!

I just followed the instructions in this site.
What I did was downloading the site certificate (.cer) using a browser (Chrome) and import it to the default keystore by running:

#keytool -import -alias GSAAPI -file ./GSA.cer
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文