Пример #1
0
        private void ValidateAndAddToFinalSourceMailboxes(string searchQuery, StorageMiniRecipient recipient, IList <ISource> finalSourceMailboxes, IList <string> versionSkippedMailboxes, IList <string> rbacDeniedMailboxes, Dictionary <MiniRecipient, MailboxInfo> crossPremiseMailboxes)
        {
            if (!this.ExecutingUserRunspace.IsCmdletAllowedInScope("New-MailboxSearch", new string[]
            {
                "EstimateOnly"
            }, recipient, ScopeLocation.RecipientWrite))
            {
                rbacDeniedMailboxes.Add(recipient.LegacyExchangeDN);
                return;
            }
            if (!this.ValidExchangeVersion(recipient))
            {
                versionSkippedMailboxes.Add(recipient.LegacyExchangeDN);
                return;
            }
            MailboxInfo   value = new MailboxInfo(recipient, MailboxType.Primary);
            SourceMailbox item;

            if ((recipient.RecipientTypeDetails & (RecipientTypeDetails)((ulong)-2147483648)) == (RecipientTypeDetails)((ulong)-2147483648) || (recipient.RecipientTypeDetails & RecipientTypeDetails.RemoteRoomMailbox) == RecipientTypeDetails.RemoteRoomMailbox || (recipient.RecipientTypeDetails & RecipientTypeDetails.RemoteEquipmentMailbox) == RecipientTypeDetails.RemoteEquipmentMailbox || (recipient.RecipientTypeDetails & RecipientTypeDetails.RemoteTeamMailbox) == RecipientTypeDetails.RemoteTeamMailbox || (recipient.RecipientTypeDetails & RecipientTypeDetails.RemoteSharedMailbox) == RecipientTypeDetails.RemoteSharedMailbox)
            {
                crossPremiseMailboxes.Add(recipient, value);
                item = new SourceMailbox(recipient.ExternalEmailAddress.AddressString, recipient.DisplayName, recipient.LegacyExchangeDN, BackEndLocator.GetBackEndWebServicesUrl(recipient), searchQuery);
                finalSourceMailboxes.Add(item);
                return;
            }
            item = new SourceMailbox(recipient.PrimarySmtpAddress.ToString(), recipient.DisplayName, recipient.LegacyExchangeDN, BackEndLocator.GetBackEndWebServicesUrl(recipient), searchQuery);
            ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromMiniRecipient(recipient, RemotingOptions.AllowCrossSite);

            if (exchangePrincipal.MailboxInfo.Location.ServerVersion < Server.E15MinVersion || exchangePrincipal.MailboxInfo.Location == null || string.IsNullOrEmpty(exchangePrincipal.MailboxInfo.Location.ServerFqdn))
            {
                versionSkippedMailboxes.Add(recipient.LegacyExchangeDN);
                return;
            }
            finalSourceMailboxes.Add(item);
        }
Пример #2
0
        public IList <ISource> GetFinalSources(string searchObjectName, string searchQuery, string executingUserPrimarySmtpAddress, Uri discoveryUserUri)
        {
            List <ISource> list = new List <ISource>();

            DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, this.recipientSession.SessionSettings, 930, "GetFinalSources", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\MailboxSearch\\Common\\MailboxSearchConfigurationProvider.cs");
            if (discoveryUserUri != null)
            {
                EwsClient ewsClient = new EwsClient(discoveryUserUri, new ServerToServerEwsCallingContext(null));
                string    empty     = string.Empty;
                List <SourceInformation.SourceConfiguration> list2 = ewsClient.FunctionalInterface.RetrieveSearchConfiguration(searchObjectName, out empty, executingUserPrimarySmtpAddress);
                int num = 0;
                foreach (SourceInformation.SourceConfiguration sourceConfiguration in list2)
                {
                    string name = string.Empty;
                    string id   = string.Empty;
                    bool   flag = sourceConfiguration.Name.StartsWith("\\");
                    if (flag)
                    {
                        name = sourceConfiguration.Id;
                        id   = sourceConfiguration.Name;
                    }
                    else
                    {
                        name = sourceConfiguration.Name;
                        id   = sourceConfiguration.Id;
                    }
                    string        legacyDN = flag ? executingUserPrimarySmtpAddress : sourceConfiguration.LegacyExchangeDN;
                    SourceMailbox item     = new SourceMailbox(id, name, legacyDN, discoveryUserUri, searchQuery);
                    list.Add(item);
                    if ((long)(++num) > (long)((ulong)this.MaxMailboxesToSearch))
                    {
                        throw new SearchTooManyMailboxesException((int)this.MaxMailboxesToSearch);
                    }
                }
                return(list);
            }
            return(new List <ISource>());
        }
Пример #3
0
        public IList <ISource> ValidateAndGetFinalSourceMailboxes(string searchQuery, IList <string> sourceMailboxes, IList <string> notFoundMailboxes, IList <string> versionSkippedMailboxes, IList <string> rbacDeniedMailboxes, IList <string> crossPremiseFailedMailboxes, IDictionary <Uri, string> crossPremiseUrls)
        {
            Util.ThrowIfNullOrEmpty(searchQuery, "Search query cannot be empty.");
            Util.ThrowIfNull(sourceMailboxes, "sourceMailboxes");
            Util.ThrowIfNull(notFoundMailboxes, "notFoundMailboxes");
            Util.ThrowIfNull(versionSkippedMailboxes, "versionSkippedMailboxes");
            Util.ThrowIfNull(rbacDeniedMailboxes, "rbacDeniedMailboxes");
            Util.ThrowIfNull(crossPremiseFailedMailboxes, "crossPremiseFailedMailboxes");
            Util.ThrowIfNull(crossPremiseUrls, "crossPremiseUrls");
            List <ISource> list = new List <ISource>();
            Dictionary <MiniRecipient, MailboxInfo> dictionary = new Dictionary <MiniRecipient, MailboxInfo>();
            int num = 0;

            if (sourceMailboxes.Count == 0)
            {
                AndFilter filter = new AndFilter(new QueryFilter[]
                {
                    new OrFilter(new QueryFilter[]
                    {
                        Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.UserMailbox),
                        Util.CreateRecipientTypeDetailsValueFilter((RecipientTypeDetails)((ulong)int.MinValue)),
                        Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.RemoteRoomMailbox),
                        Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.RemoteEquipmentMailbox),
                        Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.RemoteSharedMailbox),
                        Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.RemoteTeamMailbox)
                    }),
                    new NotFilter(Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.ArbitrationMailbox)),
                    new NotFilter(Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.MonitoringMailbox)),
                    new NotFilter(Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.AuditLogMailbox)),
                    new NotFilter(Util.CreateRecipientTypeDetailsValueFilter(RecipientTypeDetails.MailboxPlan))
                });
                this.CheckRecipientSessionIsNotNull();
                ADPagedReader <StorageMiniRecipient> adpagedReader = this.recipientSession.FindPagedMiniRecipient <StorageMiniRecipient>(null, QueryScope.SubTree, filter, null, 1000, SearchMailboxCriteria.RecipientTypeDetailsProperty);
                using (IEnumerator <StorageMiniRecipient> enumerator = adpagedReader.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        StorageMiniRecipient storageMiniRecipient = enumerator.Current;
                        if (!storageMiniRecipient.LegacyExchangeDN.Equals(this.SearchObject.Target, StringComparison.OrdinalIgnoreCase))
                        {
                            if ((long)(++num) > (long)((ulong)this.MaxMailboxesToSearch))
                            {
                                throw new SearchTooManyMailboxesException((int)this.MaxMailboxesToSearch);
                            }
                            this.ValidateAndAddToFinalSourceMailboxes(searchQuery, storageMiniRecipient, list, versionSkippedMailboxes, rbacDeniedMailboxes, dictionary);
                        }
                    }
                    goto IL_2B6;
                }
            }
            foreach (ADObjectId adobjectId in this.ExpandGroupMembers(sourceMailboxes, this.DiscoverySystemMailboxUser.OrganizationId, notFoundMailboxes))
            {
                if ((this.SearchObject.Target == null || !adobjectId.Equals(this.TargetMailboxUser.Id)) && !adobjectId.Equals(this.DiscoverySystemMailboxUser.Id))
                {
                    this.CheckRecipientSessionIsNotNull();
                    StorageMiniRecipient storageMiniRecipient2 = this.recipientSession.ReadMiniRecipient <StorageMiniRecipient>(adobjectId, SearchMailboxCriteria.RecipientTypeDetailsProperty);
                    if (storageMiniRecipient2 != null)
                    {
                        if ((long)(++num) > (long)((ulong)this.MaxMailboxesToSearch))
                        {
                            throw new SearchTooManyMailboxesException((int)this.MaxMailboxesToSearch);
                        }
                        this.ValidateAndAddToFinalSourceMailboxes(searchQuery, storageMiniRecipient2, list, versionSkippedMailboxes, rbacDeniedMailboxes, dictionary);
                    }
                    else
                    {
                        Util.Tracer.TraceError <string>((long)this.GetHashCode(), "Unable to find mailbox: {0}", adobjectId.Name);
                    }
                }
            }
IL_2B6:
            if (dictionary.Count > 0)
            {
                string domain = dictionary.First <KeyValuePair <MiniRecipient, MailboxInfo> >().Value.GetDomain();
                Util.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Before autodiscover for cross premise domain: {0}", domain);
                Uri uri = null;
                EndPointDiscoveryInfo endPointDiscoveryInfo;
                bool flag = RemoteDiscoveryEndPoint.TryGetDiscoveryEndPoint(this.SearchDataProvider.OrganizationId, domain, null, null, null, out uri, out endPointDiscoveryInfo);
                if (endPointDiscoveryInfo != null)
                {
                    ScenarioData.Current["IOC"] = ((int)endPointDiscoveryInfo.Status).ToString();
                    if (endPointDiscoveryInfo.Status != EndPointDiscoveryInfo.DiscoveryStatus.Success)
                    {
                        SearchEventLogger.Instance.LogSearchErrorEvent(ScenarioData.Current["SID"], endPointDiscoveryInfo.Message);
                    }
                }
                if (flag)
                {
                    Util.Tracer.TraceDebug <Uri>((long)this.GetHashCode(), "Auto discover Url : {1}", uri);
                    ICredentials       oauthCredentialsForAppToken = OAuthCredentials.GetOAuthCredentialsForAppToken(this.SearchDataProvider.OrganizationId, domain);
                    List <MailboxInfo> list2 = new List <MailboxInfo>(dictionary.Count);
                    foreach (KeyValuePair <MiniRecipient, MailboxInfo> keyValuePair in dictionary)
                    {
                        list2.Add(keyValuePair.Value);
                    }
                    IAutodiscoveryClient autodiscoveryClient = Factory.Current.CreateUserSettingAutoDiscoveryClient(list2, EwsWsSecurityUrl.FixForAnonymous(uri), oauthCredentialsForAppToken, new CallerInfo(true, null, null, string.Empty, null, null, null));
                    IAsyncResult         result = autodiscoveryClient.BeginAutodiscover(null, null);
                    Dictionary <GroupId, List <MailboxInfo> > dictionary2 = autodiscoveryClient.EndAutodiscover(result);
                    if (dictionary2 != null)
                    {
                        using (Dictionary <GroupId, List <MailboxInfo> > .Enumerator enumerator4 = dictionary2.GetEnumerator())
                        {
                            while (enumerator4.MoveNext())
                            {
                                KeyValuePair <GroupId, List <MailboxInfo> > keyValuePair2 = enumerator4.Current;
                                if (keyValuePair2.Key.GroupType == GroupType.CrossPremise)
                                {
                                    if (!crossPremiseUrls.ContainsKey(keyValuePair2.Key.Uri))
                                    {
                                        crossPremiseUrls.Add(keyValuePair2.Key.Uri, domain);
                                    }
                                    using (List <ISource> .Enumerator enumerator5 = list.GetEnumerator())
                                    {
                                        while (enumerator5.MoveNext())
                                        {
                                            ISource       source        = enumerator5.Current;
                                            SourceMailbox sourceMailbox = (SourceMailbox)source;
                                            foreach (MailboxInfo mailboxInfo in keyValuePair2.Value)
                                            {
                                                if (string.Compare(sourceMailbox.LegacyExchangeDN, mailboxInfo.LegacyExchangeDN, StringComparison.OrdinalIgnoreCase) == 0)
                                                {
                                                    sourceMailbox.ServiceEndpoint = keyValuePair2.Key.Uri;
                                                    break;
                                                }
                                            }
                                        }
                                        continue;
                                    }
                                }
                                if (keyValuePair2.Key.GroupType == GroupType.SkippedError)
                                {
                                    foreach (MailboxInfo mailboxInfo2 in keyValuePair2.Value)
                                    {
                                        Util.Tracer.TraceError <SmtpAddress>((long)this.GetHashCode(), "Auto discover skipped error for mailbox: {0}", mailboxInfo2.PrimarySmtpAddress);
                                        crossPremiseFailedMailboxes.Add(mailboxInfo2.LegacyExchangeDN);
                                    }
                                }
                            }
                            goto IL_5F2;
                        }
                    }
                    Util.Tracer.TraceError <string>((long)this.GetHashCode(), "Auto discover results is null for domain: {0}", domain);
                }
                else
                {
                    Util.Tracer.TraceError <string>((long)this.GetHashCode(), "Organization relationship is not set up for domain: {0}", domain);
                    foreach (KeyValuePair <MiniRecipient, MailboxInfo> keyValuePair3 in dictionary)
                    {
                        crossPremiseFailedMailboxes.Add(keyValuePair3.Value.LegacyExchangeDN);
                    }
                }
            }
IL_5F2:
            if (crossPremiseFailedMailboxes.Count > 0)
            {
                foreach (string b in crossPremiseFailedMailboxes)
                {
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        ISource source2 = list[i];
                        if (source2.LegacyExchangeDN == b)
                        {
                            list.RemoveAt(i);
                        }
                    }
                }
            }
            return(list);
        }