internal override ADSessionSettings FromAllTenantsOrRootOrgAutoDetect(ADObjectId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.DomainId == null)
            {
                ExTraceGlobals.GetConnectionTracer.TraceDebug <string>(0L, "FromAllTenantsOrRootOrgAutoDetect(): Value '{0}' passed to id parameter doesn't have DomainId initialized, falling back to RootOrg scope set", id.ToString());
                return(ADSessionSettings.FromRootOrgScopeSet());
            }
            PartitionId partitionId = id.GetPartitionId();

            if (!ADAccountPartitionLocator.IsKnownPartition(partitionId))
            {
                ExTraceGlobals.GetConnectionTracer.TraceDebug <string>(0L, "FromAllTenantsOrRootOrgAutoDetect(): Value '{0}' passed to id parameter doesn't match any known partition, falling back to RootOrg scope set", id.ToString());
                return(ADSessionSettings.FromRootOrgScopeSet());
            }
            ExTraceGlobals.GetConnectionTracer.TraceDebug <string, string>(0L, "FromAllTenantsOrRootOrgAutoDetect(): Value '{0}' passed to id parameter matches partition {1}, returning settings bound to that partition", id.ToString(), partitionId.ToString());
            if (ADSession.IsTenantIdentity(id, partitionId.ForestFQDN))
            {
                return(ADSessionSettings.FromAllTenantsObjectId(id));
            }
            if (!TopologyProvider.IsAdamTopology())
            {
                return(ADSessionSettings.FromAccountPartitionRootOrgScopeSet(id.GetPartitionId()));
            }
            return(ADSessionSettings.FromRootOrgScopeSet());
        }
示例#2
0
        public static DatabaseInformation FindServerForMdb(ADObjectId database, string dcName, NetworkCredential cred, FindServerFlags flags)
        {
            if (!ConfigBase <MRSConfigSchema> .GetConfig <bool>("CrossResourceForestEnabled"))
            {
                return(MapiUtils.FindServerForMdb(database.ObjectGuid, dcName, cred, flags));
            }
            Guid empty = Guid.Empty;
            DatabaseInformation result;

            try
            {
                if (database.GetPartitionId().IsLocalForestPartition())
                {
                    result = MapiUtils.FindServerForMdb(database.ObjectGuid, dcName, cred, flags);
                }
                else
                {
                    BackEndServer backEndServer = BackEndLocator.GetBackEndServer(database);
                    result = DatabaseInformation.FromBackEndServer(database, backEndServer);
                }
            }
            catch (BackEndLocatorException)
            {
                MrsTracer.Common.Debug("BE Locator was unable to locate MDB {0}.", new object[]
                {
                    database.ObjectGuid
                });
                if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None)
                {
                    throw;
                }
                result = DatabaseInformation.Missing(database.ObjectGuid, database.PartitionFQDN);
            }
            return(result);
        }
示例#3
0
        internal static bool IsTenantIdentity(ADObjectId id, string partitionFqdn)
        {
            if (ADSession.IsBoundToAdam || id.DomainId == null)
            {
                return(false);
            }
            if (!string.Equals(id.GetPartitionId().ForestFQDN, partitionFqdn, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("Object partition FQDN doesn't match partitionFqdn parameter.");
            }
            ADObjectId configurationNamingContext = ADSession.GetConfigurationNamingContext(partitionFqdn);

            if (id.Equals(configurationNamingContext))
            {
                return(false);
            }
            ADObjectId domainNamingContext = ADSession.GetDomainNamingContext(partitionFqdn);

            if (id.Equals(domainNamingContext))
            {
                return(false);
            }
            ADObjectId configurationUnitsRoot = ADSession.GetConfigurationUnitsRoot(partitionFqdn);

            if (id.IsDescendantOf(configurationUnitsRoot))
            {
                return(true);
            }
            ADObjectId hostedOrganizationsRoot = ADSession.GetHostedOrganizationsRoot(partitionFqdn);

            return(id.IsDescendantOf(hostedOrganizationsRoot) && !id.Equals(hostedOrganizationsRoot));
        }
        public static ExchangeConfigurationUnit GetExchangeConfigurationUnit(ADObjectId organizationMailboxId)
        {
            if (!ADSession.IsTenantIdentity(organizationMailboxId, organizationMailboxId.GetPartitionId().ForestFQDN))
            {
                throw new InvalidOperationException();
            }
            ADSessionSettings           sessionSettings            = ADSessionSettings.FromAllTenantsObjectId(organizationMailboxId);
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 495, "GetExchangeConfigurationUnit", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs");
            ExchangePrincipal           exchangePrincipal          = OrganizationMailbox.GetExchangePrincipal(organizationMailboxId);

            return(tenantConfigurationSession.Read <ExchangeConfigurationUnit>(exchangePrincipal.MailboxInfo.OrganizationId.ConfigurationUnit));
        }
 internal static EphemeralIdTable.NamingContext GetNamingContext(ADObjectId id)
 {
     if (id.IsDescendantOf(ADSession.GetConfigurationNamingContext(id.GetPartitionId().ForestFQDN)))
     {
         if (!ADSession.IsTenantIdentity(id, id.GetPartitionId().ForestFQDN))
         {
             return(EphemeralIdTable.NamingContext.Config);
         }
         return(EphemeralIdTable.NamingContext.TenantConfig);
     }
     else
     {
         if (!ADSession.IsTenantIdentity(id, id.GetPartitionId().ForestFQDN))
         {
             return(EphemeralIdTable.NamingContext.Domain);
         }
         if (!id.IsDescendantOf(ADSession.GetConfigurationUnitsRoot(id.GetPartitionId().ForestFQDN)))
         {
             return(EphemeralIdTable.NamingContext.Domain);
         }
         return(EphemeralIdTable.NamingContext.TenantConfig);
     }
 }
        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);
        }
        public static ITopologyConfigurationSession GetConfigSessionForDatabase(ITopologyConfigurationSession originalConfigSession, ADObjectId database)
        {
            ITopologyConfigurationSession result = originalConfigSession;

            if (database != null && ConfigBase <MRSConfigSchema> .GetConfig <bool>("CrossResourceForestEnabled"))
            {
                PartitionId partitionId = database.GetPartitionId();
                if (!partitionId.IsLocalForestPartition())
                {
                    ADSessionSettings sessionSettings = ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId);
                    result = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(null, true, ConsistencyMode.PartiallyConsistent, null, sessionSettings, 612, "GetConfigSessionForDatabase", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxReplication\\RequestBase\\RequestTaskHelper.cs");
                }
            }
            return(result);
        }
        private static ExchangePrincipal GetExchangePrincipal(ADObjectId organizationMailboxId)
        {
            IRecipientSession recipientSession;

            if (ADSession.IsTenantIdentity(organizationMailboxId, organizationMailboxId.GetPartitionId().ForestFQDN))
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromAllTenantsObjectId(organizationMailboxId);
                recipientSession = DirectorySessionFactory.Default.CreateTenantRecipientSession(null, null, LcidMapper.DefaultLcid, true, ConsistencyMode.IgnoreInvalid, null, sessionSettings, 515, "GetExchangePrincipal", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs");
            }
            else
            {
                ADSessionSettings sessionSettings2 = ADSessionSettings.FromRootOrgScopeSet();
                recipientSession = DirectorySessionFactory.Default.CreateRootOrgRecipientSession(null, null, LcidMapper.DefaultLcid, true, ConsistencyMode.IgnoreInvalid, null, sessionSettings2, 528, "GetExchangePrincipal", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\OrganizationMailbox\\OrganizationMailbox.cs");
            }
            ADUser aduser = recipientSession.Read(organizationMailboxId) as ADUser;

            if (aduser == null)
            {
                throw new ADNoSuchObjectException(DirectoryStrings.OrganizationMailboxNotFound(organizationMailboxId.ToString()));
            }
            return(ExchangePrincipal.FromADUser(aduser, RemotingOptions.AllowCrossSite));
        }
示例#9
0
        // Token: 0x06000354 RID: 852 RVA: 0x00012094 File Offset: 0x00010294
        private static ADNotificationRequestCookie RegisterChangeNotification <T>(T dummyObject, ADObjectId baseDN, ADNotificationCallback callback, object context) where T : ADConfigurationObject, new()
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (baseDN == null || string.IsNullOrEmpty(baseDN.DistinguishedName))
            {
                throw new ArgumentNullException("baseDN");
            }
            string forestFQDN = baseDN.GetPartitionId().ForestFQDN;

            if (!baseDN.IsDescendantOf(ADSession.GetConfigurationNamingContext(forestFQDN)) && !ADSession.IsTenantIdentity(baseDN, forestFQDN))
            {
                throw new ArgumentException(DirectoryStrings.ExArgumentException("baseDN", baseDN), "baseDN");
            }
            ADNotificationRequest adnotificationRequest = new ADNotificationRequest(typeof(T), dummyObject.MostDerivedObjectClass, baseDN, callback, context);

            ADNotificationListener.RegisterChangeNotification(adnotificationRequest);
            return(new ADNotificationRequestCookie(new ADNotificationRequest[]
            {
                adnotificationRequest
            }));
        }
示例#10
0
 internal virtual ADSessionSettings FromRootOrgBootStrapSession(ADObjectId configNC)
 {
     if (configNC == null)
     {
         throw new ArgumentNullException("configNC");
     }
     return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(ADSessionSettings.SessionSettingsFactory.GlobalScopeSet, configNC, OrganizationId.ForestWideOrgId, null, ConfigScopes.RootOrg, TopologyProvider.IsAdamTopology() ? PartitionId.LocalForest : configNC.GetPartitionId()));
 }
示例#11
0
 private void Initialize(ADObjectId orgUnit, ADObjectId configUnit)
 {
     if (orgUnit == null)
     {
         throw new ArgumentNullException("orgUnit");
     }
     if (configUnit == null)
     {
         throw new ArgumentNullException("configUnit");
     }
     this.orgUnit     = orgUnit;
     this.configUnit  = configUnit;
     this.partitionId = ((orgUnit.DomainId != null && !PartitionId.IsLocalForestPartition(orgUnit.PartitionFQDN)) ? orgUnit.GetPartitionId() : PartitionId.LocalForest);
 }
示例#12
0
        public static string GetDeploymentType(ADObjectId id)
        {
            string result = string.Empty;

            if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled)
            {
                string name = id.Parent.Name;
                ITenantConfigurationSession tenantConfigurationSession      = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(id.GetPartitionId()), 84, "GetDeploymentType", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\SQM\\SmsSqmDataPointHelper.cs");
                ExchangeConfigurationUnit   exchangeConfigurationUnitByName = tenantConfigurationSession.GetExchangeConfigurationUnitByName(name);
                result = exchangeConfigurationUnitByName.ProgramId;
            }
            else
            {
                result = "On-Premises";
            }
            return(result);
        }
示例#13
0
 internal static bool IsTenantConfigObjectInCorrectNC(ADObjectId tenantObjectId)
 {
     return(tenantObjectId == null || tenantObjectId.DomainId == null || ADSessionSettings.IsForefrontObject(tenantObjectId) || tenantObjectId.ToDNString().IndexOf("cn=configuration,dc=", StringComparison.OrdinalIgnoreCase) < 0 || !ADSession.IsTenantConfigInDomainNC(tenantObjectId.GetPartitionId().ForestFQDN));
 }
示例#14
0
        public static ExDateTime GetPasswordExpirationDate(ADObjectId adUserObjectId, IRecipientSession recipientSession)
        {
            if (adUserObjectId.IsNullOrEmpty())
            {
                throw new ArgumentException("ADUser object ID cannot be null or empty", "adUserObjectId");
            }
            ADUser aduser = recipientSession.Read(adUserObjectId) as ADUser;

            if (aduser == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
            }
            if ((aduser.UserAccountControl & UserAccountControlFlags.DoNotExpirePassword) != UserAccountControlFlags.None)
            {
                return(ExDateTime.MaxValue);
            }
            ExDateTime?exDateTime = null;

            if (aduser.PasswordLastSet != null)
            {
                exDateTime = new ExDateTime?(new ExDateTime(ExTimeZone.UtcTimeZone, aduser.PasswordLastSet.Value));
            }
            if (exDateTime == null)
            {
                return(ExDateTime.MaxValue);
            }
            IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(adUserObjectId.GetPartitionId()), 86, "GetPasswordExpirationDate", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\DirectoryHelper.cs");

            tenantOrTopologyConfigurationSession.UseConfigNC = false;
            ADDomain addomain = tenantOrTopologyConfigurationSession.Read <ADDomain>(aduser.Id.DomainId);

            if (addomain == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
            }
            EnhancedTimeSpan?maximumPasswordAge = addomain.MaximumPasswordAge;
            TimeSpan?        timeSpan           = (maximumPasswordAge != null) ? new TimeSpan?(maximumPasswordAge.GetValueOrDefault()) : null;

            if (timeSpan == null || timeSpan == TimeSpan.Zero)
            {
                return(ExDateTime.MaxValue);
            }
            return(exDateTime.Value.Add(timeSpan.Value));
        }
 internal override ADSessionSettings FromAllTenantsObjectId(ADObjectId id)
 {
     return(ADSessionSettings.FromAllTenantsPartitionId(id.GetPartitionId()));
 }
示例#16
0
            internal virtual ADSessionSettings FromOrganizationIdWithoutRbacScopes(ADObjectId rootOrgId, OrganizationId currentOrganizationId, OrganizationId executingUserOrganizationId, bool scopeToExecutingUserOrgId, bool allowRehoming)
            {
                if (rootOrgId == null)
                {
                    throw new ArgumentNullException("rootOrgId");
                }
                if (null == currentOrganizationId)
                {
                    throw new ArgumentNullException("currentOrganizationId");
                }
                if (scopeToExecutingUserOrgId && executingUserOrganizationId == null)
                {
                    throw new ArgumentException("scopeToExecutingUserOrgId + null executingUserOrganizationId");
                }
                if (allowRehoming)
                {
                    currentOrganizationId       = this.RehomeScopingOrganizationIdIfNeeded(currentOrganizationId);
                    executingUserOrganizationId = this.RehomeScopingOrganizationIdIfNeeded(executingUserOrganizationId);
                }
                OrganizationId organizationId = currentOrganizationId;

                if (scopeToExecutingUserOrgId)
                {
                    organizationId = executingUserOrganizationId;
                }
                ScopeSet     orgWideDefaultScopeSet = ScopeSet.GetOrgWideDefaultScopeSet(organizationId);
                ConfigScopes configScopes           = ConfigScopes.TenantLocal;

                return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(orgWideDefaultScopeSet, rootOrgId, currentOrganizationId, executingUserOrganizationId, configScopes, (currentOrganizationId.PartitionId != null) ? currentOrganizationId.PartitionId : (Globals.IsMicrosoftHostedOnly ? rootOrgId.GetPartitionId() : null)));
            }
 // Token: 0x060007E4 RID: 2020 RVA: 0x0001D079 File Offset: 0x0001B279
 public AccountPartitionIdParameter(ADObjectId adobjectid) : base(adobjectid)
 {
     this.fqdn = new Fqdn(adobjectid.GetPartitionId().ForestFQDN);
 }
        internal ADUser ReadADUser(ADObjectId userId, Guid exchangeGuid)
        {
            if (userId == null)
            {
                return(null);
            }
            ADRecipient adrecipient = this.Read <ADRecipient>(delegate(IRecipientSession session)
            {
                if (CommonUtils.IsMultiTenantEnabled() && exchangeGuid != Guid.Empty && !userId.GetPartitionId().Equals(this.RecipientSession.SessionSettings.PartitionId))
                {
                    return(session.FindByExchangeGuidIncludingArchive(exchangeGuid));
                }
                return(session.Read(userId));
            });

            if (adrecipient == null)
            {
                MrsTracer.Common.Warning("No ADRecipient found with Identity '{0}' in organizaton '{1}'.", new object[]
                {
                    userId.ToString(),
                    this.orgId.ToString()
                });
                return(null);
            }
            ADUser aduser = adrecipient as ADUser;

            if (aduser == null)
            {
                MrsTracer.Common.Warning("'{0}' is not a user.", new object[]
                {
                    userId.ToString()
                });
                return(null);
            }
            return(aduser);
        }