401 NTLM身份验证错误后未授权:意外状态:MSG_TYPE1_GENERATED

时间:2017-03-29 10:22:11

标签: authentication apache-httpclient-4.x ntlm ewsjavaapi

我想知道错误消息 MSG_TYPE1_GENERATED MSG_TYPE3_GENERATED (来自 httpClient / NTLMScheme.State 枚举)表示有助于调试我们遇到的问题。有人可以提供这些错误的文档吗?

我有一个服务器应用程序使用 ews-java-api 2.0 连接到 Exchange Server 2016 ,配置了 NTLM身份验证。 我已配置 HttpClient 版本 4.5.2 。 服务器应用程序使用Exchange服务帐户从Exchange Server检索会议室和会议。 成功检索了会议室和会议,但是,在成功运行一段时间后,我在日志中看到以下错误:

ERROR org.apache.http.impl.auth.HttpAuthenticator - NTLM authentication error: Unexpected state: MSG_TYPE3_GENERATED

此错误之后是从Exchange Server收到的一些401 Unauthorized错误,应用程序永远不会从此401错误中恢复,直到重新启动(这通常每天发生几次)。

Caused by: microsoft.exchange.webservices.data.core.exception.http.HttpErrorException: The remote server returned an error: (401)Unauthorized
                at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:726)
                at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:640)
                ... 34 more
 

我不确定它是否与此问题有关,但有时在 MSG_TYPE3_GENERATED 错误日志之后,我会看到很多超时:     

 Caused by: java.net.SocketTimeoutException: Read timed out
                    at java.net.SocketInputStream.socketRead0(Native Method)
                    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
                    at java.net.SocketInputStream.read(SocketInputStream.java:170)
                    at java.net.SocketInputStream.read(SocketInputStream.java:141)
                    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
                    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
                    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
                    at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:930)
                    at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
                    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
                    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
                    at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
                    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
                    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
                    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
                    at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
                    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
                    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
                    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
                    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
                    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
                    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
                    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
                    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
                    at microsoft.exchange.webservices.data.core.request.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:286)
                    at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:721)
                    ... 39 more

有时我会在错误日志中看到 MSG_TYPE1_GENERATED ,而不是 MSG_TYPE3_GENERATED 。 我查看了HttpClient库 NTLMScheme.java 源代码,发现了

enum State {
        UNINITIATED,
        CHALLENGE_RECEIVED,
        MSG_TYPE1_GENERATED,
        MSG_TYPE2_RECEVIED,
        MSG_TYPE3_GENERATED,
        FAILED,
    }

但似乎没有关于每个值的任何文档。 我试图将HttpClient的版本增加到 4.5.3 ,因为我在发行说明中发现了与 NTLM 相关的问题 (https://issues.apache.org/jira/browse/HTTPCLIENT-1779)。之后,我的应用程序似乎更稳定。我只看了一次MSG_TYPE3_GENERATED,应用程序已运行了好几天。

您认为将 HttpClient 4.5.2 升级到 4.5.3 可以解决问题吗? 你还有其他建议吗?

谢谢, 阿林

0 个答案:

没有答案