简体   繁体   English

java-HttpClient不通过NTLM进行身份验证

[英]java - HttpClient doesn't authenticate with NTLM

Trying to connect to a resource which is protected with NTLM authentication. 尝试连接到受NTLM身份验证保护的资源。 When making a request I get a response 401 unauthenticated, but httpclient doesn't perform NTLM authentication after that. 发出请求时,我得到未经身份验证的响应401,但此后httpclient不会执行NTLM身份验证。

Added Interceptor to see the communication and it doesn't even attempt to authenticate: 添加了Interceptor来查看通信,它甚至不尝试进行身份验证:

Request:
POST/NAV/xxxxxxxxx
Content-type: text/xml; charset=utf-8
SOAPAction:
Content-Length: 359
Host: xxx.local:7051
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.4 (Java/1.8.0_181)
Accept-Encoding: gzip,deflate


Response:
Unauthorized
Content-Length: 0
Server: Microsoft-HTTPAPI/2.0
WWW-Authenticate: Negotiate
Date: Wed, 26 Sep 2018 10:37:56 GMT

No requests made after that. 此后没有任何请求。

Any suggestions what can be wrong here? 有什么建议在这里有什么问题吗?

Here is my code: 这是我的代码:

NTCredentials credentials = new NTCredentials("testuser", "pass1", null, "stt.local");
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, credentials);

        ArrayList<String> authPrefs = new ArrayList<String>();
        authPrefs.add(AuthSchemes.NTLM);


        RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(30000)
                .setConnectTimeout(30000)
                .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM))
                .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
                .build();


        HttpClient client = HttpClientBuilder.
                create().
                setDefaultCredentialsProvider(credsProvider).
                setDefaultRequestConfig(requestConfig).
                addInterceptorLast(new LoggingRequestInterceptor()).
                addInterceptorLast(new LoggingResponseInterceptor()).
                build();



        HttpPost post = new HttpPost(endpoint); //Provide Request URL


        try {

            StringEntity input = new StringEntity(bodyAsString);
            input.setContentType("text/xml; charset=utf-8");
            post.setEntity(input);

            post.setHeader("Content-type", "text/xml; charset=utf-8");
            post.setHeader("SOAPAction", ""); //Provide Soap action


            org.apache.http.HttpResponse response = client.execute(post);
    }

The parameters to that NTCredentials constructor should have separate username and domain name. NTCredentials构造函数的参数应具有单独的用户名和域名。

Parameters: 参数:
userName - The user name. userName-用户名。 This should not include the domain to authenticate with. 这不应包括要进行身份验证的域。 For example: "user" is correct whereas "DOMAIN\\user\u0026quot; is not. 例如:“用户”是正确的,而“域\\用户”是不正确的。
password - The password. 密码-密码。
workstation - The workstation the authentication request is originating from. 工作站-身份验证请求所源自的工作站。 Essentially, the computer name for this machine. 本质上,这台机器的计算机名称。
domain - The domain to authenticate within. 域-要在其中进行身份验证的域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache HttpClient v5.0 未通过 Windows 上的 NTLM 进行身份验证 - Apache HttpClient v5.0 doesn't authenticate with NTLM on Windows 具有NTLM的Java HTTPClient 4.5,无法获得NTLMv2身份验证 - Java HTTPClient 4.5 with NTLM, can't get NTLMv2 authentication NTLM和Java Apache httpclient 4.5.6的多线程问题 - multithread issue with NTLM and Java Apache httpclient 4.5.6 使用 java UrlConnection 对 ntlm(或 kerberos)进行身份验证 - authenticate with ntlm (or kerberos) using java UrlConnection 无法使用java.net.URLConnection在一个会话中使用不同的NTLM凭据进行身份验证 - Can't authenticate with different NTLM credentials in one session with java.net.URLConnection 无法集成NTLM和JAVA - Can't integrate NTLM and JAVA Java HttpClient 与 NTLM - 如何使用默认网络凭据 - Java HttpClient with NTLM - how to use default network credentials Java RESTful客户端[RESTEasy或Apache HttpClient]-另一端是NTLM - Java RESTful client [RESTEasy or Apache HttpClient] - NTLM on the other side 您如何通过 apache 的 commons httpclient 使用 NTLM 身份验证以编程方式对 Web 服务器进行身份验证? - How do you programatically authenticate to a web server using NTLM Authentication with apache's commons httpclient? 使用httpclient 4.2.1进行NTLM身份验证 - NTLM authentication with httpclient 4.2.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM