// Token: 0x0600032C RID: 812 RVA: 0x00011758 File Offset: 0x0000F958
        private static TenantPartitionCacheItem FindTenantInfoByAcceptedDomain(string acceptedDomain)
        {
            PartitionId partitionId;

            if (!ADSessionSettings.IsGlsDisabled)
            {
                TenantPartitionCacheItem tenantPartitionCacheItem;
                if (ADAccountPartitionLocator.TryLookUpAccountForest(Guid.Empty, acceptedDomain, null, out tenantPartitionCacheItem))
                {
                    return(tenantPartitionCacheItem);
                }
            }
            else if (ADAccountPartitionLocator.IsSingleForestTopology(out partitionId))
            {
                ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "GLS is disabled, performing the only partition lookup for {0}", acceptedDomain);
                return(ADAccountPartitionLocator.SearchForTenantInfoByOrganizationName(acceptedDomain, partitionId));
            }
            if (GlsMServDirectorySession.ShouldScanAllForests)
            {
                ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                PartitionId[] array = ADAccountPartitionLocator.allAccountPartitionIds;
                foreach (PartitionId partitionId2 in array)
                {
                    TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.SearchForTenantInfoByOrganizationName(acceptedDomain, partitionId2);
                    if (tenantPartitionCacheItem != null)
                    {
                        ADAccountPartitionLocator.InsertCacheMaps(tenantPartitionCacheItem, acceptedDomain, null);
                        return(tenantPartitionCacheItem);
                    }
                }
            }
            return(null);
        }
 // Token: 0x06000335 RID: 821 RVA: 0x00011C9B File Offset: 0x0000FE9B
 private static void EnsureAllowedCallerForUnregisteredAccountPartition(TenantPartitionCacheItem item)
 {
     if (ADAccountPartitionLocator.crossRFLookupCheckEnabled && !item.IsRegisteredAccountPartition)
     {
         ADAccountPartitionLocator.CheckCallStackForCrossRFLookup(item.AccountPartitionId.ForestFQDN);
     }
 }
 // Token: 0x06000334 RID: 820 RVA: 0x00011C74 File Offset: 0x0000FE74
 private static void EnsureRegisteredAccountPartition(TenantPartitionCacheItem item)
 {
     if (!item.IsRegisteredAccountPartition)
     {
         Guid guid;
         ADAccountPartitionLocator.CheckAccountPartitionIsRegistered(item.AccountPartitionId.ForestFQDN, out guid);
     }
 }
        // Token: 0x06000320 RID: 800 RVA: 0x00010EF4 File Offset: 0x0000F0F4
        public static void AddTenantDataToCache(Guid externalDirectoryOrganizationId, string resourceForestFqdn, string accountForestFqdn, string domainName, string tenantContainerCN)
        {
            Guid accountPartitionGuid;

            ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(accountForestFqdn, out accountPartitionGuid);
            TenantPartitionCacheItem tenantPartitionCacheItem = new TenantPartitionCacheItem(accountPartitionGuid, accountForestFqdn, resourceForestFqdn, externalDirectoryOrganizationId, tenantContainerCN, false);

            ADAccountPartitionLocator.EnsureRegisteredAccountPartition(tenantPartitionCacheItem);
            ADAccountPartitionLocator.InsertCacheMaps(tenantPartitionCacheItem, domainName, null);
        }
        // Token: 0x0600031A RID: 794 RVA: 0x00010C84 File Offset: 0x0000EE84
        public static string GetResourceForestFqdnByExternalDirectoryOrganizationId(Guid externalDirectoryOrganizationId)
        {
            if (!Globals.IsMicrosoftHostedOnly)
            {
                return(PartitionId.LocalForest.ForestFQDN);
            }
            TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.FindTenantInfoByExternalOrgId(externalDirectoryOrganizationId);

            if (tenantPartitionCacheItem != null)
            {
                ADAccountPartitionLocator.EnsureAllowedCallerForUnregisteredAccountPartition(tenantPartitionCacheItem);
                return(tenantPartitionCacheItem.ResourceForestFqdn);
            }
            throw new CannotResolveExternalDirectoryOrganizationIdException(DirectoryStrings.CannotResolveTenantNameByExternalDirectoryId(externalDirectoryOrganizationId.ToString()));
        }
        // Token: 0x06000319 RID: 793 RVA: 0x00010C40 File Offset: 0x0000EE40
        public static string GetResourceForestFqdnByAcceptedDomainName(string acceptedDomainName)
        {
            if (!Globals.IsMicrosoftHostedOnly)
            {
                return(PartitionId.LocalForest.ForestFQDN);
            }
            TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.FindTenantInfoByAcceptedDomain(acceptedDomainName);

            if (tenantPartitionCacheItem != null)
            {
                ADAccountPartitionLocator.EnsureAllowedCallerForUnregisteredAccountPartition(tenantPartitionCacheItem);
                return(tenantPartitionCacheItem.ResourceForestFqdn);
            }
            throw new CannotResolveTenantNameException(DirectoryStrings.CannotResolveTenantNameByAcceptedDomain(acceptedDomainName));
        }
Esempio n. 7
0
 internal TenantPartitionCacheItem(Guid accountPartitionGuid, string accountPartitionFqdn, string resourceForestFqdn, Guid externalOrgId, string tenantName, bool dataFromOfflineService = false)
 {
     ArgumentValidator.ThrowIfNullOrEmpty(accountPartitionFqdn, "accountPartitionFqdn");
     ArgumentValidator.ThrowIfNullOrEmpty(resourceForestFqdn, "resourceForestFqdn");
     if (PartitionId.IsLocalForestPartition(accountPartitionFqdn))
     {
         this.accountPartitionId = PartitionId.LocalForest;
     }
     else
     {
         this.accountPartitionId = ((accountPartitionGuid == Guid.Empty) ? new PartitionId(accountPartitionFqdn) : new PartitionId(accountPartitionFqdn, accountPartitionGuid));
     }
     this.resourceForestFqdn = resourceForestFqdn;
     this.externalOrgId      = externalOrgId;
     this.tenantName         = tenantName;
     this.expirationTime     = DateTime.UtcNow + TenantPartitionCacheItem.CalculateCacheItemExpirationWindow(dataFromOfflineService, tenantName, this.externalOrgId, this.accountPartitionId);
 }
        // Token: 0x06000329 RID: 809 RVA: 0x00011358 File Offset: 0x0000F558
        private static TenantPartitionCacheItem FindTenantInfoByExternalOrgId(Guid externalOrgId)
        {
            TenantPartitionCacheItem tenantPartitionCacheItem = null;

            if (externalOrgId == TemplateTenantConfiguration.TemplateTenantExternalDirectoryOrganizationIdGuid)
            {
                ExchangeConfigurationUnit localTemplateTenant = TemplateTenantConfiguration.GetLocalTemplateTenant();
                if (localTemplateTenant != null)
                {
                    ExTraceGlobals.GLSTracer.TraceDebug <string>(0L, "FindTenantInfoByExternalOrgId() asked for Consumer Template tenant, returning {0}", localTemplateTenant.Id.Parent.DistinguishedName);
                    string name = localTemplateTenant.Id.Parent.Name;
                    tenantPartitionCacheItem = new TenantPartitionCacheItem(Guid.Empty, localTemplateTenant.OrganizationId.PartitionId.ForestFQDN, PartitionId.LocalForest.ForestFQDN, externalOrgId, name, false);
                }
                return(tenantPartitionCacheItem);
            }
            PartitionId partitionId;

            if (!ADSessionSettings.IsGlsDisabled)
            {
                if (ADAccountPartitionLocator.TryLookUpAccountForest(externalOrgId, null, null, out tenantPartitionCacheItem))
                {
                    return(tenantPartitionCacheItem);
                }
            }
            else if (ADAccountPartitionLocator.IsSingleForestTopology(out partitionId))
            {
                ExTraceGlobals.GLSTracer.TraceDebug <Guid>(0L, "GLS is disabled, performing the only partition lookup for {0}", externalOrgId);
                return(ADAccountPartitionLocator.SearchForTenantInfoByExternalOrgId(externalOrgId, partitionId));
            }
            if (GlsMServDirectorySession.ShouldScanAllForests)
            {
                ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                PartitionId[] array = ADAccountPartitionLocator.allAccountPartitionIds;
                foreach (PartitionId partitionId2 in array)
                {
                    tenantPartitionCacheItem = ADAccountPartitionLocator.SearchForTenantInfoByExternalOrgId(externalOrgId, partitionId2);
                    if (tenantPartitionCacheItem != null)
                    {
                        ADAccountPartitionLocator.InsertCacheMaps(tenantPartitionCacheItem, null, null);
                        return(tenantPartitionCacheItem);
                    }
                }
            }
            return(null);
        }
        // Token: 0x0600031C RID: 796 RVA: 0x00010CEC File Offset: 0x0000EEEC
        public static PartitionId GetPartitionIdByExternalDirectoryOrganizationId(Guid externalDirectoryOrganizationId, out string tenantContainerCN)
        {
            tenantContainerCN = null;
            TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.FindTenantInfoByExternalOrgId(externalDirectoryOrganizationId);

            if (tenantPartitionCacheItem != null)
            {
                ADAccountPartitionLocator.EnsureAllowedCallerForUnregisteredAccountPartition(tenantPartitionCacheItem);
                tenantContainerCN = tenantPartitionCacheItem.TenantName;
                return(tenantPartitionCacheItem.AccountPartitionId);
            }
            Globals.LogEvent(DirectoryEventLogConstants.Tuple_CannotResolveExternalDirectoryOrganizationId, externalDirectoryOrganizationId.ToString(), new object[]
            {
                DirectoryStrings.CannotResolveTenantNameByExternalDirectoryId(externalDirectoryOrganizationId.ToString()),
                Environment.StackTrace
            });
            throw new CannotResolveExternalDirectoryOrganizationIdException(DirectoryStrings.CannotResolveTenantNameByExternalDirectoryId(externalDirectoryOrganizationId.ToString()));
        }
        // Token: 0x06000318 RID: 792 RVA: 0x00010BE0 File Offset: 0x0000EDE0
        public static PartitionId GetPartitionIdByAcceptedDomainName(string acceptedDomainName, out string tenantContainerCN, out Guid externalDirectoryOrganizationId)
        {
            tenantContainerCN = null;
            externalDirectoryOrganizationId = Guid.Empty;
            if (!Globals.IsMicrosoftHostedOnly)
            {
                return(PartitionId.LocalForest);
            }
            TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.FindTenantInfoByAcceptedDomain(acceptedDomainName);

            if (tenantPartitionCacheItem != null)
            {
                ADAccountPartitionLocator.EnsureAllowedCallerForUnregisteredAccountPartition(tenantPartitionCacheItem);
                tenantContainerCN = tenantPartitionCacheItem.TenantName;
                externalDirectoryOrganizationId = tenantPartitionCacheItem.ExternalOrgId;
                return(tenantPartitionCacheItem.AccountPartitionId);
            }
            throw new CannotResolveTenantNameException(DirectoryStrings.CannotResolveTenantNameByAcceptedDomain(acceptedDomainName));
        }
        // Token: 0x0600031D RID: 797 RVA: 0x00010D74 File Offset: 0x0000EF74
        public static PartitionId GetPartitionIdByMSAUserNetID(string msaUserNetID, out string tenantContainerCN, out Guid externalDirectoryOrganizationId)
        {
            tenantContainerCN = null;
            externalDirectoryOrganizationId = Guid.Empty;
            TenantPartitionCacheItem tenantPartitionCacheItem = ADAccountPartitionLocator.FindTenantInfoByMSAUserNetID(msaUserNetID);

            if (tenantPartitionCacheItem != null)
            {
                ADAccountPartitionLocator.EnsureAllowedCallerForUnregisteredAccountPartition(tenantPartitionCacheItem);
                tenantContainerCN = tenantPartitionCacheItem.TenantName;
                externalDirectoryOrganizationId = tenantPartitionCacheItem.ExternalOrgId;
                return(tenantPartitionCacheItem.AccountPartitionId);
            }
            Globals.LogEvent(DirectoryEventLogConstants.Tuple_CannotResolveMSAUserNetID, msaUserNetID, new object[]
            {
                DirectoryStrings.CannotFindTenantByMSAUserNetID(msaUserNetID),
                Environment.StackTrace
            });
            throw new CannotResolveMSAUserNetIDException(DirectoryStrings.CannotFindTenantByMSAUserNetID(msaUserNetID));
        }
        // Token: 0x0600032F RID: 815 RVA: 0x000118B8 File Offset: 0x0000FAB8
        private static void InsertCacheMaps(TenantPartitionCacheItem cacheItem, string acceptedDomain, string msaUserNetID)
        {
            bool flag = string.IsNullOrEmpty(msaUserNetID);

            if (flag)
            {
                ADAccountPartitionLocator.externalOrgIdPartitionCache.Add(cacheItem.ExternalOrgId, cacheItem);
            }
            if (!string.IsNullOrEmpty(cacheItem.TenantName))
            {
                ADAccountPartitionLocator.tenantNamePartitionCache.Add(cacheItem.TenantName, cacheItem);
            }
            if (!string.IsNullOrEmpty(acceptedDomain))
            {
                ADAccountPartitionLocator.acceptedDomainPartitionCache.Add(acceptedDomain, cacheItem);
            }
            if (!flag)
            {
                ADAccountPartitionLocator.msaUserNetIdPartitionCache.Add(msaUserNetID, cacheItem);
            }
        }
        // Token: 0x0600032A RID: 810 RVA: 0x00011460 File Offset: 0x0000F660
        private static bool TryLookUpAccountForest(Guid externalDirectoryOrganizationId, string acceptedDomain, string msaUserNetID, out TenantPartitionCacheItem cacheItem)
        {
            cacheItem = null;
            Exception ex = null;

            if (acceptedDomain == string.Empty)
            {
                throw new ArgumentException(acceptedDomain);
            }
            if (msaUserNetID == string.Empty)
            {
                throw new ArgumentException(msaUserNetID);
            }
            try
            {
                IGlobalDirectorySession globalSession = DirectorySessionFactory.GetGlobalSession(null);
                bool   dataFromOfflineService         = false;
                string resourceForestFqdn;
                string text;
                string tenantName;
                bool   flag;
                if (acceptedDomain != null)
                {
                    if (ADAccountPartitionLocator.acceptedDomainPartitionCache.TryGetValue(acceptedDomain, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.AcceptedDomain, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.AcceptedDomain, false);
                    string text2;
                    flag = globalSession.TryGetTenantForestsByDomain(acceptedDomain, out externalDirectoryOrganizationId, out resourceForestFqdn, out text, out text2, out tenantName, out dataFromOfflineService);
                }
                else if (externalDirectoryOrganizationId != Guid.Empty)
                {
                    if (ADAccountPartitionLocator.externalOrgIdPartitionCache.TryGetValue(externalDirectoryOrganizationId, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.ExternalDirectoryObjectId, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.ExternalDirectoryObjectId, false);
                    flag = globalSession.TryGetTenantForestsByOrgGuid(externalDirectoryOrganizationId, out resourceForestFqdn, out text, out tenantName, out dataFromOfflineService);
                }
                else
                {
                    if (ADAccountPartitionLocator.msaUserNetIdPartitionCache.TryGetValue(msaUserNetID, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.MSAUserNetID, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.MSAUserNetID, false);
                    flag = globalSession.TryGetTenantForestsByMSAUserNetID(msaUserNetID, out externalDirectoryOrganizationId, out resourceForestFqdn, out text, out tenantName);
                }
                if (flag)
                {
                    ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                    Guid accountPartitionGuid;
                    ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(text, out accountPartitionGuid);
                    cacheItem = new TenantPartitionCacheItem(accountPartitionGuid, text, resourceForestFqdn, externalDirectoryOrganizationId, tenantName, dataFromOfflineService);
                    ADAccountPartitionLocator.InsertCacheMaps(cacheItem, acceptedDomain, msaUserNetID);
                    return(true);
                }
            }
            catch (MServTransientException ex2)
            {
                ex = ex2;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (MServPermanentException ex3)
            {
                ex = ex3;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (TransientException ex4)
            {
                ex = ex4;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (GlsPermanentException ex5)
            {
                ex = ex5;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (GlsTenantNotFoundException ex6)
            {
                ex = ex6;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            if (ex != null)
            {
                ExTraceGlobals.GLSTracer.TraceWarning <Exception>(0L, "Got exception while doing GLS lookup in ADAccountPartitionLocator, ignoring it until 2605034 is fixed {0}", ex);
            }
            return(false);
        }