internal override ADSessionSettings FromExternalDirectoryOrganizationId(Guid externalDirectoryOrganizationId) { ADObjectId adobjectId = new ADObjectId(DalHelper.GetTenantDistinguishedName(externalDirectoryOrganizationId.ToString()), externalDirectoryOrganizationId); ADPropertyBag adpropertyBag = new ADPropertyBag(); adpropertyBag[ADObjectSchema.ConfigurationUnit] = adobjectId; adpropertyBag[ADObjectSchema.OrganizationalUnitRoot] = adobjectId; OrganizationId organizationId = (OrganizationId)ADObject.OrganizationIdGetter(adpropertyBag); return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(ScopeSet.GetOrgWideDefaultScopeSet(organizationId), adobjectId, organizationId, null, ConfigScopes.TenantLocal, PartitionId.LocalForest)); }
internal override ADSessionSettings FromTenantCUName(string name) { if (name == null) { throw new ArgumentNullException("name"); } GlobalConfigSession globalConfigSession = new GlobalConfigSession(); FfoTenant tenantByName = globalConfigSession.GetTenantByName(name); if (tenantByName == null) { throw new CannotResolveTenantNameException(DirectoryStrings.CannotResolveTenantName(name)); } ExchangeConfigurationUnit exchangeConfigurationUnit = FfoConfigurationSession.GetExchangeConfigurationUnit(tenantByName); return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(ScopeSet.GetOrgWideDefaultScopeSet(OrganizationId.ForestWideOrgId), null, exchangeConfigurationUnit.OrganizationId, null, ConfigScopes.TenantLocal, PartitionId.LocalForest)); }
private void SetScopeSet(object sender, EventArgs e) { if (this.CurrentTaskContext.CanBypassRBACScope) { if (this.CurrentTaskContext.UserInfo != null) { if (this.CurrentTaskContext.UserInfo.CurrentOrganizationId != null) { this.CurrentTaskContext.ScopeSet = ScopeSet.GetOrgWideDefaultScopeSet(this.CurrentTaskContext.UserInfo.CurrentOrganizationId); } else { this.CurrentTaskContext.ScopeSet = ScopeSet.GetOrgWideDefaultScopeSet(this.CurrentTaskContext.UserInfo.ExecutingUserOrganizationId); } } if (this.CurrentTaskContext.InvocationInfo != null && this.CurrentTaskContext.InvocationInfo.IsVerboseOn && !TaskLogger.IsSetupLogging) { this.CurrentTaskContext.CommandShell.WriteVerbose(TaskVerboseStringHelper.GetScopeSetVerboseString(this.CurrentTaskContext.ScopeSet)); } } }
protected override IConfigurable PrepareDataObject() { MailboxDiscoverySearch mailboxDiscoverySearch = (MailboxDiscoverySearch)base.PrepareDataObject(); string[] paramNames = new string[] { "AllSourceMailboxes", "AllPublicFolderSources", "PublicFolderSources" }; ScopeSet scopeSet = base.ScopeSet; bool flag = false; if (scopeSet == null) { scopeSet = ScopeSet.GetOrgWideDefaultScopeSet(base.CurrentOrganizationId); } if (scopeSet != null) { ADRawEntry executingUser = base.ExchangeRunspaceConfig.ExecutingUser; if (executingUser != null) { flag = base.ExchangeRunspaceConfig.IsCmdletAllowedInScope("Set-MailboxSearch", paramNames, executingUser, ScopeLocation.RecipientWrite); } else { flag = base.ExchangeRunspaceConfig.IsCmdletAllowedInScope("Set-MailboxSearch", paramNames, scopeSet); } } if (flag && mailboxDiscoverySearch.Version == SearchObjectVersion.Original && (mailboxDiscoverySearch.Sources == null || mailboxDiscoverySearch.Sources.Count == 0) && (mailboxDiscoverySearch.PublicFolderSources == null || mailboxDiscoverySearch.PublicFolderSources.Count == 0) && !mailboxDiscoverySearch.AllSourceMailboxes && !mailboxDiscoverySearch.AllPublicFolderSources) { this.AllSourceMailboxes = true; } if (flag) { mailboxDiscoverySearch.Version = SearchObjectVersion.SecondVersion; } if (base.Fields.IsModified(SearchObjectSchema.TargetMailbox.Name)) { if (this.TargetMailbox != null) { try { this.recipientSession.SessionSettings.IncludeInactiveMailbox = false; ADUser aduser = (ADUser)base.GetDataObject <ADUser>(this.TargetMailbox, this.recipientSession, null, new LocalizedString?(Strings.ExceptionUserObjectNotFound(this.TargetMailbox.ToString())), new LocalizedString?(Strings.ExceptionUserObjectAmbiguous)); if (aduser.RecipientType != RecipientType.UserMailbox) { base.ThrowTerminatingError(new MailboxSearchTaskException(Strings.ErrorInvalidRecipientType(aduser.ToString(), aduser.RecipientType.ToString())), ErrorCategory.InvalidArgument, SearchObjectSchema.TargetMailbox.Name); } mailboxDiscoverySearch.Target = aduser.LegacyExchangeDN; if (base.ScopeSet != null) { Utils.VerifyIsInScopes(aduser, base.ScopeSet, new Task.TaskErrorLoggingDelegate(base.WriteError)); } Utils.VerifyMailboxVersion(aduser, new Task.TaskErrorLoggingDelegate(base.WriteError)); goto IL_20B; } finally { if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled) { this.recipientSession.SessionSettings.IncludeInactiveMailbox = true; } } } mailboxDiscoverySearch.Target = null; } IL_20B: if (flag) { if (base.Fields.IsModified(MailboxDiscoverySearchSchema.AllSourceMailboxes.Name)) { mailboxDiscoverySearch.AllSourceMailboxes = this.AllSourceMailboxes; } if (this.AllSourceMailboxes) { if (this.SourceMailboxes != null || mailboxDiscoverySearch.Sources != null) { this.WriteWarning(Strings.AllSourceMailboxesParameterOverride("AllSourceMailboxes", "SourceMailboxes")); } this.SourceMailboxes = null; mailboxDiscoverySearch.Sources = null; } } bool flag2 = base.Fields.IsModified(SearchObjectSchema.SourceMailboxes.Name); if (!flag2) { if (!mailboxDiscoverySearch.IsChanged(MailboxDiscoverySearchSchema.InPlaceHoldEnabled) || !mailboxDiscoverySearch.InPlaceHoldEnabled) { goto IL_442; } } try { if (mailboxDiscoverySearch.InPlaceHoldEnabled) { this.recipientSession.SessionSettings.IncludeSoftDeletedObjects = true; } IEnumerable <RecipientIdParameter> enumerable; if (!flag2) { if (mailboxDiscoverySearch.Sources != null) { enumerable = from legacyDn in mailboxDiscoverySearch.Sources select new RecipientIdParameter(legacyDn); } else { enumerable = null; } } else { enumerable = this.SourceMailboxes; } IEnumerable <RecipientIdParameter> recipientIds = enumerable; MultiValuedProperty <string> multiValuedProperty = Utils.ConvertSourceMailboxesCollection(recipientIds, mailboxDiscoverySearch.InPlaceHoldEnabled, (RecipientIdParameter recipientId) => base.GetDataObject <ADRecipient>(recipientId, this.recipientSession, null, new LocalizedString?(Strings.ExceptionUserObjectNotFound(recipientId.ToString())), new LocalizedString?(Strings.ExceptionUserObjectAmbiguous)) as ADRecipient, this.recipientSession, new Task.TaskErrorLoggingDelegate(base.WriteError), new Action <LocalizedString>(this.WriteWarning), (LocalizedString locString) => this.Force || base.ShouldContinue(locString)) ?? new MultiValuedProperty <string>(); mailboxDiscoverySearch.Sources.CopyChangesFrom(multiValuedProperty); if (mailboxDiscoverySearch.Sources.Count != multiValuedProperty.Count) { mailboxDiscoverySearch.Sources = multiValuedProperty; } if (base.ScopeSet != null) { foreach (string legacyExchangeDN in mailboxDiscoverySearch.Sources) { ADRecipient adrecipient = this.recipientSession.FindByLegacyExchangeDN(legacyExchangeDN); if (adrecipient == null) { base.WriteError(new ObjectNotFoundException(Strings.ExceptionSourceMailboxNotFound(mailboxDiscoverySearch.Target, mailboxDiscoverySearch.Name)), ErrorCategory.InvalidOperation, null); } Utils.VerifyIsInHoldScopes(mailboxDiscoverySearch.InPlaceHoldEnabled, base.ExchangeRunspaceConfig, adrecipient, "Set-MailboxSearch", new Task.TaskErrorLoggingDelegate(base.WriteError)); Utils.VerifyIsInScopes(adrecipient, base.ScopeSet, new Task.TaskErrorLoggingDelegate(base.WriteError)); } } } finally { this.recipientSession.SessionSettings.IncludeSoftDeletedObjects = false; } IL_442: if (flag) { if (base.Fields.IsModified(MailboxDiscoverySearchSchema.AllPublicFolderSources.Name)) { mailboxDiscoverySearch.AllPublicFolderSources = this.AllPublicFolderSources; } if (this.AllPublicFolderSources) { if (this.PublicFolderSources != null) { this.WriteWarning(Strings.AllSourceMailboxesParameterOverride("AllPublicFolderSources", "PublicFolderSources")); } this.PublicFolderSources = null; } if (base.Fields.IsModified(MailboxDiscoverySearchSchema.PublicFolderSources.Name)) { string[] array = null; if (this.PublicFolderSources != null && this.PublicFolderSources.Length != 0) { array = new string[this.PublicFolderSources.Length]; string action = "Get-PublicFolder"; try { using (PublicFolderDataProvider publicFolderDataProvider = new PublicFolderDataProvider(this.ConfigurationSession, action, Guid.Empty)) { for (int i = 0; i < this.PublicFolderSources.Length; i++) { PublicFolder publicFolder = null; array[i] = this.PublicFolderSources[i].ToString(); try { publicFolder = (PublicFolder)publicFolderDataProvider.Read <PublicFolder>(this.PublicFolderSources[i].PublicFolderId); } catch (FormatException exception) { base.WriteError(exception, ErrorCategory.WriteError, null); } if (publicFolder == null) { base.WriteError(new MailboxSearchTaskException(Strings.PublicFolderSourcesFolderDoesnotExist(array[i])), ErrorCategory.InvalidArgument, null); } } } } catch (AccessDeniedException exception2) { base.WriteError(exception2, ErrorCategory.PermissionDenied, mailboxDiscoverySearch.Name); } } mailboxDiscoverySearch.PublicFolderSources = Utils.ConvertCollectionToMultiValedProperty <string, string>(array, (string value, object param) => value, null, new MultiValuedProperty <string>(), new Task.TaskErrorLoggingDelegate(base.WriteError), MailboxDiscoverySearchSchema.PublicFolderSources.Name); } } if (base.Fields.IsModified(SearchObjectSchema.Senders.Name)) { MultiValuedProperty <string> senders = Utils.ConvertCollectionToMultiValedProperty <string, string>(this.Senders, (string value, object param) => value, null, new MultiValuedProperty <string>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.Senders.Name); mailboxDiscoverySearch.Senders = senders; } if (base.Fields.IsModified(SearchObjectSchema.Recipients.Name)) { MultiValuedProperty <string> recipients = Utils.ConvertCollectionToMultiValedProperty <string, string>(this.Recipients, (string value, object param) => value, null, new MultiValuedProperty <string>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.Recipients.Name); mailboxDiscoverySearch.Recipients = recipients; } if (base.Fields.IsModified(SearchObjectSchema.StartDate.Name)) { mailboxDiscoverySearch.StartDate = this.StartDate; } if (base.Fields.IsModified(SearchObjectSchema.EndDate.Name)) { mailboxDiscoverySearch.EndDate = this.EndDate; } if (base.Fields.IsModified(SearchObjectSchema.MessageTypes.Name)) { MultiValuedProperty <KindKeyword> messageTypes = Utils.ConvertCollectionToMultiValedProperty <KindKeyword, KindKeyword>(this.MessageTypes, (KindKeyword kind, object param) => kind, null, new MultiValuedProperty <KindKeyword>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.MessageTypes.Name); mailboxDiscoverySearch.MessageTypes = messageTypes; } if (base.Fields.IsModified(SearchObjectSchema.StatusMailRecipients.Name)) { MultiValuedProperty <ADObjectId> multiValuedProperty2 = Utils.ConvertCollectionToMultiValedProperty <RecipientIdParameter, ADObjectId>(this.StatusMailRecipients, new Utils.IdentityToRawIdDelegate <RecipientIdParameter, ADObjectId>(this.ADObjectIdFromRecipientIdParameter), null, new MultiValuedProperty <ADObjectId>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.StatusMailRecipients.Name); mailboxDiscoverySearch.StatusMailRecipients.CopyChangesFrom(multiValuedProperty2); if (mailboxDiscoverySearch.StatusMailRecipients.Count != multiValuedProperty2.Count) { mailboxDiscoverySearch.StatusMailRecipients = multiValuedProperty2; } } if (base.Fields.IsModified(SearchObjectSchema.ManagedBy.Name)) { MultiValuedProperty <ADObjectId> multiValuedProperty3 = Utils.ConvertCollectionToMultiValedProperty <RecipientIdParameter, ADObjectId>(this.ManagedBy, new Utils.IdentityToRawIdDelegate <RecipientIdParameter, ADObjectId>(this.ADObjectIdFromRecipientIdParameter), null, new MultiValuedProperty <ADObjectId>(), new Task.TaskErrorLoggingDelegate(base.WriteError), SearchObjectSchema.ManagedBy.Name); mailboxDiscoverySearch.ManagedBy.CopyChangesFrom(multiValuedProperty3); if (mailboxDiscoverySearch.ManagedBy.Count != multiValuedProperty3.Count) { mailboxDiscoverySearch.ManagedBy = multiValuedProperty3; } } if (base.Fields.IsModified("SearchQuery")) { mailboxDiscoverySearch.Query = this.SearchQuery; } if (base.Fields.IsModified(SearchObjectSchema.EstimateOnly.Name)) { mailboxDiscoverySearch.StatisticsOnly = this.EstimateOnly; if (this.EstimateOnly) { mailboxDiscoverySearch.LogLevel = LoggingLevel.Suppress; } else { mailboxDiscoverySearch.IncludeKeywordStatistics = false; } } if (base.Fields.IsModified(SearchObjectSchema.IncludeKeywordStatistics.Name)) { mailboxDiscoverySearch.IncludeKeywordStatistics = this.IncludeKeywordStatistics.ToBool(); } if (base.Fields.IsModified(MailboxDiscoverySearchSchema.StatisticsStartIndex.Name)) { mailboxDiscoverySearch.StatisticsStartIndex = this.StatisticsStartIndex; } if (flag && (mailboxDiscoverySearch.Sources == null || mailboxDiscoverySearch.Sources.Count == 0) && (mailboxDiscoverySearch.PublicFolderSources == null || mailboxDiscoverySearch.PublicFolderSources.Count == 0) && !mailboxDiscoverySearch.AllSourceMailboxes && !mailboxDiscoverySearch.AllPublicFolderSources) { base.WriteError(new MailboxSearchTaskException(Strings.NoSourceMailboxesAndNoPublicFolderSourcesSet), ErrorCategory.InvalidArgument, null); } bool flag3 = mailboxDiscoverySearch.InPlaceHoldEnabled && (mailboxDiscoverySearch.Sources == null || mailboxDiscoverySearch.Sources.Count == 0); bool flag4 = false; if (flag) { flag3 = (mailboxDiscoverySearch.InPlaceHoldEnabled && mailboxDiscoverySearch.AllSourceMailboxes); flag4 = (mailboxDiscoverySearch.InPlaceHoldEnabled && (mailboxDiscoverySearch.AllPublicFolderSources || (mailboxDiscoverySearch.PublicFolderSources != null && mailboxDiscoverySearch.PublicFolderSources.Count != 0))); } if (flag3) { base.WriteError(new MailboxSearchTaskException(Strings.InPlaceHoldNotAllowedForAllSourceMailboxes), ErrorCategory.InvalidArgument, null); } if (flag4) { base.WriteError(new MailboxSearchTaskException(Strings.InPlaceHoldNotAllowedForPublicFolders), ErrorCategory.InvalidArgument, null); } return(mailboxDiscoverySearch); }
internal static IConfigDataProvider CreateConfigSession(OrganizationId currentOrganizationId, OrganizationId executingUserOrganizationId) { ADSessionSettings sessionSettings = ADSessionSettings.FromCustomScopeSet(ScopeSet.GetOrgWideDefaultScopeSet(currentOrganizationId), ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), currentOrganizationId, executingUserOrganizationId, true); return(DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(null, false, ConsistencyMode.PartiallyConsistent, sessionSettings, 102, "CreateConfigSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\FfoReporting\\Common\\ADHelper.cs")); }
internal override ADSessionSettings FromAllTenantsPartitionId(PartitionId partitionId) { return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(ScopeSet.GetOrgWideDefaultScopeSet(OrganizationId.ForestWideOrgId), null, OrganizationId.ForestWideOrgId, null, ConfigScopes.AllTenants, PartitionId.LocalForest)); }
internal override ADSessionSettings FromAllTenantsOrRootOrgAutoDetect(OrganizationId orgId) { if (!OrganizationId.ForestWideOrgId.Equals(orgId)) { return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(ScopeSet.GetOrgWideDefaultScopeSet(OrganizationId.ForestWideOrgId), null, orgId, null, ConfigScopes.AllTenants, PartitionId.LocalForest)); } return(ADSessionSettings.FromRootOrgScopeSet()); }