HttpClient gives Negotiate error with NTLM auth provider

apache-httpclient-4.x, authentication, java, ntlm

Solution

I think it is all very simple. Effectively the client is only willing to do `NTLM` while the server is only willing to do `Negotiate`, thus failing to agree on a common authentication scheme.

This is how one can adjust auth scheme preference to force HttpClient to choose NTLM over SPNEGO / Kerberos

RequestConfig config = RequestConfig.custom()
        .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.KERBEROS, AuthSchemes.SPNEGO))
        .build();
CloseableHttpClient client = HttpClients.custom()
        .setDefaultRequestConfig(config)
        .build();

Problem

I am "forcing" the httpclient to do ntlm authentication by using: ``` PoolingHttpClientConnectionManager connPool connPool = new PoolingHttpClientConnectionManager(); Lookup<AuthSchemeProvider> authProviders = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.NTLM, new NTLMSchemeFactory()) .build(); CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connPool).setDefaultAuthSchemeRegistry(authProviders).build(); ``` But, when authenticating to the server, I get an annoying log message "Authentication scheme Negotiate not supported". How can I get rid of this message? (This will be running on a linux box, so HttpClient 4.4 JNA support for native authentication won't help.)

Original source