protected override IConfigDataProvider CreateSession() { if (this.AccountPartition == null && this.Identity == null) { base.WriteError(new NotSupportedException(Strings.ErrorUnknownPartition), ErrorCategory.InvalidData, null); } PartitionId partitionId; if (this.Identity != null) { if (this.Identity.RawIdentity.Contains("*")) { base.WriteError(new ArgumentException(Strings.ErrorWildcardNotSupportedInRelocationIdentity(this.Identity.RawIdentity)), ErrorCategory.InvalidOperation, this.Identity); } OrganizationId organizationId = this.Identity.ResolveOrganizationId(); partitionId = organizationId.PartitionId; } else { partitionId = RecipientTaskHelper.ResolvePartitionId(this.AccountPartition, new Task.TaskErrorLoggingDelegate(base.WriteError)); } this.sourceForestRIDMaster = ForestTenantRelocationsCache.GetRidMasterName(partitionId); ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(base.DomainController, true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 223, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Relocation\\GetTenantRelocationRequest.cs"); if (base.DomainController != null && !this.sourceForestRIDMaster.StartsWith(base.DomainController, StringComparison.OrdinalIgnoreCase)) { ForestTenantRelocationsCache.Reset(); } tenantConfigurationSession.SessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; return(tenantConfigurationSession); }
private static ITenantConfigurationSession CreateWritableTenantSession(OrganizationId organizationId) { string ridMasterName = ForestTenantRelocationsCache.GetRidMasterName(organizationId.PartitionId); ADSessionSettings adsessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(organizationId, false); adsessionSettings.RetiredTenantModificationAllowed = true; adsessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; return(DirectorySessionFactory.Default.CreateTenantConfigurationSession(ridMasterName, false, ConsistencyMode.PartiallyConsistent, adsessionSettings, 541, "CreateWritableTenantSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Relocation\\SetTenantRelocationRequest.cs")); }
internal static void PopulateCache(string partitionFqdn, Organization rootOrganization) { ArgumentValidator.ThrowIfNullOrEmpty("partitionFqdn", partitionFqdn); ArgumentValidator.ThrowIfNull("organization", rootOrganization); if (InternalDirectoryRootOrganizationCache.InternalGetTenantCULocation(partitionFqdn) == TenantCULocation.Undefined) { TenantCULocation value; if (Globals.IsDatacenter) { value = ((rootOrganization.ForestMode == ForestModeFlags.Legacy) ? TenantCULocation.ConfigNC : TenantCULocation.DomainNC); } else { value = TenantCULocation.ConfigNC; } InternalDirectoryRootOrganizationCache.tenantCULocations.TryAdd(partitionFqdn, value); } InternalDirectoryRootOrganizationCache.rootOrgContainerIds.TryAdd(partitionFqdn, new ADObjectIdCachableItem(rootOrganization.Id)); ForestTenantRelocationsCache.UpdateTenantRelocationAllowedValue(rootOrganization); }
internal void RebindDataSessionToDataObjectPartitionRidMasterIncludeRetiredTenants(PartitionId partitionId) { string ridMasterName = ForestTenantRelocationsCache.GetRidMasterName(partitionId); if (this.DomainController != null) { string value = this.DomainController.ToString().Split(new char[] { '.' })[0] + "."; if (!ridMasterName.StartsWith(value, StringComparison.OrdinalIgnoreCase)) { ForestTenantRelocationsCache.Reset(); base.WriteError(new InvalidOperationException(Strings.ErrorMustWriteToRidMaster(ridMasterName)), ErrorCategory.InvalidOperation, ridMasterName); } } ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId); adsessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; adsessionSettings.RetiredTenantModificationAllowed = true; this.dataSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ridMasterName, false, ConsistencyMode.PartiallyConsistent, adsessionSettings, 1125, "RebindDataSessionToDataObjectPartitionRidMasterIncludeRetiredTenants", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\BaseTasks\\DataAccessTask.cs"); }
protected override void WriteResult(IConfigurable dataObject) { TaskLogger.LogEnter(new object[] { dataObject.Identity }); TenantRelocationRequest tenantRelocationRequest = (TenantRelocationRequest)dataObject; if (!this.SourceStateOnly) { if (tenantRelocationRequest.TargetForest != null) { this.targetForestRIDMaster = ForestTenantRelocationsCache.GetRidMasterName(new PartitionId(tenantRelocationRequest.TargetForest)); } Exception ex; TenantRelocationRequest.PopulatePresentationObject(tenantRelocationRequest, this.targetForestRIDMaster, out ex); if (ex != null) { if (ex is CannotFindTargetTenantException) { base.WriteWarning(ex.Message); } else { base.WriteError(ex, ErrorCategory.InvalidOperation, tenantRelocationRequest.Identity); } } GetTenantRelocationRequest.PopulateGlsProperty(tenantRelocationRequest, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); GetTenantRelocationRequest.PopulateRidMasterProperties(tenantRelocationRequest, this.sourceForestRIDMaster, this.targetForestRIDMaster, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); if (tenantRelocationRequest.OriginatingServer != this.sourceForestRIDMaster) { this.warning = Strings.WarningShouldReadFromRidMaster(tenantRelocationRequest.OriginatingServer, this.sourceForestRIDMaster); } } base.WriteResult(tenantRelocationRequest); TaskLogger.LogExit(); }
protected override void InternalValidate() { base.InternalValidate(); if (this.DataObject.IsChanged(OrganizationSchema.CustomerFeedbackEnabled) && this.DataObject.CustomerFeedbackEnabled == null) { base.WriteError(new InvalidOperationException(Strings.CustomerFeedbackEnabledError), ErrorCategory.InvalidOperation, null); } if (this.DataObject.IsChanged(OrganizationSchema.OrganizationSummary)) { MultiValuedProperty <OrganizationSummaryEntry> organizationSummary = this.DataObject.OrganizationSummary; this.MergeAdded(organizationSummary); this.MergeRemoved(organizationSummary); if (this.mergedCollection.Changed) { this.UpdateUploadDate(); } this.DataObject.OrganizationSummary = this.mergedCollection; } Organization organization = (Organization)this.GetDynamicParameters(); if (organization.EwsAllowListSpecified && organization.EwsBlockListSpecified) { base.ThrowTerminatingError(new ArgumentException(Strings.ErrorEwsAllowListAndEwsBlockListSpecified), ErrorCategory.InvalidArgument, null); } if (organization.IsModified(OrganizationSchema.EwsApplicationAccessPolicy)) { if (organization.EwsApplicationAccessPolicy == EwsApplicationAccessPolicy.EnforceAllowList && organization.EwsBlockListSpecified) { base.ThrowTerminatingError(new ArgumentException(Strings.ErrorEwsEnforceAllowListAndEwsBlockListSpecified), ErrorCategory.InvalidArgument, null); } if (organization.EwsApplicationAccessPolicy == EwsApplicationAccessPolicy.EnforceBlockList && organization.EwsAllowListSpecified) { base.ThrowTerminatingError(new ArgumentException(Strings.ErrorEwsEnforceBlockListAndEwsAllowListSpecified), ErrorCategory.InvalidArgument, null); } } if (organization.IsModified(OrganizationSchema.DefaultPublicFolderMailbox)) { Organization orgContainer = ((IConfigurationSession)base.DataSession).GetOrgContainer(); PublicFolderInformation defaultPublicFolderMailbox = orgContainer.DefaultPublicFolderMailbox; if (!defaultPublicFolderMailbox.CanUpdate) { base.WriteError(new RecipientTaskException(Strings.ErrorCannotUpdatePublicFolderHierarchyInformation), ExchangeErrorCategory.Client, null); } if (defaultPublicFolderMailbox.HierarchyMailboxGuid != Guid.Empty) { base.WriteError(new RecipientTaskException(Strings.ErrorPublicFolderHierarchyAlreadyProvisioned), ExchangeErrorCategory.Client, null); } } if (this.DataObject.IsChanged(OrganizationSchema.TenantRelocationsAllowed) && !this.DataObject.TenantRelocationsAllowed) { string ridMasterName = ForestTenantRelocationsCache.GetRidMasterName(this.DataObject.OrganizationId.PartitionId); ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ridMasterName, true, ConsistencyMode.PartiallyConsistent, null, ADSessionSettings.FromAllTenantsPartitionId(this.DataObject.OrganizationId.PartitionId ?? PartitionId.LocalForest), 564, "InternalValidate", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\organization\\SetOrganization.cs"); TenantRelocationRequest[] array = tenantConfigurationSession.Find <TenantRelocationRequest>(null, QueryScope.SubTree, new OrFilter(new QueryFilter[] { TenantRelocationRequest.TenantRelocationRequestFilter, TenantRelocationRequest.TenantRelocationLandingFilter }), null, 1); if (array.Length > 0) { base.WriteError(new InvalidOperationException(Strings.ErrorTenantRelocationInProgress(array[0].Name)), ErrorCategory.InvalidOperation, null); } } }
protected override void InternalProcessRecord() { string forestFQDN = this.DataObject.OrganizationId.PartitionId.ForestFQDN; if (this.applyTransitionFromCmdlet) { LocalizedString?localizedString = null; if (!this.DataObject.AutoCompletionEnabled && this.DataObject.RelocationStatusDetailsSource != (RelocationStatusDetailsSource)this.DataObject.RelocationStateRequested) { localizedString = new LocalizedString?(Strings.WarningApplyingTransitionWhileRelocationStatusNotReachedStateRequested(this.Identity.ToString(), this.DataObject.RelocationStateRequested.ToString(), this.DataObject.RelocationStatusDetailsSource.ToString())); } else if (this.DataObject.AutoCompletionEnabled && this.DataObject.RelocationStatusDetailsSource != RelocationStatusDetailsSource.RetiredUpdatedTargetForest) { localizedString = new LocalizedString?(Strings.WarningApplyingTransitionWhileRelocationStatusNotReachedStateRequested(this.Identity.ToString(), this.DataObject.RelocationStateRequested.ToString(), this.DataObject.RelocationStatusDetailsSource.ToString())); } if (localizedString != null && !base.ShouldContinue(localizedString.Value)) { return; } if (this.RollbackGls && this.DataObject.RelocationStatusDetailsSource == RelocationStatusDetailsSource.RetiredUpdatedTargetForest) { localizedString = new LocalizedString?(Strings.WarningPossibleDataLossWithGlsRollback(this.Identity.ToString(), this.DataObject.TargetForest, forestFQDN)); if (!base.ShouldContinue(localizedString.Value)) { return; } } } if (this.Suspend && this.DataObject.RelocationStatusDetailsSource > RelocationStatusDetailsSource.SynchronizationStartedDeltaSync) { LocalizedString?localizedString2 = new LocalizedString?(Strings.WarningSuspendSupportedOnlyDuringSync(this.DataObject.RelocationStatusDetailsSource.ToString(), RelocationStatusDetailsSource.SynchronizationStartedFullSync.ToString(), RelocationStatusDetailsSource.SynchronizationStartedDeltaSync.ToString())); if (!base.ShouldContinue(localizedString2.Value)) { return; } } this.DataObject.RelocationLastError = RelocationError.None; if (base.Fields.IsChanged(TenantRelocationRequestSchema.RelocationStateRequested)) { this.DataObject.RelocationStateRequested = (RelocationStateRequested)this.RelocationStateRequested; } if (base.Fields.IsChanged(TenantRelocationRequestSchema.LargeTenantModeEnabled)) { this.DataObject.LargeTenantModeEnabled = this.LargeTenantModeEnabled; } if (base.Fields.IsChanged(TenantRelocationRequestSchema.AutoCompletionEnabled)) { this.DataObject.AutoCompletionEnabled = this.AutoCompletionEnabled; if (this.AutoCompletionEnabled) { this.DataObject.RelocationStateRequested = Microsoft.Exchange.Data.Directory.SystemConfiguration.RelocationStateRequested.None; } } if (base.Fields.IsChanged(TenantRelocationRequestSchema.SafeLockdownSchedule)) { this.DataObject.SafeLockdownSchedule = this.SafeLockdownSchedule; } if (this.Suspend) { this.DataObject.Suspended = true; } else if (this.Resume) { this.DataObject.Suspended = false; } if (this.applyTransitionFromCmdlet) { Exception ex; TenantRelocationRequest.PopulatePresentationObject(this.DataObject, null, out ex); if (ex != null) { throw ex; } RelocationStatusDetails relocationStatusDetailsRaw = this.DataObject.RelocationStatusDetailsRaw; this.DataObject.RelocationStatusDetailsRaw = RelocationStatusDetails.SynchronizationFinishedFullSync; this.DataObject.AutoCompletionEnabled = false; if (this.RollbackGls) { this.RevertGlsAccountForestToSource(forestFQDN); this.RevertTargetTenantStateToArriving(); this.DataObject.IncrementTransitionCounter(TenantRelocationTransition.RetiredToSync); this.DataObject.OrganizationStatus = OrganizationStatus.Active; TenantRelocationRequest.SetRelocationCompletedOnOU((ITenantConfigurationSession)base.DataSession, this.DataObject.OrganizationId); } else { TenantRelocationTransition transition; if (relocationStatusDetailsRaw == RelocationStatusDetails.SynchronizationFinishedDeltaSync) { transition = TenantRelocationTransition.DeltaSyncToSync; } else { transition = TenantRelocationTransition.LockdownToSync; } this.DataObject.IncrementTransitionCounter(transition); } } if (this.ResetTransitionCounter) { this.DataObject.TransitionCounter = new MultiValuedProperty <TransitionCount>(); } if (this.ResetPermanentError) { this.DataObject.RelocationLastError = RelocationError.None; } if (this.ResetStartSyncTime) { this.DataObject.LastSuccessfulRelocationSyncStart = new DateTime?(DateTime.UtcNow); } ((IDirectorySession)base.DataSession).SessionSettings.RetiredTenantModificationAllowed = true; base.InternalProcessRecord(); string ridMasterName = ForestTenantRelocationsCache.GetRidMasterName(new PartitionId(forestFQDN)); if (this.DataObject.OriginatingServer != ridMasterName) { this.WriteWarning(Strings.WarningShouldWriteToRidMaster(this.DataObject.OriginatingServer, ridMasterName)); } }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); this.DataObject.AutoCompletionEnabled = this.AutoCompletionEnabled; this.DataObject.LargeTenantModeEnabled = this.LargeTenantModeEnabled; this.DataObject.SafeLockdownSchedule = (this.SafeLockdownSchedule ?? Schedule.Always); if (base.Fields.IsModified(TenantRelocationRequestSchema.RelocationStateRequested)) { this.DataObject.RelocationStateRequested = (RelocationStateRequested)this.RelocationStateRequested; } this.DataObject.TargetForest = this.targetAccountPartitionFqdn; this.sourceForestRIDMaster = ForestTenantRelocationsCache.GetRidMasterName(this.sourceAccountPartitionId); DirectorySessionFactory @default = DirectorySessionFactory.Default; Fqdn domainController = base.DomainController; ITenantConfigurationSession tenantConfigurationSession = @default.CreateTenantConfigurationSession((domainController != null) ? domainController : this.sourceForestRIDMaster, false, ConsistencyMode.PartiallyConsistent, null, ADSessionSettings.FromAllTenantsPartitionId(this.sourceAccountPartitionId), 334, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Relocation\\NewTenantRelocationRequest.cs"); PartitionId partitionId = new PartitionId(this.targetAccountPartitionFqdn); this.targetForestRIDMaster = ForestTenantRelocationsCache.GetRidMasterName(partitionId); ITenantConfigurationSession tenantConfigurationSession2 = DirectorySessionFactory.Default.CreateTenantConfigurationSession(this.targetForestRIDMaster, false, ConsistencyMode.PartiallyConsistent, null, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 343, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Relocation\\NewTenantRelocationRequest.cs"); tenantConfigurationSession2.SessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; MsoTenantCookieContainer msoTenantCookieContainer = tenantConfigurationSession2.GetMsoTenantCookieContainer(this.externalDirectoryOrganizationId); if (msoTenantCookieContainer != null && !NewTenantRelocationRequest.IntraForestRelocationEnabled()) { InvalidOperationException exception = new InvalidOperationException(Strings.ErrorTargetPartitionHasTenantWithSameId(this.DataObject.DistinguishedName, this.targetAccountPartitionFqdn, msoTenantCookieContainer.DistinguishedName, this.DataObject.ExternalDirectoryOrganizationId)); base.WriteError(exception, ErrorCategory.InvalidOperation, this.DataObject.Identity); } string text = this.GetInitialDomainName(tenantConfigurationSession, this.DataObject.OrganizationId); ExchangeConfigurationUnit exchangeConfigurationUnitByName = tenantConfigurationSession2.GetExchangeConfigurationUnitByName(text); if (exchangeConfigurationUnitByName != null) { if (text.Length > 50) { text = text.Substring(0, 50); } text = string.Format("{0}-RELO-{1}", text, Guid.NewGuid().ToString()); if (text.Length > 64) { text = text.Substring(0, 64); } } Exception ex; OrganizationId targetSharedOrgId = SharedConfiguration.FindMostRecentSharedConfigurationInPartition(this.DataObject.OrganizationId, partitionId, out ex); if (ex != null) { base.WriteError(ex, ErrorCategory.InvalidOperation, this.DataObject.Identity); } ADOrganizationalUnit adorganizationalUnit = null; bool useConfigNC = tenantConfigurationSession.UseConfigNC; try { tenantConfigurationSession.UseConfigNC = false; adorganizationalUnit = tenantConfigurationSession.Read <ADOrganizationalUnit>(this.DataObject.OrganizationId.OrganizationalUnit); } finally { tenantConfigurationSession.UseConfigNC = useConfigNC; } this.DataObject.RelocationStatusDetailsRaw = RelocationStatusDetails.InitializationStarted; base.InternalProcessRecord(); ADObjectId enclosureContainerId = this.CreateEnclosureConfigContainer(text, tenantConfigurationSession2); ExchangeConfigurationUnit exchangeConfigurationUnit = this.CreateOrgConfigurationContainer(enclosureContainerId, targetSharedOrgId, this.DataObject.ExternalDirectoryOrganizationId, this.DataObject.ProgramId, this.DataObject.OfferId, this.DataObject.IsDehydrated, this.DataObject.IsStaticConfigurationShared, this.sourceForestFqdn, this.DataObject.Guid, this.DataObject.ExchangeObjectId, tenantConfigurationSession2); ADObjectId organizationalUnitLink = this.CreateOrganizationUnitContainer(text, adorganizationalUnit.Guid, adorganizationalUnit.ExchangeObjectId, tenantConfigurationSession2); exchangeConfigurationUnit.OrganizationalUnitLink = organizationalUnitLink; exchangeConfigurationUnit.RelocationStatusDetailsRaw = RelocationStatusDetails.InitializationFinished; tenantConfigurationSession2.Save(exchangeConfigurationUnit); this.DataObject.RelocationStatusDetailsRaw = RelocationStatusDetails.InitializationFinished; base.DataSession.Save(this.DataObject); TenantRelocationRequest tenantRelocationRequest = (TenantRelocationRequest)base.DataSession.Read <TenantRelocationRequest>(this.DataObject.Identity); TenantRelocationRequest targetForestObject = tenantConfigurationSession2.Read <TenantRelocationRequest>(exchangeConfigurationUnit.Id); TenantRelocationRequest.PopulatePresentationObject(tenantRelocationRequest, targetForestObject); GetTenantRelocationRequest.PopulateGlsProperty(tenantRelocationRequest, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); GetTenantRelocationRequest.PopulateRidMasterProperties(tenantRelocationRequest, this.sourceForestRIDMaster, this.targetForestRIDMaster, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); if (tenantRelocationRequest.OriginatingServer != this.sourceForestRIDMaster) { this.WriteWarning(Strings.WarningShouldWriteToRidMaster(tenantRelocationRequest.OriginatingServer, this.sourceForestRIDMaster)); } base.WriteObject(tenantRelocationRequest); TaskLogger.LogExit(); }