public static void GetOrganizationMailboxesByCapability(IRecipientSession session, OrganizationCapability capability, ADObjectId siteId, out List <ADUser> filteredList, out List <ADUser> completeList)
 {
     ExAssert.RetailAssert(!OrganizationMailbox.IsMultiTenantEnvironment(), "GetOrganizationMailboxesByCapability (site-based) should not be used in Datacenter Multitenant environment");
     ExTraceGlobals.StorageTracer.TraceDebug <OrganizationCapability>(0L, "Entering GetOrganizationMailboxByCapability capability='{0}'", capability);
     if (siteId == null)
     {
         throw new ArgumentNullException("siteId");
     }
     completeList = OrganizationMailbox.GetOrganizationMailboxesByCapability(session, capability);
     ExTraceGlobals.StorageTracer.TraceDebug <int, OrganizationCapability>(0L, "GetOrganizationMailboxByCapability -completeList of mailbox, count='{0}', capability='{1}'", completeList.Count, capability);
     filteredList = new List <ADUser>();
     if (completeList.Count > 0)
     {
         ExTraceGlobals.StorageTracer.TraceDebug <OrganizationCapability>(0L, "GetOrganizationMailboxByCapability -GetCurrentServiceTopology capability='{0}'", capability);
         ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs", "GetOrganizationMailboxesByCapability", 137);
         foreach (ADUser aduser in completeList)
         {
             ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(session.SessionSettings, aduser, RemotingOptions.AllowCrossSite);
             string            serverFqdn        = exchangePrincipal.MailboxInfo.Location.ServerFqdn;
             ExTraceGlobals.StorageTracer.TraceDebug <string, OrganizationCapability>(0L, "GetOrganizationMailboxByCapability calling GetSite with Prinicipal.ServerFQDN='{0}', capability='{1}'", serverFqdn, capability);
             Site site       = currentServiceTopology.GetSite(serverFqdn, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs", "GetOrganizationMailboxesByCapability", 151);
             Guid objectGuid = site.Id.ObjectGuid;
             ExTraceGlobals.StorageTracer.TraceDebug <string, Guid, OrganizationCapability>(0L, "GetOrganizationMailboxByCapability  GetSite called with Prinicipal.ServerFQDN='{0}', Site='{1}'capability='{2}'", serverFqdn, objectGuid, capability);
             if (siteId.ObjectGuid.Equals(objectGuid))
             {
                 filteredList.Add(aduser);
             }
         }
     }
 }
        private static Uri GetEcpServiceUrl(ExchangePrincipal principal, ClientAccessType type)
        {
            bool enabled = VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled;

            if (principal.MailboxInfo.Location.ServerVersion >= Server.E15MinVersion && enabled)
            {
                return(TextMessagingHelper.GetE15MultitenancyEcpServiceUrl(principal, type));
            }
            ServiceTopology serviceTopology = enabled ? ServiceTopology.GetCurrentLegacyServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\sms\\TextMessagingHelper.cs", "GetEcpServiceUrl", 371) : ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\sms\\TextMessagingHelper.cs", "GetEcpServiceUrl", 371);

            if (serviceTopology != null)
            {
                IList <EcpService> list = serviceTopology.FindAll <EcpService>(principal, type, "f:\\15.00.1497\\sources\\dev\\data\\src\\ApplicationLogic\\sms\\TextMessagingHelper.cs", "GetEcpServiceUrl", 374);
                if (list != null && 0 < list.Count)
                {
                    return(list[0].Url);
                }
            }
            return(null);
        }
Exemple #3
0
        private string GetEnterpriseOrE14SharingUrl(ExchangePrincipal exchangePrincipal)
        {
            SharedFolderDataEncryption.Tracer.TraceDebug <ExchangePrincipal, bool>((long)this.GetHashCode(), "Entering GetEnterpriseOrE14SharingUrl - mailbox {0}, isMultitenancyEnabled={1}", exchangePrincipal, this.IsMultitenancyEnabled);
            ServiceTopology            serviceTopology = this.IsMultitenancyEnabled ? ServiceTopology.GetCurrentLegacyServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\SharedFolderDataEncryption.cs", "GetEnterpriseOrE14SharingUrl", 655) : ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\SharedFolderDataEncryption.cs", "GetEnterpriseOrE14SharingUrl", 655);
            IList <WebServicesService> list            = serviceTopology.FindAll <WebServicesService>(exchangePrincipal, ClientAccessType.External, SharedFolderDataEncryption.serviceVersionFilter, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\SharedFolderDataEncryption.cs", "GetEnterpriseOrE14SharingUrl", 658);

            if (list.Count != 0)
            {
                return(EwsWsSecurityUrl.Fix(list[0].Url.ToString()));
            }
            SharedFolderDataEncryption.Tracer.TraceDebug <ExchangePrincipal>((long)this.GetHashCode(), "Unable to find a CAS with external access in same site of user {0}. Trying other sites.", exchangePrincipal);
            WebServicesService webServicesService = serviceTopology.FindAny <WebServicesService>(ClientAccessType.External, SharedFolderDataEncryption.serviceVersionFilter, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\SharedFolderDataEncryption.cs", "GetEnterpriseOrE14SharingUrl", 671);

            if (webServicesService == null)
            {
                throw new NoExternalEwsAvailableException();
            }
            return(EwsWsSecurityUrl.Fix(webServicesService.Url.ToString()));
        }
        private static void SyncInternal(MailboxSession mailboxSession, ExDateTime lastSyncTime, StoreId folderId, string folderDisplayname, SecurityAccessToken securityAccessToken)
        {
            RefreshSharingFolderClient.Tracer.TraceDebug <string, IExchangePrincipal>(0L, "Sync sharing folder {0} from mailbox {1}", folderDisplayname, mailboxSession.MailboxOwner);
            if (!RefreshSharingFolderClient.CanSyncNow(lastSyncTime))
            {
                return;
            }
            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                RefreshSharingFolderClient.Tracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due exception {0}", NetworkServiceImpersonator.Exception);
                return;
            }
            string id = StoreId.StoreIdToEwsId(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, folderId);
            IList <WebServicesService> list;

            try
            {
                ClientAccessType clientAccessType = RefreshSharingFolderClient.ClientAccessType;
                RefreshSharingFolderClient.Tracer.TraceDebug <ClientAccessType>(0L, "Will try to discover the URL for EWS with the following client access type: {0}", clientAccessType);
                ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\RefreshSharingFolderClient.cs", "SyncInternal", 153);
                list = currentServiceTopology.FindAll <WebServicesService>(mailboxSession.MailboxOwner, clientAccessType, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\RefreshSharingFolderClient.cs", "SyncInternal", 154);
            }
            catch (LocalizedException arg)
            {
                RefreshSharingFolderClient.Tracer.TraceError <IExchangePrincipal, LocalizedException>(0L, "Unable to discover internal URL for EWS for mailbox {0} due exception {1}", mailboxSession.MailboxOwner, arg);
                return;
            }
            if (list.Count != 0)
            {
                string text = list[0].Url.ToString();
                RefreshSharingFolderClient.Tracer.TraceDebug <string>(0L, "Using {0} to call BeginRefreshSharingFolder", text);
                ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding("RefreshSharingFolder", new RemoteCertificateValidationCallback(RefreshSharingFolderClient.CertificateErrorHandler));
                exchangeServiceBinding.Url = text;
                exchangeServiceBinding.RequestServerVersionValue         = new RequestServerVersion();
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
                exchangeServiceBinding.UserAgent     = WellKnownUserAgent.GetEwsNegoAuthUserAgent("RefreshSharingFolder");
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
                exchangeServiceBinding.Authenticator.AdditionalSoapHeaders.Add(new SerializedSecurityContextType
                {
                    UserSid             = securityAccessToken.UserSid,
                    GroupSids           = RefreshSharingFolderClient.SidStringAndAttributesConverter(securityAccessToken.GroupSids),
                    RestrictedGroupSids = RefreshSharingFolderClient.SidStringAndAttributesConverter(securityAccessToken.RestrictedGroupSids),
                    PrimarySmtpAddress  = mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()
                });
                Exception ex = null;
                try
                {
                    exchangeServiceBinding.BeginRefreshSharingFolder(new RefreshSharingFolderType
                    {
                        SharingFolderId = new FolderIdType
                        {
                            Id = id
                        }
                    }, new AsyncCallback(RefreshSharingFolderClient.TraceResponse), exchangeServiceBinding);
                }
                catch (SoapException ex2)
                {
                    ex = ex2;
                }
                catch (WebException ex3)
                {
                    ex = ex3;
                }
                catch (IOException ex4)
                {
                    ex = ex4;
                }
                catch (InvalidOperationException ex5)
                {
                    ex = ex5;
                }
                catch (LocalizedException ex6)
                {
                    ex = ex6;
                }
                if (ex != null)
                {
                    RefreshSharingFolderClient.Tracer.TraceError <StoreId, IExchangePrincipal, Exception>(0L, "Unable to sync sharing folder {0} in mailbox {1}. Exception {2}", folderId, mailboxSession.MailboxOwner, ex);
                }
                return;
            }
            RefreshSharingFolderClient.Tracer.TraceError <IExchangePrincipal>(0L, "Unable to find internal URL for EWS for mailbox {0}", mailboxSession.MailboxOwner);
        }
        private Uri GetEnterpriseOrE14OwaServiceUrl(IExchangePrincipal exchangePrincipal)
        {
            ServiceTopology        serviceTopology = this.IsMultitenancyEnabled ? ServiceTopology.GetCurrentLegacyServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\OwaAnonymousVdirLocater.cs", "GetEnterpriseOrE14OwaServiceUrl", 230) : ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\OwaAnonymousVdirLocater.cs", "GetEnterpriseOrE14OwaServiceUrl", 230);
            Predicate <OwaService> serviceFilter   = (OwaService service) => service.AnonymousFeaturesEnabled;
            IList <OwaService>     list            = serviceTopology.FindAll <OwaService>(exchangePrincipal, ClientAccessType.External, serviceFilter, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\OwaAnonymousVdirLocater.cs", "GetEnterpriseOrE14OwaServiceUrl", 235);
            OwaService             owaService;

            if (list.Count > 0)
            {
                owaService = list[0];
            }
            else
            {
                owaService = serviceTopology.FindAny <OwaService>(ClientAccessType.External, serviceFilter, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\OwaAnonymousVdirLocater.cs", "GetEnterpriseOrE14OwaServiceUrl", 247);
                if (owaService == null)
                {
                    throw new NoExternalOwaAvailableException();
                }
            }
            return(owaService.Url);
        }