ews-java-api icon indicating copy to clipboard operation
ews-java-api copied to clipboard

NTLM Authentication support

Open venkatrangan opened this issue 9 years ago • 2 comments

Hi,

I am trying to use NTLM authentication with the HTTP Client 4.4.1 and it is failing with 401 Unauthorized. The same user format (domain\user) using external Microsoft connectivity tool (ExRCA) is working, so credentials and format are correct. Here is the call:

        String username = "mydomain\\username";
        String password = "mypassword";
        String exchangeServer = "myserver";
        String domain = "mydomain";
        boolean performAutodiscovery = false;

        ExchangeCredentials credentials = new WebCredentials(username, password, domain);
        service.setCredentials(credentials);
        try {
            service.setUrl(new URI("https://" + exchangeServer + "/EWS/Exchange.asmx"));
        } catch(Exception e) {

        }

Here is the log extract:

2015-10-18 22:30:02 [main] DEBUG o.a.http.impl.auth.HttpAuthenticator - myserver:443 requested authentication
2015-10-18 22:30:02 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
2015-10-18 22:30:02 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - Cookie [version: 0][name: exchangecookie][value: 9dcb3e0e9fd24d778adb8f53542dd920][domain: myserver][path: /][expiry: Tue Oct 18 22:29:08 IST 2016] match [(secure)mail.server.com:443/EWS/Exchange.asmx]
2015-10-18 22:30:02 [main] DEBUG o.a.http.impl.auth.HttpAuthenticator - Authorization challenge processed
2015-10-18 22:30:02 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /EWS/Exchange.asmx HTTP/1.1
2015-10-18 22:30:02 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: HANDSHAKE
2015-10-18 22:30:02 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /EWS/Exchange.asmx HTTP/1.1
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-type: text/xml; charset=utf-8
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: ExchangeServicesClient/0.0.0.0
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: text/xml
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Keep-Alive: 300
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 1313
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: myserver.com
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Cookie: exchangecookie=9dcb3e0e9fd24d778adb8f53542dd920
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: NTLM removed
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /EWS/Exchange.asmx HTTP/1.1[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-type: text/xml; charset=utf-8[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: ExchangeServicesClient/0.0.0.0[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: text/xml[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Keep-Alive: 300[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 1313[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: myserver.com[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Cookie: exchangecookie=9dcb3e0e9fd24d778adb8f53542dd920[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: NTLM removed=[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Header><t:RequestServerVersion Version="Exchange2010_SP2"></t:RequestServerVersion></soap:Header><soap:Body><m:FindItem Traversal="Shallow"><m:ItemShape><t:BaseShape>AllProperties</t:BaseShape></m:ItemShape><m:IndexedPageItemView MaxEntriesReturned="100" Offset="0" BasePoint="Beginning"></m:IndexedPageItemView><m:Restriction><t:And><t:IsGreaterThan><t:FieldURI FieldURI="calendar:Start"></t:FieldURI><t:FieldURIOrConstant><t:Constant Value="2014-04-20T06:30:00Z"></t:Constant></t:FieldURIOrConstant></t:IsGreaterThan><t:IsGreaterThan><t:FieldURI FieldURI="calendar:Start"></t:FieldURI><t:FieldURIOrConstant><t:Constant Value="2014-04-20T06:30:00Z"></t:Constant></t:FieldURIOrConstant></t:IsGreaterThan></t:And></m:Restriction><m:SortOrder><t:FieldOrder Order="Descending"><t:FieldURI FieldURI="item:DateTimeReceived"></t:FieldURI></t:FieldOrder></m:SortOrder><m:ParentFolderIds><t:DistinguishedFolderId Id="calendar"></t:DistinguishedFolderId></m:ParentFolderIds></m:FindItem></soap:Body></soap:Envelope>"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: Microsoft-IIS/7.5[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "WWW-Authenticate: Negotiate[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "WWW-Authenticate: NTLM[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="myserver.com"[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Powered-By: ASP.NET[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Sun, 18 Oct 2015 17:00:01 GMT[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 0[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 401 Unauthorized
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Server: Microsoft-IIS/7.5
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << WWW-Authenticate: Negotiate
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << WWW-Authenticate: NTLM
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << WWW-Authenticate: Basic realm="myserver.com"
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Powered-By: ASP.NET
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Sun, 18 Oct 2015 17:00:01 GMT
2015-10-18 22:30:05 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 0
Disconnected from the target VM, address: '127.0.0.1:51373', transport: 'socket'
2015-10-18 22:30:05 [main] DEBUG o.a.h.impl.execchain.MainClientExec - Connection can be kept alive indefinitely
2015-10-18 22:30:05 [main] DEBUG o.a.http.impl.auth.HttpAuthenticator - Authentication required
2015-10-18 22:30:05 [main] DEBUG o.a.http.impl.auth.HttpAuthenticator - myserver.com:443 requested authentication
2015-10-18 22:30:05 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
2015-10-18 22:30:05 [main] DEBUG o.a.h.c.protocol.RequestAddCookies - Cookie [version: 0][name: exchangecookie][value: 9dcb3e0e9fd24d778adb8f53542dd920][domain: mydomain.com][path: /][expiry: Tue Oct 18 22:29:08 IST 2016] match [(secure)mail.server.com:443/EWS/Exchange.asmx]
2015-10-18 22:30:05 [main] DEBUG o.a.http.impl.auth.HttpAuthenticator - Authorization challenge processed
2015-10-18 22:30:05 [main] DEBUG o.a.http.impl.auth.HttpAuthenticator - Authentication failed
2015-10-18 22:30:05 [main] DEBUG o.a.h.i.c.BasicHttpClientConnectionManager - Releasing connection 192.168.2.102:51376<->198.54.169.104:443

venkatrangan avatar Oct 18 '15 20:10 venkatrangan

Anyone?

asfernandes avatar Apr 19 '18 10:04 asfernandes

?

Roinw avatar Nov 03 '20 15:11 Roinw