Exemple #1
0
        protected override void SetResult(AutoDiscoverQueryItem queryItem, LocalizedString exceptionString, uint locationIdentifier)
        {
            WebServiceUri webServiceUri = new WebServiceUri(null, exceptionString, queryItem.EmailAddress);

            base.AddWebServiceUriToCache(queryItem, webServiceUri);
            queryItem.SetResult(new AutoDiscoverResult(new AutoDiscoverFailedException(exceptionString, locationIdentifier)));
        }
Exemple #2
0
 public override void BeginInvoke(TaskCompleteCallback callback)
 {
     base.BeginInvoke(callback);
     this.queryItems        = AutoDiscoverQueryItem.CreateAutoDiscoverQueryItems(base.Application, base.QueryList, this.targetForestConfiguration.AutoDiscoverUrl);
     this.autoDiscoverQuery = new AutoDiscoverQueryInternal(base.Application, base.ClientContext, base.RequestLogger, this.targetForestConfiguration, this.queryItems, new CreateAutoDiscoverRequestDelegate(AutoDiscoverRequestXmlByUser.Create), base.QueryList);
     this.autoDiscoverQuery.BeginInvoke(new TaskCompleteCallback(this.Complete1));
 }
Exemple #3
0
        protected override void SetResult(AutoDiscoverQueryItem queryItem, WebServiceUri webServiceUri)
        {
            WebServiceUri webServiceUri2 = new WebServiceUri(webServiceUri, this.targetForestConfiguration.Credentials, queryItem.EmailAddress);

            base.AddWebServiceUriToCache(queryItem, webServiceUri2);
            queryItem.SetResult(this.GetResult(queryItem.RecipientData, webServiceUri2));
        }
 public override void BeginInvoke(TaskCompleteCallback callback)
 {
     base.BeginInvoke(callback);
     this.queryItems        = AutoDiscoverQueryItem.CreateAutoDiscoverQueryItems(base.Application, base.QueryList, this.targetForestConfiguration.AutoDiscoverUrl);
     this.autoDiscoverQuery = new AutoDiscoverQueryInternal(base.Application, base.ClientContext, base.RequestLogger, this.targetForestConfiguration, this.queryItems, this.createAutoDiscoverRequest, base.QueryList);
     this.requestTimer      = Stopwatch.StartNew();
     this.autoDiscoverQuery.BeginInvoke(new TaskCompleteCallback(this.Complete1));
 }
Exemple #5
0
        public override void BeginInvoke(TaskCompleteCallback callback)
        {
            base.BeginInvoke(callback);
            ProxyAuthenticator proxyAuthenticator = ProxyAuthenticator.Create(OAuthCredentialsFactory.CreateAsApp(base.ClientContext as InternalClientContext, base.RequestLogger), base.ClientContext.MessageId, true);

            this.queryItems        = AutoDiscoverQueryItem.CreateAutoDiscoverQueryItems(base.Application, base.QueryList, this.autoDiscoverUrl);
            this.autoDiscoverQuery = new AutoDiscoverQueryExternalByOAuth(base.Application, base.ClientContext, base.RequestLogger, this.autoDiscoverUrl, proxyAuthenticator, this.queryItems, this.createAutoDiscoverRequest, base.QueryList);
            this.autoDiscoverQuery.BeginInvoke(new TaskCompleteCallback(this.Complete1));
        }
Exemple #6
0
        protected void AddWebServiceUriToCache(AutoDiscoverQueryItem queryItem, WebServiceUri webServiceUri)
        {
            int autodiscoverVersionBucket = this.Application.GetAutodiscoverVersionBucket(this.autodiscoverType);

            RemoteServiceUriCache.Add(queryItem.EmailAddress, webServiceUri, autodiscoverVersionBucket);
            if (queryItem.InitialEmailAddress != queryItem.EmailAddress)
            {
                RemoteServiceUriCache.Add(queryItem.InitialEmailAddress, webServiceUri, autodiscoverVersionBucket);
            }
        }
Exemple #7
0
        public static AutoDiscoverQueryItem[] CreateAutoDiscoverQueryItems(Application application, QueryList queryList, Uri autoDiscoverUrl)
        {
            AutoDiscoverQueryItem[] array = new AutoDiscoverQueryItem[queryList.Count];
            string target = autoDiscoverUrl.ToString();

            for (int i = 0; i < queryList.Count; i++)
            {
                queryList[i].Target = target;
                array[i]            = new AutoDiscoverQueryItem(queryList[i].RecipientData, application.Name, queryList[i]);
            }
            return(array);
        }
Exemple #8
0
        protected override void SetResult(AutoDiscoverQueryItem queryItem, WebServiceUri webServiceUri)
        {
            WebServiceUri webServiceUri2 = new WebServiceUri(webServiceUri, null, queryItem.EmailAddress);

            base.AddWebServiceUriToCache(queryItem, webServiceUri2);
            AutoDiscoverResult result;

            if (!base.Application.IsVersionSupportedForExternalUser(webServiceUri.ServerVersion))
            {
                AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, int, Type>((long)this.GetHashCode(), "{0}: Remote server version {1} is considered a legacy server by {2} application for external user.", TraceContext.Get(), webServiceUri.ServerVersion, base.Application.GetType());
                result = new AutoDiscoverResult(base.Application.CreateExceptionForUnsupportedVersion(queryItem.RecipientData, webServiceUri.ServerVersion));
            }
            else
            {
                result = new AutoDiscoverResult(webServiceUri2, base.Authenticator.ProxyAuthenticator);
            }
            queryItem.SetResult(result);
        }
Exemple #9
0
 protected abstract void SetResult(AutoDiscoverQueryItem queryItem, LocalizedString exceptionString, uint locationIdentifier);
Exemple #10
0
 protected abstract void SetResult(AutoDiscoverQueryItem queryItem, WebServiceUri webServiceUri);
Exemple #11
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);
            }
        }