我想使用Rest模板对NTLM进行身份验证,有人可以建议这种方式吗?

最佳答案

如果有人再次迷失于此条目,这是内置的解决方案:

确保您的项目包含org.apache.httpcomponents.httpclient

然后,您可以使用以下代码段构建RestTemplate:

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(user, password, "source-host-name", "domain-name"));
CloseableHttpClient httpClient = HttpClients.custom()
        .setDefaultCredentialsProvider(credsProvider)
        .build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);

关于spring - 如何在Spring的Rest模板头中设置NTLM身份验证,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45811242/

10-11 03:51