javaauthenticationwindows-authenticationapache-httpclient-4.xgoogle-http-client

NT Authentication with GoogleHttpClient


How are you supposed to do NT Authentication using the Google Http Client?

I can find plenty of information for the Apache HttpClient and NTCredentials and I have that working but nothing on the Google client which I am trying to standardize new code on.

I have gotten this far:

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

and I get this exception:

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)

caused by this in org.apache.http.impl.client.InternalHttpClient.java:

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

Solution

  • ApacheHttpTransport Solution

    I ended up pulling the most recent dev branch and patching up the offending ApacheHttpTransport constructor myself.

    I also submitted a pull request to have the changes merged into the mainline project.

    I actually patched up version 1.20.0 because that is what I am using and recompiled and installed just this module in my local maven repository.

    I know a better solution using RequestConfig exists, but this fixes up the issue for me and gets me working again now.

    If I refactor the entire class to use RequestConfig I will update my fork as well. I need to read up on how RequestConfig is intended to be used correctly and that requires time.