Esempio n. 1
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            IRecipientSession recipientSession = (IRecipientSession)base.DataSession;

            if (this.GenerateExternalDirectoryObjectId && string.IsNullOrEmpty(this.DataObject.ExternalDirectoryObjectId))
            {
                this.DataObject.ExternalDirectoryObjectId = Guid.NewGuid().ToString();
            }
            if (this.BusinessNetID != null)
            {
                this.DataObject.ConsumerNetID = this.DataObject.NetID;
                this.DataObject.NetID         = this.BusinessNetID;
            }
            if (this.CopyShadowAttributes)
            {
                foreach (PropertyDefinition propertyDefinition in this.DataObject.Schema.AllProperties)
                {
                    ADPropertyDefinition adpropertyDefinition = propertyDefinition as ADPropertyDefinition;
                    if (adpropertyDefinition != null)
                    {
                        object value = null;
                        if (adpropertyDefinition.ShadowProperty != null && this.DataObject.propertyBag.TryGetField(adpropertyDefinition, ref value))
                        {
                            this.DataObject.propertyBag[adpropertyDefinition.ShadowProperty] = value;
                        }
                    }
                }
            }
            if (this.EnableAccount.IsPresent && this.DataObject.UserAccountControl == (UserAccountControlFlags.AccountDisabled | UserAccountControlFlags.PasswordNotRequired | UserAccountControlFlags.NormalAccount))
            {
                this.DataObject.UserAccountControl = UserAccountControlFlags.NormalAccount;
                using (SecureString randomPassword = MailboxTaskUtilities.GetRandomPassword(this.DataObject.Name, this.DataObject.SamAccountName))
                {
                    recipientSession.SetPassword(this.DataObject, randomPassword);
                }
            }
            if (base.Fields.IsModified(ADRecipientSchema.LEOEnabled))
            {
                this.DataObject.LEOEnabled = this.LEOEnabled;
            }
            if (base.Fields.IsModified("UpgradeMessage"))
            {
                this.DataObject.UpgradeMessage = this.UpgradeMessage;
            }
            if (base.Fields.IsModified("UpgradeDetails"))
            {
                this.DataObject.UpgradeDetails = this.UpgradeDetails;
            }
            if (base.Fields.IsModified("UpgradeStage"))
            {
                this.DataObject.UpgradeStage = this.UpgradeStage;
            }
            if (base.Fields.IsModified("UpgradeStageTimeStamp"))
            {
                this.DataObject.UpgradeStageTimeStamp = this.UpgradeStageTimeStamp;
            }
            if (base.Fields.IsModified("MailboxRelease"))
            {
                this.DataObject.MailboxRelease = this.MailboxRelease;
            }
            if (base.Fields.IsModified("ArchiveRelease"))
            {
                this.DataObject.ArchiveRelease = this.ArchiveRelease;
            }
            base.InternalProcessRecord();
            TaskLogger.LogExit();
        }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            try
            {
                ADUser            dataObject       = this.DataObject;
                IRecipientSession recipientSession = (IRecipientSession)base.DataSession;
                recipientSession.Save(dataObject);
                ADUser aduser = (ADUser)base.DataSession.Read <ADUser>(dataObject.Identity);
                if (aduser == null)
                {
                    throw new LocalizedException(Strings.ErrorReadingUpdatedUserFromAD(dataObject.OriginatingServer, recipientSession.LastUsedDc));
                }
                aduser.UserAccountControl = UserAccountControlFlags.None;
                if (this.LogonEnabled)
                {
                    using (SecureString randomPassword = MailboxTaskUtilities.GetRandomPassword(this.Name, aduser.SamAccountName))
                    {
                        recipientSession.SetPassword(aduser, randomPassword);
                        goto IL_98;
                    }
                }
                aduser.UserAccountControl |= UserAccountControlFlags.AccountDisabled;
IL_98:
                aduser.UserAccountControl |= UserAccountControlFlags.NormalAccount;
                this.DataObject            = aduser;
                base.InternalProcessRecord();
            }
            catch (ADObjectAlreadyExistsException ex)
            {
                base.WriteVerbose(Strings.UserCreateFailed(this.Name, ex.Message.ToString()));
            }
            LocalizedString localizedString = LocalizedString.Empty;

            try
            {
                base.WriteVerbose(Strings.VerboseGrantingEoaFullAccessOnMailbox(this.DataObject.Identity.ToString()));
                ADGroup adgroup = base.RootOrgGlobalCatalogSession.ResolveWellKnownGuid <ADGroup>(WellKnownGuid.EoaWkGuid, base.GlobalConfigSession.ConfigurationNamingContext.ToDNString());
                if (adgroup == null)
                {
                    localizedString = Strings.ErrorGroupNotFound(WellKnownGuid.EoaWkGuid.ToString());
                }
                else
                {
                    DirectoryCommon.SetAces(new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), null, (IDirectorySession)base.DataSession, this.DataObject.Id, new ActiveDirectoryAccessRule[]
                    {
                        new ActiveDirectoryAccessRule(adgroup.Sid, ActiveDirectoryRights.GenericAll, AccessControlType.Allow, ActiveDirectorySecurityInheritance.All)
                    });
                }
            }
            catch (ADTransientException ex2)
            {
                localizedString = ex2.LocalizedString;
            }
            catch (ADOperationException ex3)
            {
                localizedString = ex3.LocalizedString;
            }
            catch (SecurityDescriptorAccessDeniedException ex4)
            {
                localizedString = ex4.LocalizedString;
            }
            if (LocalizedString.Empty != localizedString)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorGrantingEraFullAccessOnMailbox(this.DataObject.Identity.ToString(), localizedString)), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            TaskLogger.LogExit();
        }