I am trying to make a HttpClient to a service that support NTLM and Basic auth. In my case NTLM will not work, because the machine HttpClient is on is under a different domain to the service (thanks a corporate decision to very slowly migrate the name of the domain being used...). However it seems HttpClient will still try to use it anyway.
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(
username, password));
HttpClient client = HttpClientBuilder.create()
.setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet method = new HttpGet(uri);
HttpResponse response = client.execute(method);
Severe: [WARN] HttpAuthenticator - NEGOTIATE authentication error: No valid credentials provided (Mechanism level: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)) Severe: [WARN] HttpAuthenticator - NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.http.auth.UsernamePasswordCredentials
I just want it to send the HTTP Authentication: Basic ...
header. I have tested this outside any Java HTTP frameworks (e.g. using a raw ssl socket with a manually created HTTP request), so it seems to be some Java/Apache HTTP issue with it trying to do things I did not ask for and really don't want it to even try to do...
This is not a full answer but more of a pointer:
In 4.x, (refer: http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/auth/AuthSchemeRegistry.html) class acts as the registry, you could unregister NTLM from there. (currently deprecated)
Another method could be to use preemptive HTTP authentication with Authorization header (use of preemptive auth. is debatable).
In 3.x it was easier (refer: http://hc.apache.org/httpclient-3.x/authentication.html)
That is because well behaved clients should choose a more secure scheme over an inherently insecure BASIC auth.
This is how one can disable NTLM (and other non-standard schemes) permanently
This is how one can force HttpClient to choose BASIC over NTLM on a per request basis