Example #1
0
 internal ADSessionSettings GetTenantScopedADSessionSettingsServiceOnly()
 {
     if (this.externalDirectoryOrganizationId != null)
     {
         ExTraceGlobals.GetConnectionTracer.TraceDebug <string>(0L, "FromTenantPartitionHint(): Partition hint '{0}' has externalDirectoryOrganizationId initialized, no need to lookup", this.ToString());
         if (this.externalDirectoryOrganizationId == TenantPartitionHint.ExternalDirectoryOrganizationIdForRootOrg)
         {
             return(ADSessionSettings.FromRootOrgScopeSet());
         }
         return(ADSessionSettings.FromExternalDirectoryOrganizationId(this.externalDirectoryOrganizationId.Value));
     }
     else
     {
         ADSessionSettings           sessionSettings            = ADSessionSettings.FromAllTenantsPartitionId(this.partitionId);
         ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, sessionSettings, 442, "GetTenantScopedADSessionSettingsServiceOnly", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\TenantPartitionHint.cs");
         ExTraceGlobals.GetConnectionTracer.TraceDebug <TenantPartitionHint>(0L, "FromTenantPartitionHint(): Partition hint '{0}' has externalDirectoryOrganizationId not initialized, need to read this property from AD, looking up", this);
         ExchangeConfigurationUnit exchangeConfigurationUnitByName = tenantConfigurationSession.GetExchangeConfigurationUnitByName(this.tenantName);
         if (exchangeConfigurationUnitByName != null)
         {
             ExTraceGlobals.GetConnectionTracer.TraceDebug <TenantPartitionHint>(0L, "FromTenantPartitionHint(): Partition hint '{0}' has PartitionId and tenantName initialized, reading this OrganizationId property from CU", this);
             return(ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(exchangeConfigurationUnitByName.OrganizationId));
         }
         ExTraceGlobals.GetConnectionTracer.TraceDebug <TenantPartitionHint>(0L, "FromTenantPartitionHint(): Partition hint '{0}' has partitionId and tenantName initialized, but failed to find this tenant's CU", this);
         Globals.LogEvent(DirectoryEventLogConstants.Tuple_CannotResolveExternalDirectoryOrganizationId, this.tenantName, new object[]
         {
             DirectoryStrings.CannotResolveTenantName(this.tenantName),
             Environment.StackTrace
         });
         throw new CannotResolveExternalDirectoryOrganizationIdException(DirectoryStrings.CannotResolveTenantName(this.tenantName));
     }
 }
        // Token: 0x0600032B RID: 811 RVA: 0x0001163C File Offset: 0x0000F83C
        private static TenantPartitionCacheItem SearchForTenantInfoByExternalOrgId(Guid externalOrgId, PartitionId partitionId)
        {
            if (partitionId == null)
            {
                throw new ArgumentNullException("partitionId");
            }
            if (partitionId.PartitionObjectId == null || partitionId.PartitionObjectId.Value == Guid.Empty)
            {
                throw new ArgumentNullException("partitionId.PartitionObjectId");
            }
            ADSessionSettings           sessionSettings                       = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
            ITenantConfigurationSession tenantConfigurationSession            = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, sessionSettings, 985, "SearchForTenantInfoByExternalOrgId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\ADAccountPartitionLocator.cs");
            ExchangeConfigurationUnit   exchangeConfigurationUnitByExternalId = tenantConfigurationSession.GetExchangeConfigurationUnitByExternalId(externalOrgId);

            if (exchangeConfigurationUnitByExternalId != null)
            {
                string name = exchangeConfigurationUnitByExternalId.Id.Parent.Name;
                if (ExchangeConfigurationUnit.IsInactiveRelocationNode(exchangeConfigurationUnitByExternalId))
                {
                    ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByExternalOrgId() found organization in partition {0} - inactive due to relocation, skipping.", partitionId.ForestFQDN);
                }
                else
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByExternalOrgId() found organization in partition {0}.", partitionId.ForestFQDN);
                        return(new TenantPartitionCacheItem(partitionId.PartitionObjectId.Value, partitionId.ForestFQDN, PartitionId.LocalForest.ForestFQDN, externalOrgId, name, false));
                    }
                    ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByExternalOrgId() found organization in partition {0} - not fully provisioned, ExternalDirectoryOrganizationId or partitionGuid is not populated, skipping.", partitionId.ForestFQDN);
                }
            }
            return(null);
        }
Example #3
0
        internal static OrganizationId FromTenantForestAndCN(string exoAccountForest, string exoTenantContainer)
        {
            PartitionId                 partitionId     = new PartitionId(exoAccountForest);
            ADSessionSettings           sessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
            ITenantConfigurationSession session         = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 505, "FromTenantForestAndCN", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\OrganizationId.cs");

            return(OrganizationId.FromTenantContainerCN(exoTenantContainer, session));
        }
        // Token: 0x060072B9 RID: 29369 RVA: 0x0017BC24 File Offset: 0x00179E24
        internal override IThrottlingPolicy InternalLookup()
        {
            ExchangeConfigurationUnit cu = null;
            ADOperationResult         adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
            {
                PartitionId partitionIdByAcceptedDomainName = ADAccountPartitionLocator.GetPartitionIdByAcceptedDomainName(this.principal.DelegatedOrganization);
                if (partitionIdByAcceptedDomainName != null)
                {
                    ADSessionSettings sessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionIdByAcceptedDomainName);
                    ITenantConfigurationSession tenantConfigurationSession           = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, sessionSettings, 86, "InternalLookup", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\throttling\\DelegatedPrincipalBudgetKey.cs");
                    tenantConfigurationSession.SessionSettings.IsSharedConfigChecked = true;
                    cu = tenantConfigurationSession.GetExchangeConfigurationUnitByNameOrAcceptedDomain(this.principal.DelegatedOrganization);
                }
                if (cu == null)
                {
                    throw new CannotResolveTenantNameException(DirectoryStrings.CannotResolveTenantNameByAcceptedDomain(this.principal.DelegatedOrganization));
                }
            });

            if (!adoperationResult.Succeeded)
            {
                ExTraceGlobals.ClientThrottlingTracer.TraceError <string, string, Exception>((long)this.GetHashCode(), "[DelegatedPrincipalBudgetKey.Lookup] Failed to find Delegated Organization: '{0}' for user '{1}', using global throttling policy.  Exception: '{2}'", this.principal.DelegatedOrganization, this.principal.UserId, adoperationResult.Exception);
                return(ThrottlingPolicyCache.Singleton.GetGlobalThrottlingPolicy());
            }
            OrganizationId orgId = cu.OrganizationId;

            if (cu.SupportedSharedConfigurations.Count > 0)
            {
                SharedConfiguration sharedConfig = null;
                adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
                {
                    sharedConfig = SharedConfiguration.GetSharedConfiguration(cu.OrganizationId);
                });
                if (!adoperationResult.Succeeded)
                {
                    ExTraceGlobals.ClientThrottlingTracer.TraceError <OrganizationId, Exception>((long)this.GetHashCode(), "[DelegatedPrincipalBudgetKey.Lookup] Failed to get Shared Configuration Organization: '{0}', using global throttling policy.  Exception: '{1}'", cu.OrganizationId, adoperationResult.Exception);
                    return(ThrottlingPolicyCache.Singleton.GetGlobalThrottlingPolicy());
                }
                if (sharedConfig != null)
                {
                    orgId = sharedConfig.SharedConfigId;
                }
            }
            return(base.ADRetryLookup(delegate
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromAllTenantsOrRootOrgAutoDetect(orgId);
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 149, "InternalLookup", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\throttling\\DelegatedPrincipalBudgetKey.cs");
                tenantOrTopologyConfigurationSession.SessionSettings.IsSharedConfigChecked = true;
                ThrottlingPolicy organizationThrottlingPolicy = tenantOrTopologyConfigurationSession.GetOrganizationThrottlingPolicy(orgId, false);
                if (organizationThrottlingPolicy == null)
                {
                    ExTraceGlobals.ClientThrottlingTracer.TraceError <string, string>((long)this.GetHashCode(), "[DelegatedPrincipalBudgetKey.Lookup] Failed to find Default Throttling Policy for '{0}\\{1}', using global throttling policy", this.principal.DelegatedOrganization, this.principal.UserId);
                    return ThrottlingPolicyCache.Singleton.GetGlobalThrottlingPolicy();
                }
                return organizationThrottlingPolicy.GetEffectiveThrottlingPolicy(true);
            }));
        }
 public static void RunOperationOnAllAccountPartitions(bool readOnly, PartitionDataAggregator.OperationDelegate operation)
 {
     foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds())
     {
         ADSessionSettings sessionSettings  = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
         IRecipientSession recipientSession = DirectorySessionFactory.Default.CreateTenantRecipientSession(readOnly, ConsistencyMode.IgnoreInvalid, sessionSettings, 185, "RunOperationOnAllAccountPartitions", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
         operation(recipientSession);
     }
 }
 internal override ADSessionSettings FromAllTenantsOrRootOrgAutoDetect(OrganizationId orgId)
 {
     if (orgId == null)
     {
         throw new ArgumentNullException("orgId");
     }
     if (!OrganizationId.ForestWideOrgId.Equals(orgId))
     {
         return(ADSessionSettings.FromAllTenantsPartitionId(orgId.PartitionId));
     }
     return(ADSessionSettings.FromRootOrgScopeSet());
 }
        // Token: 0x06000328 RID: 808 RVA: 0x00011284 File Offset: 0x0000F484
        private static TenantPartitionCacheItem SearchForTenantInfoByUserNetID(string userNetID, PartitionId partitionId)
        {
            GlsDirectorySession.ThrowIfInvalidNetID(userNetID, "userNetID");
            if (partitionId == null)
            {
                throw new ArgumentNullException("partitionId");
            }
            ADSessionSettings           sessionSettings                      = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
            ITenantConfigurationSession tenantConfigurationSession           = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, sessionSettings, 711, "SearchForTenantInfoByUserNetID", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\ADAccountPartitionLocator.cs");
            ExchangeConfigurationUnit   exchangeConfigurationUnitByUserNetID = tenantConfigurationSession.GetExchangeConfigurationUnitByUserNetID(userNetID);

            if (exchangeConfigurationUnitByUserNetID != null)
            {
                string externalDirectoryOrganizationId = exchangeConfigurationUnitByUserNetID.ExternalDirectoryOrganizationId;
                string name = exchangeConfigurationUnitByUserNetID.Id.Parent.Name;
                ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByUserNetID() found organization in partition {0}.", partitionId.ForestFQDN);
                return(new TenantPartitionCacheItem((partitionId.PartitionObjectId != null) ? partitionId.PartitionObjectId.Value : Guid.Empty, partitionId.ForestFQDN, PartitionId.LocalForest.ForestFQDN, new Guid(externalDirectoryOrganizationId), name, false));
            }
            return(null);
        }
        public static IEnumerable <ADUser> GetUMEnabledUsersInDatabase(MailboxDatabase database)
        {
            QueryFilter filter = UMMailbox.GetUMEnabledUserQueryFilter(database);

            foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds(true))
            {
                ADSessionSettings           settings        = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
                ITenantRecipientSession     session         = DirectorySessionFactory.Default.CreateTenantRecipientSession(null, null, LcidMapper.DefaultLcid, true, ConsistencyMode.IgnoreInvalid, null, settings, 199, "GetUMEnabledUsersInDatabase", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
                ADPagedReader <ADRecipient> recipientReader = session.FindPaged(null, QueryScope.SubTree, filter, null, 0);
                foreach (ADRecipient recipient in recipientReader)
                {
                    ADUser user = recipient as ADUser;
                    if (user != null)
                    {
                        yield return(user);
                    }
                }
            }
            yield break;
        }
        private static IEnumerable <T> FindPaged <T>(QueryFilter filter, bool includeRetiredTenants = false, SortBy sortBy = null) where T : ADConfigurationObject, new()
        {
            PartitionId[] allAccountPartitionIds = ADAccountPartitionLocator.GetAllAccountPartitionIds();
            int           i = 0;

            while (i < allAccountPartitionIds.Length)
            {
                PartitionId       partitionId = allAccountPartitionIds[i];
                ADPagedReader <T> tenantReader;
                try
                {
                    ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
                    if (includeRetiredTenants)
                    {
                        adsessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants;
                    }
                    ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, adsessionSettings, 641, "FindPaged", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
                    tenantReader = tenantConfigurationSession.FindPaged <T>(null, QueryScope.SubTree, filter, sortBy, 0);
                }
                catch (OrgContainerNotFoundException)
                {
                    if (Globals.IsDatacenter)
                    {
                        goto IL_10B;
                    }
                    throw;
                }
                goto IL_AF;
IL_10B:
                i++;
                continue;
IL_AF:
                foreach (T request in tenantReader)
                {
                    yield return(request);
                }
                goto IL_10B;
            }
            yield break;
        }
Example #10
0
        private static OrganizationId FromPartition <T>(T lookupKey, Guid externalDirectoryOrganizationId, string tenantContainerCN, PartitionId partitionId, Func <ITenantConfigurationSession, OrganizationId> GetOrgFromAD, Func <Exception> CreateNotFoundException)
        {
            ADSessionSettings           sessionSettings            = ADSessionSettings.FromAllTenantsPartitionId(partitionId);
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 561, "FromPartition", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\OrganizationId.cs");

            if (!string.IsNullOrEmpty(tenantContainerCN))
            {
                OrganizationId organizationId = OrganizationId.FromTenantContainerCN(tenantContainerCN, tenantConfigurationSession);
                organizationId.externalDirectoryOrganizationId = new Guid?(externalDirectoryOrganizationId);
                return(organizationId);
            }
            OrganizationId organizationId2 = GetOrgFromAD(tenantConfigurationSession);

            if (organizationId2 != null)
            {
                ExTraceGlobals.GLSTracer.TraceDebug <OrganizationId, T>(0L, "[OrganizationIdConvertor.FromExternalDirectoryOrganizationId]: Found OrganizationId {0} for {1}", organizationId2, lookupKey);
                Guid value = Guid.Empty;
                if (externalDirectoryOrganizationId == Guid.Empty)
                {
                    ADRawEntry adrawEntry = tenantConfigurationSession.ReadADRawEntry(organizationId2.ConfigurationUnit, new PropertyDefinition[]
                    {
                        ExchangeConfigurationUnitSchema.ExternalDirectoryOrganizationId
                    });
                    if (adrawEntry != null)
                    {
                        Guid.TryParse(adrawEntry[ExchangeConfigurationUnitSchema.ExternalDirectoryOrganizationId].ToString(), out value);
                    }
                }
                else
                {
                    value = externalDirectoryOrganizationId;
                }
                organizationId2.externalDirectoryOrganizationId = new Guid?(value);
                return(organizationId2);
            }
            throw CreateNotFoundException();
        }
        // Token: 0x06000327 RID: 807 RVA: 0x0001115C File Offset: 0x0000F35C
        private static TenantPartitionCacheItem SearchForTenantInfoByOrganizationName(string organizationName, PartitionId partitionId)
        {
            if (string.IsNullOrEmpty(organizationName))
            {
                throw new ArgumentNullException("organizationName");
            }
            if (partitionId == null)
            {
                throw new ArgumentNullException("partitionId");
            }
            ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId);

            adsessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants;
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, adsessionSettings, 643, "SearchForTenantInfoByOrganizationName", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\ADAccountPartitionLocator.cs");
            ExchangeConfigurationUnit   exchangeConfigurationUnitByNameOrAcceptedDomain = tenantConfigurationSession.GetExchangeConfigurationUnitByNameOrAcceptedDomain(organizationName);

            if (exchangeConfigurationUnitByNameOrAcceptedDomain != null)
            {
                if (ExchangeConfigurationUnit.IsInactiveRelocationNode(exchangeConfigurationUnitByNameOrAcceptedDomain))
                {
                    ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByOrganizationName() found organization in partition {0} - inactive due to relocation, skipping.", partitionId.ForestFQDN);
                }
                else
                {
                    string externalDirectoryOrganizationId = exchangeConfigurationUnitByNameOrAcceptedDomain.ExternalDirectoryOrganizationId;
                    string name = exchangeConfigurationUnitByNameOrAcceptedDomain.Id.Parent.Name;
                    if (!string.IsNullOrEmpty(name))
                    {
                        ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByOrganizationName() found organization in partition {0}.", partitionId.ForestFQDN);
                        return(new TenantPartitionCacheItem((partitionId.PartitionObjectId != null) ? partitionId.PartitionObjectId.Value : Guid.Empty, partitionId.ForestFQDN, PartitionId.LocalForest.ForestFQDN, new Guid(externalDirectoryOrganizationId), name, false));
                    }
                    ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "SearchForTenantInfoByOrganizationName() found organization in partition {0} - not fully provisioned, ExternalDirectoryOrganizationId or partitionGuid is not populated, skipping.", partitionId.ForestFQDN);
                }
            }
            return(null);
        }
        // Token: 0x0600116D RID: 4461 RVA: 0x00053DF8 File Offset: 0x00051FF8
        public static ExchangeConfigurationUnit[] LoadSharedConfigurationsSorted(OrganizationId orgId)
        {
            if (orgId.Equals(OrganizationId.ForestWideOrgId))
            {
                return(null);
            }
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(orgId.PartitionId), 151, "LoadSharedConfigurationsSorted", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SharedConfiguration.cs");

            ExchangeConfigurationUnit[] array = tenantConfigurationSession.FindSharedConfigurationByOrganizationId(orgId);
            if (array.Length > 1)
            {
                Array.Sort <ExchangeConfigurationUnit>(array, new Comparison <ExchangeConfigurationUnit>(SharedConfiguration.CompareBySharedConfigurationInfo));
            }
            return(array);
        }
        internal static ADPagedReader <ExchangeConfigurationUnit> FindAllTempateTenants(string programId, string offerId, PartitionId partitionId)
        {
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 236, "FindAllTempateTenants", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\TemplateTenantConfiguration.cs");
            QueryFilter filter = new AndFilter(new QueryFilter[]
            {
                new ExistsFilter(OrganizationSchema.SharedConfigurationInfo),
                new ComparisonFilter(ComparisonOperator.Equal, ExchangeConfigurationUnitSchema.ResellerId, programId + "." + offerId),
                new ComparisonFilter(ComparisonOperator.Equal, ExchangeConfigurationUnitSchema.OrganizationStatus, OrganizationStatus.Active),
                new ComparisonFilter(ComparisonOperator.Equal, OrganizationSchema.EnableAsSharedConfiguration, true)
            });

            return(tenantConfigurationSession.FindPaged <ExchangeConfigurationUnit>(null, QueryScope.SubTree, filter, null, 0));
        }
 // Token: 0x0600117B RID: 4475 RVA: 0x000543C8 File Offset: 0x000525C8
 private void LoadTinyTenantCUIfNecessary()
 {
     if (this.tinyTenantCU == null)
     {
         IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsPartitionId(this.tinyTenantId.PartitionId), 587, "LoadTinyTenantCUIfNecessary", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SharedConfiguration.cs");
         this.tinyTenantCU = tenantOrTopologyConfigurationSession.Read <ExchangeConfigurationUnit>(this.tinyTenantId.ConfigurationUnit);
     }
 }
        // Token: 0x0600117F RID: 4479 RVA: 0x000544FC File Offset: 0x000526FC
        internal static ExchangeConfigurationUnit FindOneSharedConfiguration(SharedConfigurationInfo sci, PartitionId partitionId)
        {
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 657, "FindOneSharedConfiguration", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SharedConfiguration.cs");

            ExchangeConfigurationUnit[] array = tenantConfigurationSession.FindSharedConfiguration(sci, true);
            if (array == null || array.Length == 0)
            {
                return(null);
            }
            if (array.Length == 1)
            {
                return(array[0]);
            }
            Random random = new Random();

            return(array[random.Next(array.Length)]);
        }
 // Token: 0x06001171 RID: 4465 RVA: 0x00054010 File Offset: 0x00052210
 public static bool IsDehydratedConfiguration(OrganizationId orgId)
 {
     return(Globals.IsDatacenter && !(orgId == null) && !OrganizationId.ForestWideOrgId.Equals(orgId) && !DatacenterRegistry.IsForefrontForOffice() && ProvisioningCache.Instance.TryAddAndGetOrganizationData <bool>(CannedProvisioningCacheKeys.IsDehydratedConfigurationCacheKey, orgId, delegate()
     {
         IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsPartitionId(orgId.PartitionId), 310, "IsDehydratedConfiguration", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SharedConfiguration.cs");
         ExchangeConfigurationUnit[] array = tenantOrTopologyConfigurationSession.Find <ExchangeConfigurationUnit>(orgId.ConfigurationUnit, QueryScope.Base, new ExistsFilter(OrganizationSchema.SupportedSharedConfigurations), null, 1);
         return array != null && array.Length == 1 && array[0].IsDehydrated;
     }));
 }
 // Token: 0x06001177 RID: 4471 RVA: 0x0005429C File Offset: 0x0005249C
 public static SharedTenantConfigurationState GetSharedConfigurationState(OrganizationId orgId)
 {
     if (OrganizationId.ForestWideOrgId.Equals(orgId))
     {
         return(SharedTenantConfigurationState.UnSupported);
     }
     return(ProvisioningCache.Instance.TryAddAndGetOrganizationData <SharedTenantConfigurationState>(CannedProvisioningCacheKeys.SharedConfigurationStateCacheKey, orgId, delegate()
     {
         IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsPartitionId(orgId.PartitionId), 461, "GetSharedConfigurationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SharedConfiguration.cs");
         ExchangeConfigurationUnit[] array = tenantOrTopologyConfigurationSession.Find <ExchangeConfigurationUnit>(orgId.ConfigurationUnit, QueryScope.Base, QueryFilter.OrTogether(new QueryFilter[]
         {
             new ExistsFilter(OrganizationSchema.SupportedSharedConfigurations),
             new ExistsFilter(OrganizationSchema.SharedConfigurationInfo)
         }), null, 1);
         if (array == null || array.Length != 1)
         {
             return SharedTenantConfigurationState.NotShared;
         }
         if (null != array[0].SharedConfigurationInfo)
         {
             return SharedTenantConfigurationState.Shared;
         }
         SharedTenantConfigurationState sharedTenantConfigurationState = SharedTenantConfigurationState.UnSupported;
         if (array[0].IsStaticConfigurationShared)
         {
             sharedTenantConfigurationState |= SharedTenantConfigurationState.Static;
         }
         if (array[0].IsDehydrated)
         {
             sharedTenantConfigurationState |= SharedTenantConfigurationState.Dehydrated;
         }
         return sharedTenantConfigurationState;
     }));
 }
        private static TenantRelocationState LoadTenantRelocationState(string tenantName, PartitionId partitionId)
        {
            ITenantConfigurationSession session = DirectorySessionFactory.NonCacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 185, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ExchangeConfigurationUnit   exchangeCUAndThrowIfNotFound = TenantRelocationStateCache.GetExchangeCUAndThrowIfNotFound(tenantName, session);

            if (exchangeCUAndThrowIfNotFound.IsCached)
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Tenant {0} found in cache.", tenantName);
                if ((DateTime.UtcNow - exchangeCUAndThrowIfNotFound.WhenReadUTC).Value.TotalSeconds >= 30.0)
                {
                    ITenantConfigurationSession session2 = DirectorySessionFactory.NonCacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 203, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
                    exchangeCUAndThrowIfNotFound = TenantRelocationStateCache.GetExchangeCUAndThrowIfNotFound(tenantName, session2);
                    ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.CacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 206, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
                    tenantConfigurationSession.Delete(exchangeCUAndThrowIfNotFound);
                    tenantConfigurationSession.Save(exchangeCUAndThrowIfNotFound);
                }
            }
            if ((string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest) && string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw)) || (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw) && exchangeCUAndThrowIfNotFound.RelocationStateRequested == RelocationStateRequested.Cleanup))
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string, bool>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} Cached {2} - not being relocated.", tenantName, exchangeCUAndThrowIfNotFound.OriginatingServer, exchangeCUAndThrowIfNotFound.IsCached);
                return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
            }
            if (string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId))
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string, bool>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} Cached {2} - prepared for deletion.", tenantName, exchangeCUAndThrowIfNotFound.OriginatingServer, exchangeCUAndThrowIfNotFound.IsCached);
                TenantRelocationStatus sourceForestState;
                if (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest))
                {
                    sourceForestState = exchangeCUAndThrowIfNotFound.RelocationStatus;
                }
                else
                {
                    sourceForestState = TenantRelocationStatus.NotStarted;
                }
                return(new TenantRelocationState(partitionId.ForestFQDN, sourceForestState));
            }
            if (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest))
            {
                TenantRelocationRequest tenantRelocationRequest;
                Exception ex;
                TenantRelocationRequest.LoadOtherForestObjectInternal(null, exchangeCUAndThrowIfNotFound.TargetForest, exchangeCUAndThrowIfNotFound.DistinguishedName, exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId, true, out tenantRelocationRequest, out ex);
                if (ex != null && !(ex is CannotFindTargetTenantException))
                {
                    throw ex;
                }
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} - this is relocation source.", tenantName, (tenantRelocationRequest != null) ? tenantRelocationRequest.OriginatingServer : "<unknown>");
                return(new TenantRelocationState(partitionId.ForestFQDN, exchangeCUAndThrowIfNotFound.RelocationStatus, exchangeCUAndThrowIfNotFound.TargetForest, (RelocationStatusDetailsDestination)((tenantRelocationRequest != null) ? tenantRelocationRequest.RelocationStatusDetailsRaw : RelocationStatusDetails.NotStarted), exchangeCUAndThrowIfNotFound.OrganizationId, (tenantRelocationRequest != null) ? tenantRelocationRequest.OrganizationId : null));
            }
            else
            {
                Exception ex;
                TenantRelocationRequest tenantRelocationRequest2;
                TenantRelocationRequest.LoadOtherForestObjectInternal(null, exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw, exchangeCUAndThrowIfNotFound.DistinguishedName, exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId, false, out tenantRelocationRequest2, out ex);
                if (ex == null)
                {
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug(0L, string.Format("TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} - this is relocation target.", tenantName, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.OriginatingServer : "<unknown>"));
                    return(new TenantRelocationState(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.RelocationStatus : TenantRelocationStatus.NotStarted, partitionId.ForestFQDN, (RelocationStatusDetailsDestination)exchangeCUAndThrowIfNotFound.RelocationStatusDetailsSource, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.OrganizationId : null, exchangeCUAndThrowIfNotFound.OrganizationId));
                }
                if (ex is CannotFindTargetTenantException)
                {
                    return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
                }
                throw ex;
            }
        }
        // Token: 0x06001170 RID: 4464 RVA: 0x00053F30 File Offset: 0x00052130
        public static bool IsSharedConfiguration(OrganizationId orgId)
        {
            if (OrganizationId.ForestWideOrgId.Equals(orgId))
            {
                return(false);
            }
            IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsPartitionId(orgId.PartitionId), 279, "IsSharedConfiguration", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SharedConfiguration.cs");

            ExchangeConfigurationUnit[] array = tenantOrTopologyConfigurationSession.Find <ExchangeConfigurationUnit>(orgId.ConfigurationUnit, QueryScope.Base, new ExistsFilter(OrganizationSchema.SharedConfigurationInfo), null, 1);
            return(array != null && array.Length == 1);
        }
Example #20
0
        private static TimeSpan CalculateCacheItemExpirationWindow(bool dataFromOfflineService, string tenantName, Guid externalOrgId, PartitionId accountPartitionId)
        {
            if (dataFromOfflineService)
            {
                return(TimeSpan.FromMinutes((double)ConfigBase <AdDriverConfigSchema> .GetConfig <int>("OfflineDataCacheExpirationTimeInMinutes")));
            }
            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(accountPartitionId.ForestFQDN))
            {
                return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.DefaultExpirationWindow);
            }
            if (!string.IsNullOrEmpty(tenantName))
            {
                return(TenantRelocationStateCache.GetTenantCacheExpirationWindow(tenantName, accountPartitionId));
            }
            ITenantConfigurationSession tenantConfigurationSession            = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(accountPartitionId), 110, "CalculateCacheItemExpirationWindow", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\TenantPartitionCacheItem.cs");
            ExchangeConfigurationUnit   exchangeConfigurationUnitByExternalId = tenantConfigurationSession.GetExchangeConfigurationUnitByExternalId(externalOrgId);

            if (exchangeConfigurationUnitByExternalId != null)
            {
                tenantName = ((ADObjectId)exchangeConfigurationUnitByExternalId.Identity).Parent.Name;
                return(TenantRelocationStateCache.GetTenantCacheExpirationWindow(tenantName, accountPartitionId));
            }
            return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.DefaultExpirationWindow);
        }
        internal static bool TryLoadTenantRelocationStateSourceReplica(string tenantName, PartitionId partitionId, out RelocationStatusDetailsSource status)
        {
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 164, "TryLoadTenantRelocationStateSourceReplica", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");

            tenantConfigurationSession.SessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants;
            ExchangeConfigurationUnit exchangeConfigurationUnitByName = tenantConfigurationSession.GetExchangeConfigurationUnitByName(tenantName);

            if (exchangeConfigurationUnitByName != null)
            {
                status = exchangeConfigurationUnitByName.RelocationStatusDetailsSource;
                return(true);
            }
            status = RelocationStatusDetailsSource.NotStarted;
            return(false);
        }
        public static MiniRecipient GetMiniRecipientFromUserId(SecurityIdentifier sid, IEnumerable <PropertyDefinition> properties, ConsistencyMode consistencyMode)
        {
            MiniRecipient miniRecipient = null;

            foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds())
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, consistencyMode, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 249, "GetMiniRecipientFromUserId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
                try
                {
                    miniRecipient = tenantOrRootOrgRecipientSession.FindMiniRecipientBySid <MiniRecipient>(sid, properties);
                }
                catch (NonUniqueRecipientException)
                {
                }
                if (miniRecipient != null)
                {
                    break;
                }
            }
            return(miniRecipient);
        }
        public static ADRawEntry FindUserBySid(SecurityIdentifier sId, IList <PropertyDefinition> properties, ref IRecipientSession recipientSession)
        {
            ADRawEntry adrawEntry = null;

            foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds())
            {
                ITenantRecipientSession tenantRecipientSession = DirectorySessionFactory.Default.CreateTenantRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 286, "FindUserBySid", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
                adrawEntry = tenantRecipientSession.FindUserBySid(sId, properties);
                if (adrawEntry != null)
                {
                    recipientSession = tenantRecipientSession;
                    break;
                }
            }
            return(adrawEntry);
        }
        public static ADUser[] FindAllArbitrationMailboxes(string legDN)
        {
            List <ADUser> list = new List <ADUser>();

            foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds())
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 367, "FindAllArbitrationMailboxes", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
                ADUser[]          collection = tenantOrRootOrgRecipientSession.FindPaged <ADUser>(RecipientFilterHelper.DiscoveryMailboxFilterForAuditLog(legDN), null, true, null, 0).ToArray <ADUser>();
                list.AddRange(collection);
            }
            return(list.ToArray());
        }
 internal override ADSessionSettings FromAllTenantsObjectId(ADObjectId id)
 {
     return(ADSessionSettings.FromAllTenantsPartitionId(id.GetPartitionId()));
 }
        public static bool TryGetTenantRelocationStateByObjectId(ADObjectId identity, out TenantRelocationState state, out bool isSourceTenant)
        {
            ArgumentValidator.ThrowIfNull("identity", identity);
            state          = null;
            isSourceTenant = true;
            PartitionId partitionId = identity.GetPartitionId();

            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(partitionId.ForestFQDN))
            {
                return(false);
            }
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 595, "TryGetTenantRelocationStateByObjectId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ADObjectId configurationUnitsRoot = tenantConfigurationSession.GetConfigurationUnitsRoot();

            if (configurationUnitsRoot.Equals(identity))
            {
                return(false);
            }
            ADObjectId adobjectId = null;

            if (identity.IsDescendantOf(configurationUnitsRoot))
            {
                adobjectId = identity.GetFirstGenerationDecendantOf(configurationUnitsRoot);
            }
            else
            {
                ADObjectId hostedOrganizationsRoot = tenantConfigurationSession.GetHostedOrganizationsRoot();
                if (hostedOrganizationsRoot.Equals(identity))
                {
                    return(false);
                }
                if (identity.IsDescendantOf(hostedOrganizationsRoot))
                {
                    adobjectId = identity.GetFirstGenerationDecendantOf(hostedOrganizationsRoot);
                }
            }
            if (adobjectId == null)
            {
                return(false);
            }
            try
            {
                state = TenantRelocationStateCache.GetTenantRelocationState(adobjectId.Name, partitionId, out isSourceTenant, false);
            }
            catch (CannotResolveTenantNameException)
            {
                return(false);
            }
            return(true);
        }