【问题标题】:NT Authentication with GoogleHttpClient使用 GoogleHttpClient 进行 NT 身份验证
【发布时间】:2016-02-19 02:17:21
【问题描述】:

您应该如何使用Google Http Client 进行 NT 身份验证?

我可以找到有关 Apache HttpClientNTCredentials 的大量信息,并且我可以使用这些信息,但在我试图标准化新代码的 Google 客户端上却没有。

我已经走到这一步了:

final NTCredentials ntc = new NTCredentials(System.getProperty("user.name"), args[0], InetAddress.getLocalHost().getHostName(), "DOMAIN");
final BasicCredentialsProvider cp = new BasicCredentialsProvider();
cp.setCredentials(AuthScope.ANY, ntc);
final HttpClientBuilder hcb = HttpClientBuilder.create();
hcb.setDefaultCredentialsProvider(cp);
final HttpTransport ht = new ApacheHttpTransport(hcb.build());

我得到了这个异常:

Exception in thread "main" java.lang.UnsupportedOperationException
    at org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:210)
    at com.google.api.client.http.apache.ApacheHttpTransport.<init>(ApacheHttpTransport.java:129)
    at GoogleHttpClientScratch.main(GoogleHttpClientScratch.java:36)

org.apache.http.impl.client.InternalHttpClient.java引起的:

@Override
public HttpParams getParams() {
    throw new UnsupportedOperationException();
}

【问题讨论】:

    标签: java authentication windows-authentication apache-httpclient-4.x google-http-client


    【解决方案1】:

    ApacheHttpTransport 解决方案

    我最终提取了最新的dev 分支和patching up the offending ApacheHttpTransport constructor myself

    我还提交了pull request 以将更改合并到主线项目中。

    我实际上修补了 1.20.0 版本,因为这是我正在使用的版本,并在我的本地 maven 存储库中重新编译和安装了这个模块。

    我知道存在使用RequestConfig 的更好解决方案,但这解决了我的问题并让我再次工作现在

    如果我将整个类重构为使用 RequestConfig,我也会更新我的 fork。我需要了解如何正确使用 RequestConfig,这需要时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 2017-06-13
      • 2017-03-11
      • 2013-05-30
      • 2015-09-23
      • 2023-03-29
      相关资源
      最近更新 更多