protected override void PrepareRecipientObject(ADGroup group) { TaskLogger.LogEnter(); base.PrepareRecipientObject(group); group.GroupType = (GroupTypeFlags)((GroupType)8 | this.Type); if (!group.IsModified(ADRecipientSchema.DisplayName)) { group.DisplayName = group.Name; } if (!group.IsModified(ADMailboxRecipientSchema.SamAccountName)) { group.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(base.PartitionOrRootOrgGlobalCatalogSession, group.Id.DomainId, group.Name, false, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), true); } TaskLogger.LogExit(); }
protected override void PrepareRecipientObject(ADUser user) { TaskLogger.LogEnter(); base.PrepareRecipientObject(user); if (user.IsModified(ADRecipientSchema.WindowsLiveID) && user.WindowsLiveID != SmtpAddress.Empty) { user.UserPrincipalName = user.WindowsLiveID.ToString(); } if (!user.IsModified(ADRecipientSchema.DisplayName)) { user.DisplayName = user.Name; } if (!user.IsModified(IADSecurityPrincipalSchema.SamAccountName)) { user.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(base.PartitionOrRootOrgGlobalCatalogSession, user.Id.DomainId, user.Name, false, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), true); } TaskLogger.LogExit(); }
protected override void PrepareRecipientObject(ADUser user) { TaskLogger.LogEnter(); string userPrincipalName = user.UserPrincipalName; base.PrepareRecipientObject(user); bool flag = base.Fields.Contains("SoftDeletedObject"); if (flag && userPrincipalName != user.UserPrincipalName) { user.UserPrincipalName = userPrincipalName; } using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "NewUserBase.PrepareUserObject", LoggerHelper.CmdletPerfMonitors)) { this.PrepareUserObject(user); } if (!string.IsNullOrEmpty(this.ImmutableId)) { this.DataObject.ImmutableId = this.ImmutableId; } if (base.IsDebugOn) { base.WriteDebug(Strings.DebugStartUpnUniquenessCheck); } using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.IsUserPrincipalNameUnique", LoggerHelper.CmdletPerfMonitors)) { RecipientTaskHelper.IsUserPrincipalNameUnique(base.TenantGlobalCatalogSession, user, user.UserPrincipalName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.ServerOperation, !flag); } if (base.IsDebugOn) { base.WriteDebug(Strings.DebugEndUpnUniquenessCheck); } if (!string.IsNullOrEmpty(user.SamAccountName)) { using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.IsSamAccountNameUnique", LoggerHelper.CmdletPerfMonitors)) { RecipientTaskHelper.IsSamAccountNameUnique(base.TenantGlobalCatalogSession, user, user.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.Client, !flag); goto IL_2C1; } } bool useRandomSuffix = this.WindowsLiveID != null && this.WindowsLiveID.SmtpAddress != SmtpAddress.Empty; if (base.IsDebugOn) { base.WriteDebug(Strings.DebugStartGeneratingUniqueSamAccountName); } using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.PrepareRecipientObject/VariantConfiguration", LoggerHelper.CmdletPerfMonitors)) { IRecipientSession[] recipientSessions = new IRecipientSession[] { base.RootOrgGlobalCatalogSession }; if (VariantConfiguration.InvariantNoFlightingSnapshot.CmdletInfra.ServiceAccountForest.Enabled && base.CurrentOrganizationId != OrganizationId.ForestWideOrgId) { recipientSessions = new IRecipientSession[] { base.RootOrgGlobalCatalogSession, base.PartitionOrRootOrgGlobalCatalogSession }; } using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.GenerateUniqueSamAccountName", LoggerHelper.CmdletPerfMonitors)) { user.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(recipientSessions, user.Id.DomainId, RecipientTaskHelper.GetLocalPartOfUserPrincalName(user.UserPrincipalName), false, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), useRandomSuffix); } } if (base.IsDebugOn) { base.WriteDebug(Strings.DebugEndGeneratingUniqueSamAccountName); } IL_2C1: if (string.IsNullOrEmpty(user.Alias)) { using (new CmdletMonitoredScope(base.CurrentTaskContext.UniqueId, "BizLogic", "RecipientTaskHelper.GenerateUniqueAlias", LoggerHelper.CmdletPerfMonitors)) { user.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, user.OrganizationId, string.IsNullOrEmpty(user.UserPrincipalName) ? user.SamAccountName : RecipientTaskHelper.GetLocalPartOfUserPrincalName(user.UserPrincipalName), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); } } if (base.Fields.IsModified("SKUCapability")) { user.SKUCapability = new Capability?(this.SKUCapability); } if (base.Fields.IsModified("AddOnSKUCapability")) { CapabilityHelper.SetAddOnSKUCapabilities(this.AddOnSKUCapability, user.PersistedCapabilities); RecipientTaskHelper.UpgradeArchiveQuotaOnArchiveAddOnSKU(user, user.PersistedCapabilities); } if (base.Fields.IsModified(ADRecipientSchema.SKUAssigned)) { user.SKUAssigned = new bool?(this.SKUAssigned); } TaskLogger.LogExit(); }
protected override void PrepareRecipientObject(ADGroup group) { TaskLogger.LogEnter(); base.PrepareRecipientObject(group); group.GroupType = (GroupTypeFlags.Universal | GroupTypeFlags.SecurityEnabled); group[ADRecipientSchema.Description] = new MultiValuedProperty <string>(this.Description); if (string.Equals(this.Description, CoreStrings.MsoManagedTenantAdminGroupDescription, StringComparison.Ordinal)) { group[ADGroupSchema.RoleGroupTypeId] = 23; } else if (string.Equals(this.Description, CoreStrings.MsoMailTenantAdminGroupDescription, StringComparison.Ordinal)) { group[ADGroupSchema.RoleGroupTypeId] = 24; } else if (string.Equals(this.Description, CoreStrings.MsoManagedTenantHelpdeskGroupDescription, StringComparison.Ordinal)) { group[ADGroupSchema.RoleGroupTypeId] = 25; } if (base.CurrentOrganizationId == OrganizationId.ForestWideOrgId) { ADObjectId adobjectId = RoleGroupCommon.RoleGroupContainerId(base.TenantGlobalCatalogSession, this.ConfigurationSession); group.SetId(adobjectId.GetChildId(this.Name)); } MailboxTaskHelper.StampOnManagedBy(this.DataObject, this.managedByRecipients, new Task.ErrorLoggerDelegate(base.WriteError)); this.DataObject.RecipientTypeDetails = RecipientTypeDetails.RoleGroup; MailboxTaskHelper.ValidateGroupManagedBy(base.TenantGlobalCatalogSession, group, this.managedByRecipients, RoleGroupCommon.OwnerRecipientTypeDetails, true, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>), new Task.ErrorLoggerDelegate(base.WriteError)); if (string.IsNullOrEmpty(group.SamAccountName)) { IRecipientSession[] recipientSessions = new IRecipientSession[] { base.RootOrgGlobalCatalogSession }; if (VariantConfiguration.InvariantNoFlightingSnapshot.CmdletInfra.ServiceAccountForest.Enabled && base.CurrentOrganizationId != OrganizationId.ForestWideOrgId) { recipientSessions = new IRecipientSession[] { base.RootOrgGlobalCatalogSession, base.PartitionOrRootOrgGlobalCatalogSession }; } group.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(recipientSessions, group.Id.DomainId, group.Name, true, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), false); } else { RecipientTaskHelper.IsSamAccountNameUnique(group, group.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.Client); } if ("crossforest" == base.ParameterSetName) { group.ForeignGroupSid = this.linkedGroupSid; } if ("linkedpartnergroup" == base.ParameterSetName) { group.LinkedPartnerGroupId = this.LinkedPartnerGroupId; group.LinkedPartnerOrganizationId = this.LinkedPartnerOrganizationId; } if (this.PartnerManaged.IsPresent) { group.RawCapabilities.Add(Capability.Partner_Managed); } if (base.Fields.IsChanged(RoleGroupParameters.ParameterMembers) && this.Members != null) { foreach (SecurityPrincipalIdParameter member in this.Members) { MailboxTaskHelper.ValidateAndAddMember(base.TenantGlobalCatalogSession, group, member, false, new Task.ErrorLoggerDelegate(base.WriteError), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>)); } } MailboxTaskHelper.ValidateAddedMembers(base.TenantGlobalCatalogSession, group, new Task.ErrorLoggerDelegate(base.WriteError), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>)); TaskLogger.LogExit(); }
protected override void PrepareRecipientObject(ADGroup group) { TaskLogger.LogEnter(); base.PrepareRecipientObject(group); Organization organization; if (base.Organization == null) { organization = this.ConfigurationSession.GetOrgContainer(); } else { organization = this.ConfigurationSession.Read <ExchangeConfigurationUnit>(base.CurrentOrgContainerId); } ADObjectId adobjectId = null; base.TryGetExecutingUserId(out adobjectId); if (!this.IgnoreNamingPolicy.IsPresent && adobjectId != null) { ADUser user = (ADUser)RecipientTaskHelper.CreatePartitionOrRootOrgScopedGcSession(null, adobjectId).Read(adobjectId); string groupNameWithNamingPolicy = DistributionGroupTaskHelper.GetGroupNameWithNamingPolicy(organization, user, group, base.Name, ADObjectSchema.Name, new Task.ErrorLoggerDelegate(base.WriteError)); if (groupNameWithNamingPolicy.Length > 64) { base.WriteError(new RecipientTaskException(Strings.ErrorDistributionGroupNameTooLong), ExchangeErrorCategory.Client, null); } base.Name = groupNameWithNamingPolicy; if (!string.IsNullOrEmpty(base.DisplayName)) { base.DisplayName = DistributionGroupTaskHelper.GetGroupNameWithNamingPolicy(organization, user, group, base.DisplayName, ADRecipientSchema.DisplayName, new Task.ErrorLoggerDelegate(base.WriteError)); } } if (base.OrganizationalUnit == null && !ADObjectId.IsNullOrEmpty(organization.DistributionGroupDefaultOU)) { group.SetId(organization.DistributionGroupDefaultOU.GetChildId(base.Name)); } if (base.OrganizationalUnit == null && group[ADRecipientSchema.DefaultDistributionListOU] != null) { ADObjectId adobjectId2 = (ADObjectId)group[ADRecipientSchema.DefaultDistributionListOU]; RecipientTaskHelper.ResolveOrganizationalUnitInOrganization(new OrganizationalUnitIdParameter(adobjectId2), this.ConfigurationSession, base.CurrentOrganizationId, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ExchangeOrganizationalUnit>), ExchangeErrorCategory.Client, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError)); group.SetId(adobjectId2.GetChildId(base.Name)); } if (this.Type != GroupType.Distribution && this.Type != GroupType.Security) { base.WriteError(new RecipientTaskException(Strings.ErrorGroupTypeInvalid), ExchangeErrorCategory.Client, null); } if (base.Fields.IsModified(DistributionGroupSchema.ManagedBy)) { MailboxTaskHelper.StampOnManagedBy(this.DataObject, this.managedByRecipients, new Task.ErrorLoggerDelegate(base.WriteError)); } if (this.RoomList.IsPresent) { if (this.Type != GroupType.Distribution) { base.WriteError(new RecipientTaskException(Strings.ErrorCreateRoomListSecurityGroup(base.Name)), ExchangeErrorCategory.Client, base.Name); } group.RecipientTypeDetails = RecipientTypeDetails.RoomList; if (group.ManagedBy != null) { group.AcceptMessagesOnlyFromSendersOrMembers = new MultiValuedProperty <ADObjectId>(group.ManagedBy); } } MailboxTaskHelper.ValidateGroupManagedBy(base.TenantGlobalCatalogSession, group, this.managedByRecipients, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>), new Task.ErrorLoggerDelegate(base.WriteError)); MailboxTaskHelper.ValidateGroupManagedByRecipientRestriction(base.TenantGlobalCatalogSession, group, this.managedByRecipients, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>), new Task.ErrorLoggerDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning)); group.GroupType = (GroupTypeFlags)((GroupType)8 | this.Type); if (!group.IsChanged(ADRecipientSchema.RecipientDisplayType)) { if ((group.GroupType & GroupTypeFlags.SecurityEnabled) == GroupTypeFlags.SecurityEnabled) { group.RecipientDisplayType = new RecipientDisplayType?(RecipientDisplayType.SecurityDistributionGroup); } else { group.RecipientDisplayType = new RecipientDisplayType?(RecipientDisplayType.DistributionGroup); } } if (string.IsNullOrEmpty(group.SamAccountName)) { IRecipientSession[] recipientSessions = new IRecipientSession[] { base.RootOrgGlobalCatalogSession }; if (VariantConfiguration.InvariantNoFlightingSnapshot.CmdletInfra.ServiceAccountForest.Enabled && base.CurrentOrganizationId != OrganizationId.ForestWideOrgId) { recipientSessions = new IRecipientSession[] { base.RootOrgGlobalCatalogSession, base.PartitionOrRootOrgGlobalCatalogSession }; } group.SamAccountName = RecipientTaskHelper.GenerateUniqueSamAccountName(recipientSessions, group.Id.DomainId, group.Name, true, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), false); } else { RecipientTaskHelper.IsSamAccountNameUnique(group, group.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.Client); } if (string.IsNullOrEmpty(group.Alias)) { group.Alias = RecipientTaskHelper.GenerateUniqueAlias(base.TenantGlobalCatalogSession, base.CurrentOrganizationId, group.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); } if (base.Fields.IsChanged(ADGroupSchema.Members) && this.Members != null) { foreach (RecipientIdParameter member in this.Members) { MailboxTaskHelper.ValidateAndAddMember(base.TenantGlobalCatalogSession, group, member, false, new Task.ErrorLoggerDelegate(base.WriteError), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>)); } } if (this.CopyOwnerToMember.IsPresent && this.managedByRecipients != null) { foreach (ADRecipient adrecipient in this.managedByRecipients) { if (!group.Members.Contains(adrecipient.Id)) { MailboxTaskHelper.ValidateMemberInGroup(adrecipient, group, new Task.ErrorLoggerDelegate(base.WriteError)); group.Members.Add(adrecipient.Id); } } } if ((group.GroupType & GroupTypeFlags.Universal) == GroupTypeFlags.Universal) { MailboxTaskHelper.ValidateAddedMembers(base.TenantGlobalCatalogSession, group, new Task.ErrorLoggerDelegate(base.WriteError), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>)); } if (!this.DataObject.IsModified(ADGroupSchema.MemberDepartRestriction)) { this.DataObject.MemberDepartRestriction = ((this.Type == GroupType.Security) ? MemberUpdateType.Closed : MemberUpdateType.Open); } if (group.ArbitrationMailbox == null) { group.ArbitrationMailbox = MailboxTaskHelper.GetArbitrationMailbox(base.TenantGlobalCatalogSession, base.CurrentOrgContainerId); if (group.ArbitrationMailbox == null) { if (group.MemberJoinRestriction == MemberUpdateType.ApprovalRequired || group.MemberDepartRestriction == MemberUpdateType.ApprovalRequired) { base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMbxNotSetForApproval(base.Name)), ExchangeErrorCategory.Client, group.Identity); } if (group.ModerationEnabled) { base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMbxNotSetForModeration(base.Name)), ExchangeErrorCategory.Client, group.Identity); } } } DistributionGroupTaskHelper.CheckMembershipRestriction(group, new Task.ErrorLoggerDelegate(base.WriteError)); TaskLogger.LogExit(); }