我找不到任何好的示例或文档来清楚地解释这一点。我可以成功地使用(旧的)RestTemplate进行身份验证:
HttpClientBuilder httpClient = HttpClients.custom();
BasicCredentialsProvider provider = new BasicCredentialsProvider();
Credentials cred = new NTCredentials("my-user", "my-password", null, "my-domain");
provider.setCredentials(AuthScope.ANY, cred);
httpClient.setDefaultCredentialsProvider(provider);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.httpClient = httpClient.build();
RestTemplate restTemplate = new RestTemplate(request);
restTemplate.getForEntity("https://my.url.com", String.class)
我一直无法找到将NTCredentials
(或Credentials
)传递到WebClient的方法,已尝试
WebClient client = WebClient.builder()
.filter(ExchangeFilterFunctions.basicAuthentication("user", "password"))
.build();
也可以
WebClient client = WebClient.builder().build();
client.get().headers(h -> h.setBasicAuth("user", "password"))...
但这两种方法都不适用于WebClient
问题:
1.如何使用Spring WebClient进行Windows/NTLM身份验证?
1.当使用当前用户上下文在Windows中运行时,是否有任何方法可以在不提供用户/密码的情况下获得NTLM或Windows身份验证?
1条答案
按热度按时间qoefvg9y1#
我最近一直在寻找Spring WebClient的NTLM。首先我尝试使用Apache HttpClient,但请求时没有得到响应。我没有进一步调查原因...
由于我无论如何都想使用netty HttpClient,所以我使用JCIFS实现(与Apache HttpClient使用的相同)实现了我自己的
ExchangeFilterFunction
。我无法回答你的第二个问题。我的系统是Linux。