How to migrate NTLM auth to Apache HttpClient 5 from older version

303 views Asked by At

I have the following Java code with org.apache.commons.httpclient:

String url = "something";
CredentialsProvider credsProvider;
RequestConfig requestConfig;
credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(user, pass, host, domain));
requestConfig = RequestConfig.custom()
        .setTargetPreferredAuthSchemes(Collections.singletonList(AuthSchemes.NTLM)).build();

HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
                .setDefaultRequestConfig(requestConfig).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate.getForObject(url, String.class);

I want to migrate it to the newest org.apache.hc.client5 but lines 4 and 5 cannot be converted one to one, neither I was able to find a proper conversion.

Is there a path here to migrate this NTLM auth to the latest apache version (or to standard Java)?

0

There are 0 answers