Example #1
0
 private AutoDiscoverRequestResult GetAutodiscoverResultFromDomainResponse(EmailAddress emailAddress, DomainResponse domainResponse)
 {
     if (domainResponse != null)
     {
         if (domainResponse.DomainSettingErrors != null)
         {
             foreach (DomainSettingError domainSettingError in domainResponse.DomainSettingErrors)
             {
                 if (domainSettingError != null && domainSettingError.ErrorCode != ErrorCode.NoError)
                 {
                     SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: Response for domain {1} has DomainSettings error: {2}:{3}:{4}", new object[]
                     {
                         this,
                         emailAddress.Domain,
                         domainSettingError.SettingName,
                         domainSettingError.ErrorCode,
                         domainSettingError.ErrorMessage
                     });
                     return(new AutoDiscoverRequestResult(base.TargetUri, new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverRequestUserSettingError(base.TargetUri.ToString(), domainSettingError.SettingName, domainSettingError.ErrorMessage), 39228U), null, null));
                 }
             }
         }
         DomainStringSetting domainStringSetting  = null;
         DomainStringSetting domainStringSetting2 = null;
         foreach (DomainSetting domainSetting in domainResponse.DomainSettings)
         {
             if (StringComparer.InvariantCulture.Equals(domainSetting.Name, "ExternalEwsUrl"))
             {
                 domainStringSetting = (domainSetting as DomainStringSetting);
             }
             if (StringComparer.InvariantCulture.Equals(domainSetting.Name, "ExternalEwsVersion"))
             {
                 domainStringSetting2 = (domainSetting as DomainStringSetting);
             }
             if (domainStringSetting != null && domainStringSetting2 != null)
             {
                 break;
             }
         }
         if (domainStringSetting != null && !string.IsNullOrEmpty(domainStringSetting.Value))
         {
             string versionValue = (domainStringSetting2 != null) ? domainStringSetting2.Value : null;
             AutoDiscoverRequestResult autodiscoverResult = base.GetAutodiscoverResult(domainStringSetting.Value, versionValue, emailAddress);
             if (autodiscoverResult != null)
             {
                 return(autodiscoverResult);
             }
         }
         else
         {
             SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError <DomainSoapAutoDiscoverRequest, string>((long)this.GetHashCode(), "{0}: ExternalEwsUrl setting domain {1} has missing value", this, emailAddress.Domain);
         }
         SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError <DomainSoapAutoDiscoverRequest, string>((long)this.GetHashCode(), "{0}: Unable to find ExternalEwsUrl setting domain {1} in response", this, emailAddress.Domain);
     }
     else
     {
         SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError <DomainSoapAutoDiscoverRequest, string>((long)this.GetHashCode(), "{0}: Response for domain {1} is empty.", this, emailAddress.Domain);
     }
     return(new AutoDiscoverRequestResult(base.TargetUri, new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverRequestUserSettingInvalidError(base.TargetUri.ToString(), "ExternalEwsUrl"), 55612U), null, null));
 }
Example #2
0
 private void CompleteRequest(AsyncTask task)
 {
     AutoDiscoverRequestResult[] array = new AutoDiscoverRequestResult[this.requests.Length];
     for (int i = 0; i < this.requests.Length; i++)
     {
         array[i] = this.GetResult(this.requests[i]);
     }
     base.HandleResultsAndCompleteRequest(null, array);
 }
Example #3
0
        private AutoDiscoverRequestResult GetAutodiscoverResultFromUserResponse(EmailAddress emailAddress, UserResponse userResponse)
        {
            AutoDiscoverRequestResult autoDiscoverRequestResult = this.GetAutodiscoverResultFromUserResponseInternal(emailAddress, userResponse);

            if (autoDiscoverRequestResult == null)
            {
                autoDiscoverRequestResult = new AutoDiscoverRequestResult(base.TargetUri, new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverRequestUserSettingInvalidError(base.TargetUri.ToString(), "ExternalEwsUrl"), 43836U), base.FrontEndServerName, base.BackEndServerName);
            }
            return(autoDiscoverRequestResult);
        }
Example #4
0
        protected override void HandleResponse(AutodiscoverResponse autodiscoverResponse)
        {
            GetDomainSettingsResponse getDomainSettingsResponse = (GetDomainSettingsResponse)autodiscoverResponse;

            if (getDomainSettingsResponse.DomainResponses == null || getDomainSettingsResponse.DomainResponses.Length != base.EmailAddresses.Length)
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError <DomainSoapAutoDiscoverRequest>((long)this.GetHashCode(), "{0}: Response with no DomainResponses or unexpected number of DomainResponses", this);
                this.HandleException(new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverInvalidResponseError(this.client.Url), 63804U));
                return;
            }
            SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <DomainSoapAutoDiscoverRequest>((long)this.GetHashCode(), "{0}: Received valid response.", this);
            AutoDiscoverRequestResult[] array = new AutoDiscoverRequestResult[base.EmailAddresses.Length];
            for (int i = 0; i < base.EmailAddresses.Length; i++)
            {
                array[i] = this.GetAutodiscoverResultFromDomainResponse(base.EmailAddresses[i], getDomainSettingsResponse.DomainResponses[i]);
            }
            base.HandleResult(array);
        }
Example #5
0
        protected override void HandleResponse(AutodiscoverResponse autodiscoverResponse)
        {
            GetUserSettingsResponse getUserSettingsResponse = (GetUserSettingsResponse)autodiscoverResponse;

            if (getUserSettingsResponse.UserResponses == null)
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError <object, UserSoapAutoDiscoverRequest>((long)this.GetHashCode(), "{0}: Request '{1}' got response with no UserResponses", TraceContext.Get(), this);
                this.HandleException(new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverInvalidResponseError(this.client.Url), 39740U));
                return;
            }
            if (getUserSettingsResponse.UserResponses.Length != base.EmailAddresses.Length)
            {
                SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: Request '{1}' got response with unexpected number of UserResponses EmailAddress length {2} UserResponses length{3}", new object[]
                {
                    TraceContext.Get(),
                    this,
                    base.EmailAddresses.Length,
                    getUserSettingsResponse.UserResponses.Length
                });
                for (int i = 0; i < getUserSettingsResponse.UserResponses.Length; i++)
                {
                    if (getUserSettingsResponse.UserResponses[i].ErrorCodeSpecified)
                    {
                        SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: UserResponses[{1}] ErrorCode {2} ErrorMessage {3}", new object[]
                        {
                            TraceContext.Get(),
                            i,
                            getUserSettingsResponse.UserResponses[i].ErrorCode,
                            getUserSettingsResponse.UserResponses[i].ErrorMessage
                        });
                    }
                }
                this.HandleException(new AutoDiscoverFailedException(Strings.descSoapAutoDiscoverInvalidResponseError(this.client.Url), 56124U));
                return;
            }
            SoapAutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, UserSoapAutoDiscoverRequest>((long)this.GetHashCode(), "{0}: Request '{1}' received valid response.", TraceContext.Get(), this);
            AutoDiscoverRequestResult[] array = new AutoDiscoverRequestResult[base.EmailAddresses.Length];
            for (int j = 0; j < base.EmailAddresses.Length; j++)
            {
                array[j] = this.GetAutodiscoverResultFromUserResponse(base.EmailAddresses[j], getUserSettingsResponse.UserResponses[j]);
            }
            base.HandleResult(array);
        }
Example #6
0
        private bool CompleteRequestInternal()
        {
            Uri httpRedirect = this.GetHttpRedirect(this.pendingRequest.Exception);

            if (httpRedirect != null)
            {
                this.redirectionDepth++;
                if (this.redirectionDepth > 3)
                {
                    this.SetErrorRedirectionDepthExceeded();
                    return(true);
                }
                this.pendingRequest.Dispose();
                this.pendingRequest = this.createAutoDiscoverRequest(this.Application, this.clientContext, this.requestLogger, httpRedirect, this.authenticator, this.emailAddresses, UriSource.EmailDomain, this.autodiscoverType);
                this.pendingRequest.BeginInvoke(new TaskCompleteCallback(this.CompleteRequest));
                return(false);
            }
            else
            {
                if (this.pendingRequest.Exception != null)
                {
                    AutoDiscoverQuery.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: Failed to get results from AutoDiscover for {1}, error: {2}. FE: {3}, BE: {4}", new object[]
                    {
                        TraceContext.Get(),
                        this.emailAddressesString,
                        this.pendingRequest.Exception,
                        this.pendingRequest.FrontEndServerName,
                        this.pendingRequest.BackEndServerName
                    });
                    foreach (AutoDiscoverQueryItem autoDiscoverQueryItem in this.queryItems)
                    {
                        autoDiscoverQueryItem.SetResult(new AutoDiscoverResult(new AutoDiscoverFailedException(Strings.descAutoDiscoverFailedWithException(autoDiscoverQueryItem.EmailAddress.ToString(), this.pendingRequest.Exception.ToString()), this.pendingRequest.Exception)));
                        if (!base.Aborted)
                        {
                            autoDiscoverQueryItem.SourceQuery.LogAutoDiscRequestDetails(this.pendingRequest.FrontEndServerName, this.pendingRequest.BackEndServerName, null);
                        }
                    }
                    return(true);
                }
                Dictionary <Uri, List <AutoDiscoverQueryItem> >    dictionary  = null;
                Dictionary <string, List <AutoDiscoverQueryItem> > dictionary2 = null;
                for (int j = 0; j < this.queryItems.Length; j++)
                {
                    AutoDiscoverQueryItem     autoDiscoverQueryItem2    = this.queryItems[j];
                    AutoDiscoverRequestResult autoDiscoverRequestResult = this.pendingRequest.Results[j];
                    if (autoDiscoverRequestResult.WebServiceUri != null)
                    {
                        AutoDiscoverQuery.AutoDiscoverTracer.TraceDebug((long)this.GetHashCode(), "{0}: Found WebServiceUri {1} for user {2} in the response for request at {3}", new object[]
                        {
                            TraceContext.Get(),
                            autoDiscoverRequestResult.WebServiceUri,
                            autoDiscoverQueryItem2.EmailAddress,
                            autoDiscoverRequestResult.Url
                        });
                        this.SetResult(autoDiscoverQueryItem2, autoDiscoverRequestResult.WebServiceUri);
                    }
                    else if (autoDiscoverRequestResult.Exception != null)
                    {
                        autoDiscoverQueryItem2.SetResult(new AutoDiscoverResult(new AutoDiscoverFailedException(Strings.descAutoDiscoverFailedWithException(autoDiscoverQueryItem2.EmailAddress.ToString(), autoDiscoverRequestResult.Exception.ToString()), autoDiscoverRequestResult.Exception)));
                        if (!base.Aborted)
                        {
                            autoDiscoverQueryItem2.SourceQuery.LogAutoDiscRequestDetails(autoDiscoverRequestResult.FrontEndServerName, autoDiscoverRequestResult.BackEndServerName, null);
                        }
                    }
                    else if (autoDiscoverRequestResult.AutoDiscoverRedirectUri != null)
                    {
                        AutoDiscoverQuery.AutoDiscoverTracer.TraceDebug((long)this.GetHashCode(), "{0}: Got redirect autodiscover URL for user {1} to {2}. FE: {3}, BE: {4}", new object[]
                        {
                            TraceContext.Get(),
                            autoDiscoverQueryItem2.EmailAddress,
                            autoDiscoverRequestResult.AutoDiscoverRedirectUri,
                            autoDiscoverRequestResult.FrontEndServerName,
                            autoDiscoverRequestResult.BackEndServerName
                        });
                        if (!base.Aborted)
                        {
                            autoDiscoverQueryItem2.SourceQuery.LogAutoDiscRequestDetails(autoDiscoverRequestResult.FrontEndServerName, autoDiscoverRequestResult.BackEndServerName, autoDiscoverRequestResult.AutoDiscoverRedirectUri.ToString());
                        }
                        if (dictionary == null)
                        {
                            dictionary = new Dictionary <Uri, List <AutoDiscoverQueryItem> >(1);
                        }
                        List <AutoDiscoverQueryItem> list;
                        if (!dictionary.TryGetValue(autoDiscoverRequestResult.AutoDiscoverRedirectUri, out list))
                        {
                            list = new List <AutoDiscoverQueryItem>(1);
                            dictionary.Add(autoDiscoverRequestResult.AutoDiscoverRedirectUri, list);
                        }
                        list.Add(autoDiscoverQueryItem2);
                    }
                    else if (autoDiscoverRequestResult.RedirectAddress != null)
                    {
                        AutoDiscoverQuery.AutoDiscoverTracer.TraceDebug((long)this.GetHashCode(), "{0}: Got redirect e-mail address from {1} to {2}. FE: {3}, BE: {4}", new object[]
                        {
                            TraceContext.Get(),
                            autoDiscoverQueryItem2.EmailAddress,
                            autoDiscoverRequestResult.RedirectAddress,
                            autoDiscoverRequestResult.FrontEndServerName,
                            autoDiscoverRequestResult.BackEndServerName
                        });
                        if (!base.Aborted)
                        {
                            autoDiscoverQueryItem2.SourceQuery.LogAutoDiscRequestDetails(autoDiscoverRequestResult.FrontEndServerName, autoDiscoverRequestResult.BackEndServerName, autoDiscoverRequestResult.RedirectAddress);
                        }
                        if (StringComparer.InvariantCultureIgnoreCase.Equals(autoDiscoverRequestResult.RedirectAddress, autoDiscoverQueryItem2.EmailAddress))
                        {
                            AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, EmailAddress>((long)this.GetHashCode(), "{0}: Got redirect e-mail address with same value as the original e-mail address {1}", TraceContext.Get(), autoDiscoverQueryItem2.EmailAddress);
                            autoDiscoverQueryItem2.SetResult(new AutoDiscoverResult(new AutoDiscoverFailedException(Strings.descInvalidTargetAddress(autoDiscoverRequestResult.RedirectAddress), 52540U)));
                        }
                        else if (!SmtpAddress.IsValidSmtpAddress(autoDiscoverRequestResult.RedirectAddress))
                        {
                            AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, string>((long)this.GetHashCode(), "{0}: Got redirect e-mail address which is not valid {1}", TraceContext.Get(), autoDiscoverRequestResult.RedirectAddress);
                            this.SetResult(autoDiscoverQueryItem2, Strings.descInvalidTargetAddress(autoDiscoverRequestResult.RedirectAddress), 46396U);
                        }
                        else
                        {
                            EmailAddress emailAddress = new EmailAddress(null, autoDiscoverRequestResult.RedirectAddress);
                            if (dictionary2 == null)
                            {
                                dictionary2 = new Dictionary <string, List <AutoDiscoverQueryItem> >(1);
                            }
                            List <AutoDiscoverQueryItem> list2;
                            if (!dictionary2.TryGetValue(emailAddress.Domain, out list2))
                            {
                                list2 = new List <AutoDiscoverQueryItem>(1);
                                dictionary2.Add(emailAddress.Domain, list2);
                            }
                            autoDiscoverQueryItem2.EmailAddress = emailAddress;
                            list2.Add(autoDiscoverQueryItem2);
                        }
                    }
                    else
                    {
                        AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, EmailAddress, Uri>((long)this.GetHashCode(), "{0}: Found no WebServiceUri for user {1} in the response for request at {2}", TraceContext.Get(), autoDiscoverQueryItem2.EmailAddress, autoDiscoverRequestResult.Url);
                        this.SetResult(autoDiscoverQueryItem2, Strings.descCrossForestServiceMissing(autoDiscoverQueryItem2.EmailAddress.ToString()), 62780U);
                    }
                }
                if (dictionary == null && dictionary2 == null)
                {
                    return(true);
                }
                this.redirectionDepth++;
                if (this.redirectionDepth > 3)
                {
                    this.SetErrorRedirectionDepthExceeded();
                    return(true);
                }
                List <AutoDiscoverQuery> list3 = new List <AutoDiscoverQuery>(((dictionary != null) ? dictionary.Count : 0) + ((dictionary2 != null) ? dictionary2.Count : 0));
                if (dictionary != null)
                {
                    foreach (KeyValuePair <Uri, List <AutoDiscoverQueryItem> > keyValuePair in dictionary)
                    {
                        Uri key = keyValuePair.Key;
                        AutoDiscoverQueryItem[] array2 = keyValuePair.Value.ToArray();
                        AutoDiscoverQuery       item   = this.CreateAutoDiscoverQuery(key, array2, this.redirectionDepth);
                        list3.Add(item);
                    }
                }
                if (dictionary2 != null)
                {
                    foreach (KeyValuePair <string, List <AutoDiscoverQueryItem> > keyValuePair2 in dictionary2)
                    {
                        string key2 = keyValuePair2.Key;
                        AutoDiscoverQueryItem[] array3 = keyValuePair2.Value.ToArray();
                        try
                        {
                            AutoDiscoverQuery item2 = this.CreateAutoDiscoverQuery(key2, array3, this.redirectionDepth);
                            list3.Add(item2);
                        }
                        catch (LocalizedException ex)
                        {
                            AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, string, LocalizedException>((long)this.GetHashCode(), "{0}: Failed to create AutoDiscoverQuery for {1} due exception: {2}", TraceContext.Get(), key2, ex);
                            foreach (AutoDiscoverQueryItem autoDiscoverQueryItem3 in array3)
                            {
                                autoDiscoverQueryItem3.SetResult(new AutoDiscoverResult(new AutoDiscoverFailedException(Strings.descAutoDiscoverFailedWithException(autoDiscoverQueryItem3.EmailAddress.ToString(), ex.ToString()), 38204U)));
                            }
                        }
                    }
                }
                if (list3.Count == 0)
                {
                    AutoDiscoverQuery.AutoDiscoverTracer.TraceError((long)this.GetHashCode(), "{0}: No redirect requests", new object[]
                    {
                        TraceContext.Get()
                    });
                    return(true);
                }
                this.redirectRequests        = list3.ToArray();
                this.pendingRedirectRequests = new AsyncTaskParallel(this.redirectRequests);
                this.pendingRedirectRequests.BeginInvoke(new TaskCompleteCallback(this.CompleteRedirectRequests));
                return(false);
            }
        }