Beispiel #1
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            if (base.HasErrors)
            {
                return;
            }
            DistributionGroupTaskHelper.CheckMembershipRestriction(this.DataObject, new Task.ErrorLoggerDelegate(base.WriteError));
            if (this.RoomList.IsPresent && this.DataObject.RecipientTypeDetails != RecipientTypeDetails.RoomList)
            {
                this.ValidateConvertToRoomList();
            }
            base.ValidateMultiReferenceParameter(DistributionGroupSchema.ManagedBy, new ValidateRecipientWithBaseObjectDelegate <ADGroup>(MailboxTaskHelper.ValidateGroupManagedBy));
            MultiValuedProperty <ADRecipient> recipients;

            this.recipientsDictionary.TryGetValue(DistributionGroupSchema.ManagedBy, out recipients);
            if (base.Fields.IsModified(DistributionGroupSchema.ManagedBy) || base.Fields.IsModified(DistributionGroupSchema.MemberJoinRestriction) || base.Fields.IsModified(DistributionGroupSchema.MemberDepartRestriction) || this.DataObject.ModerationEnabled || base.Fields.IsModified(MailEnabledRecipientSchema.ModeratedBy))
            {
                MailboxTaskHelper.ValidateGroupManagedByRecipientRestriction(base.TenantGlobalCatalogSession, this.DataObject, recipients, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADRecipient>), new Task.ErrorLoggerDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning));
            }
            if (this.DataObject.IsModified(ADMailboxRecipientSchema.SamAccountName))
            {
                RecipientTaskHelper.IsSamAccountNameUnique(this.DataObject, this.DataObject.SamAccountName, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), ExchangeErrorCategory.Client);
            }
            if (base.Fields.IsModified("ExpansionServer"))
            {
                this.DataObject.ExpansionServer = this.ExpansionServer;
                this.DataObject.HomeMTA         = this.homeMTA;
            }
            else if (this.DataObject.IsChanged(DistributionGroupBaseSchema.ExpansionServer))
            {
                if (!string.IsNullOrEmpty(this.DataObject.ExpansionServer))
                {
                    QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, ServerSchema.ExchangeLegacyDN, this.DataObject.ExpansionServer);
                    base.WriteVerbose(TaskVerboseStringHelper.GetFindDataObjectsVerboseString(base.GlobalConfigSession, typeof(Server), filter, null, true));
                    Server[] array = null;
                    try
                    {
                        array = base.GlobalConfigSession.Find <Server>(null, QueryScope.SubTree, filter, null, 2);
                    }
                    finally
                    {
                        base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(base.GlobalConfigSession));
                    }
                    switch (array.Length)
                    {
                    case 0:
                        base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorServerNotFound(this.DataObject.ExpansionServer)), ExchangeErrorCategory.Client, this.Identity);
                        return;

                    case 1:
                        base.ValidateExpansionServer(array[0], false);
                        this.DataObject.ExpansionServer = array[0].ExchangeLegacyDN;
                        break;

                    case 2:
                        base.WriteError(new ManagementObjectAmbiguousException(Strings.ErrorServerNotUnique(this.DataObject.ExpansionServer)), ExchangeErrorCategory.Client, this.Identity);
                        return;
                    }
                    this.DataObject.HomeMTA = array[0].ResponsibleMTA;
                }
                else
                {
                    this.DataObject.HomeMTA = null;
                }
            }
            DistributionGroupTaskHelper.CheckModerationInMixedEnvironment(this.DataObject, new Task.TaskWarningLoggingDelegate(this.WriteWarning), Strings.WarningLegacyExchangeServer);
            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();
        }