本文介绍了如何在Spring的rest模板Header中设置NTLM身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to authenticate NTLM using Rest template , can any one suggest the way ?

推荐答案

如果有人再次偶然发现此条目,这是内置解决方案:

If anyone stumble upon this entry again, this is the builtin solution:

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

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

Then you can build your RestTemplate with this snippet:

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的rest模板Header中设置NTLM身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 05:27