locked
[E2010] [EWS Java API 1.1] (401)Unauthorized RRS feed

  • Question

  • I have verified my credentials in OWA, and verified that the Exchange server has Basic Authentication enabled.

    When I run the following code, I get the 401 Unauthorized error (logs follow).  Can I get a 401 if the SSL certificate is not trusted?

    CODE:

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
    service.setTraceEnabled(true);
    ExchangeCredentials credentials = new WebCredentials("Test1", "test", "domainName");
    service.setCredentials(credentials);
    service.setUrl(new URI("https://hostname/ews/Exchange.asmx"));
    ArrayList<FolderId> folderIds = new ArrayList<FolderId>(1);
    folderIds.add(new FolderId(WellKnownFolderName.Inbox));
    PushSubscription pushSubscription = service.subscribeToPushNotifications(
    folderIds, new URI("http://myserver"), 5, null, new EventType[] { EventType.NewMail} );

    LOG:

    [2012-03-28 18:31:48,585] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.useragent = Jakarta Commons-HttpClient/3.1
    [2012-03-28 18:31:48,587] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.version = HTTP/1.1
    [2012-03-28 18:31:48,589] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.connection-manager.class = class org.apache.commons.httpclient.SimpleHttpConnectionManager
    [2012-03-28 18:31:48,590] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.cookie-policy = default
    [2012-03-28 18:31:48,591] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.element-charset = US-ASCII
    [2012-03-28 18:31:48,592] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.content-charset = ISO-8859-1
    [2012-03-28 18:31:48,595] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@55acc1c2
    [2012-03-28 18:31:48,596] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:s
    s yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd
    MMM yy HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy HH:mm:ss z]
    [2012-03-28 18:31:48,632] DEBUG: org.apache.commons.httpclient.HttpClient - Java version: 1.6.0_27
    [2012-03-28 18:31:48,633] DEBUG: org.apache.commons.httpclient.HttpClient - Java vendor: Sun Microsystems Inc.
    [2012-03-28 18:31:48,634] DEBUG: org.apache.commons.httpclient.HttpClient - Java class path: C:\apache-maven-3.0.3/boot/plexus-classworlds-2.4.jar
    [2012-03-28 18:31:48,635] DEBUG: org.apache.commons.httpclient.HttpClient - Operating system name: Windows 7
    [2012-03-28 18:31:48,636] DEBUG: org.apache.commons.httpclient.HttpClient - Operating system architecture: amd64
    [2012-03-28 18:31:48,637] DEBUG: org.apache.commons.httpclient.HttpClient - Operating system version: 6.1
    [2012-03-28 18:31:48,650] DEBUG: org.apache.commons.httpclient.HttpClient - SUN 1.6: SUN (DSA key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom; X.509 certificates; JKS keystore; PKIX Cert
    PathValidator; PKIX CertPathBuilder; LDAP, Collection CertStores, JavaPolicy Policy; JavaLoginConfig Configuration)
    [2012-03-28 18:31:48,652] DEBUG: org.apache.commons.httpclient.HttpClient - SunRsaSign 1.5: Sun RSA signature provider
    [2012-03-28 18:31:48,653] DEBUG: org.apache.commons.httpclient.HttpClient - SunJSSE 1.6: Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
    [2012-03-28 18:31:48,654] DEBUG: org.apache.commons.httpclient.HttpClient - SunJCE 1.6: SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
    [2012-03-28 18:31:48,655] DEBUG: org.apache.commons.httpclient.HttpClient - SunJGSS 1.0: Sun (Kerberos v5, SPNEGO)
    [2012-03-28 18:31:48,656] DEBUG: org.apache.commons.httpclient.HttpClient - SunSASL 1.5: Sun SASL provider(implements client mechanisms for: DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5; server mechanisms for:
     DIGEST-MD5, GSSAPI, CRAM-MD5)
    [2012-03-28 18:31:48,658] DEBUG: org.apache.commons.httpclient.HttpClient - XMLDSig 1.0: XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory)
    [2012-03-28 18:31:48,659] DEBUG: org.apache.commons.httpclient.HttpClient - SunPCSC 1.6: Sun PC/SC provider
    [2012-03-28 18:31:48,664] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.auth.scheme-priority = [NTLM, Basic, Digest]
    [2012-03-28 18:31:48,666] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.socket.timeout = 100000
    [2012-03-28 18:31:48,667] DEBUG: org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.connection.timeout = 100000
    <Trace Tag="EwsRequestHttpHeaders" Tid="1" Time="2012-03-28 22:31:48Z">
    POST /ews/Exchange.asmx HTTP/1.1
    Content-type : text/xml; charset=utf-8
    Accept-Encoding : gzip,deflate
    Keep-Alive : 300
    User-Agent : ExchangeServicesClient/0.0.0.0
    Connection : Keep-Alive
    Accept : text/xml




    </Trace>


    <Trace Tag="EwsRequest" Tid="1" Time="2012-03-28 22:31:48Z">
    <?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/s
    ervices/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Header><t:RequestServerVersion Version="Exchange2010"></t:RequestServerVersion></soap:Header><soap:Body><m:Subscr
    ibe><m:PushSubscriptionRequest><t:FolderIds><t:DistinguishedFolderId Id="inbox"></t:DistinguishedFolderId></t:FolderIds><t:EventTypes><t:EventType>NewMailEvent</t:EventType></t:EventTypes><t:StatusFrequency>5</
    t:StatusFrequency><t:URL>http://10.1.16.124</t:URL></m:PushSubscriptionRequest></m:Subscribe></soap:Body></soap:Envelope>
    </Trace>


    [2012-03-28 18:31:48,729] DEBUG: org.apache.commons.httpclient.MultiThreadedHttpConnectionManager - HttpConnectionManager.getConnection:  config = HostConfiguration[host=https://10.1.18.223], timeout = 0
    [2012-03-28 18:31:48,731] DEBUG: org.apache.commons.httpclient.MultiThreadedHttpConnectionManager - Allocating new connection, hostConfig=HostConfiguration[host=https://10.1.18.223]
    [2012-03-28 18:31:48,736] DEBUG: org.apache.commons.httpclient.HttpConnection - Open connection to hostname:443
    [2012-03-28 18:31:48,847] DEBUG: org.apache.commons.httpclient.HttpMethodBase - Adding Host request header
    [2012-03-28 18:31:48,880] DEBUG: org.apache.commons.httpclient.methods.EntityEnclosingMethod - Request body sent
    [2012-03-28 18:31:51,727] DEBUG: org.apache.commons.httpclient.cookie.CookieSpec - Unrecognized cookie attribute: name=HttpOnly, value=null
    [2012-03-28 18:31:51,729] DEBUG: org.apache.commons.httpclient.HttpMethodBase - Cookie accepted: "$Version=0; exchangecookie=8e9d5cb44f714dbc9eacf943999570df; $Path=/"
    [2012-03-28 18:31:51,731] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Authorization required
    [2012-03-28 18:31:51,732] DEBUG: org.apache.commons.httpclient.auth.AuthChallengeProcessor - Supported authentication schemes in the order of preference: [NTLM, Basic, Digest]
    [2012-03-28 18:31:51,734] DEBUG: org.apache.commons.httpclient.auth.AuthChallengeProcessor - Challenge for NTLM authentication scheme not available
    [2012-03-28 18:31:51,735] INFO : org.apache.commons.httpclient.auth.AuthChallengeProcessor - Basic authentication scheme selected
    [2012-03-28 18:31:51,741] DEBUG: org.apache.commons.httpclient.auth.AuthChallengeProcessor - Using authentication scheme: basic
    [2012-03-28 18:31:51,742] DEBUG: org.apache.commons.httpclient.auth.AuthChallengeProcessor - Authorization challenge processed
    [2012-03-28 18:31:51,744] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Authentication scope: BASIC 'hostname'@hostname:443
    [2012-03-28 18:31:51,745] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Retry authentication
    [2012-03-28 18:31:51,747] DEBUG: org.apache.commons.httpclient.HttpMethodBase - Should NOT close connection in response to directive: Keep-Alive
    [2012-03-28 18:31:51,749] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Authenticating with BASIC 'hostname'@hostname:443
    [2012-03-28 18:31:51,750] DEBUG: org.apache.commons.httpclient.params.HttpMethodParams - Credential charset not configured, using HTTP element charset
    [2012-03-28 18:31:51,755] DEBUG: org.apache.commons.httpclient.HttpMethodBase - Adding Host request header
    [2012-03-28 18:31:51,757] DEBUG: org.apache.commons.httpclient.methods.EntityEnclosingMethod - Request body sent
    [2012-03-28 18:31:51,760] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Authorization required
    [2012-03-28 18:31:51,761] DEBUG: org.apache.commons.httpclient.auth.AuthChallengeProcessor - Using authentication scheme: basic
    [2012-03-28 18:31:51,762] DEBUG: org.apache.commons.httpclient.auth.AuthChallengeProcessor - Authorization challenge processed
    [2012-03-28 18:31:51,763] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Authentication scope: BASIC 'hostname'@hostname:443
    [2012-03-28 18:31:51,764] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Credentials required
    [2012-03-28 18:31:51,765] DEBUG: org.apache.commons.httpclient.HttpMethodDirector - Credentials provider not available
    [2012-03-28 18:31:51,766] INFO : org.apache.commons.httpclient.HttpMethodDirector - Failure authenticating with BASIC 'hostname'@hostname:443
    <Trace Tag="EwsResponseHttpHeaders" Tid="1" Time="2012-03-28 22:31:51Z">
    401 null
    WWW-Authenticate : Basic realm="hostname"
    Date : Wed, 28 Mar 2012 22:31:23 GMT
    Content-Length : 0
    X-Powered-By : ASP.NET
    Server : Microsoft-IIS/7.5




    </Trace>


    microsoft.exchange.webservices.data.HttpErrorException: The remote server returned an error: (401)Unauthorized
            at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:729)
            at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:36)
            at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:140)
            at microsoft.exchange.webservices.data.ExchangeService.internalSubscribeToPushNotifications(ExchangeService.java:2088)
            at microsoft.exchange.webservices.data.ExchangeService.subscribeToPushNotifications(ExchangeService.java:2013)


    Thursday, March 29, 2012 12:14 AM

Answers

  • Found the problem.

    Apparently the server requires that the domain be part of the username.  For example, "domain\\user" as the username in the credentials object.


    yw

    • Marked as answer by yw2012 Thursday, March 29, 2012 3:53 PM
    Thursday, March 29, 2012 3:53 PM