Exemple #1
0
        protected override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            ExchangeOrganizationalUnit exchangeOrganizationalUnit = null;

            ((IConfigurationSession)base.DataSession).SessionSettings.IsSharedConfigChecked = true;
            this.ConfigurationSession.SessionSettings.IsSharedConfigChecked = true;
            this.DataObject = (ExchangeRoleAssignment)base.PrepareDataObject();
            if (base.HasErrors)
            {
                return(null);
            }
            if (!this.IgnoreDehydratedFlag)
            {
                SharedConfigurationTaskHelper.VerifyIsNotTinyTenant(base.CurrentOrgState, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            this.role = (ExchangeRole)base.GetDataObject <ExchangeRole>(this.Role, base.DataSession, null, new LocalizedString?(Strings.ErrorRoleNotFound(this.Role.ToString())), new LocalizedString?(Strings.ErrorRoleNotUnique(this.Role.ToString())));
            RoleHelper.VerifyNoScopeForUnScopedRole(base.Fields, this.role, new Task.TaskErrorLoggingDelegate(base.WriteError));
            if (this.role != null && this.role.IsDeprecated)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorCannotCreateRoleAssignmentToADeprecatedRole(this.role.ToString())), ErrorCategory.InvalidOperation, null);
            }
            RoleAssigneeType roleAssigneeType;
            ADObject         adobject;

            if (this.Policy != null)
            {
                RoleAssignmentPolicy roleAssignmentPolicy = (RoleAssignmentPolicy)base.GetDataObject <RoleAssignmentPolicy>(this.Policy, RecipientTaskHelper.GetTenantLocalConfigSession(base.CurrentOrganizationId, base.ExecutingUserOrganizationId, base.RootOrgContainerId), null, new LocalizedString?(Strings.ErrorRBACPolicyNotFound(this.Policy.ToString())), new LocalizedString?(Strings.ErrorRBACPolicyNotUnique(this.Policy.ToString())));
                if (!this.role.IsEndUserRole)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorNonEndUserRoleCannoBeAssignedToPolicy(this.role.Name)), ErrorCategory.InvalidOperation, roleAssignmentPolicy.Id);
                }
                OrganizationId organizationId = OrganizationId.ForestWideOrgId;
                if (this.ConfigurationSession is ITenantConfigurationSession)
                {
                    organizationId = TaskHelper.ResolveOrganizationId(this.role.Id, ExchangeRole.RdnContainer, (ITenantConfigurationSession)this.ConfigurationSession);
                }
                ADObjectId adobjectId;
                if (OrganizationId.ForestWideOrgId.Equals(organizationId))
                {
                    adobjectId = this.ConfigurationSession.GetOrgContainerId();
                }
                else
                {
                    adobjectId = organizationId.ConfigurationUnit;
                }
                if (!roleAssignmentPolicy.Id.IsDescendantOf(adobjectId))
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorPolicyOutOfRoleScope(roleAssignmentPolicy.Id.ToString(), adobjectId.Name)), ErrorCategory.InvalidOperation, null);
                }
                roleAssigneeType = RoleAssigneeType.RoleAssignmentPolicy;
                adobject         = roleAssignmentPolicy;
            }
            else
            {
                ADRecipient adrecipient = null;
                if (this.User != null)
                {
                    adrecipient = (ADUser)base.GetDataObject <ADUser>(this.User, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorAssigneeUserNotFound(this.User.ToString())), new LocalizedString?(Strings.ErrorAssigneeUserNotUnique(this.User.ToString())));
                }
                else if (this.SecurityGroup != null)
                {
                    adrecipient = (ADGroup)base.GetDataObject <ADGroup>(this.SecurityGroup, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorAssigneeSecurityGroupNotFound(this.SecurityGroup.ToString())), new LocalizedString?(Strings.ErrorAssigneeSecurityGroupNotUnique(this.SecurityGroup.ToString())));
                }
                else if (this.Computer != null)
                {
                    adrecipient = (ADComputerRecipient)base.GetDataObject <ADComputerRecipient>(this.Computer, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorAssigneeComputerNotFound(this.Computer.ToString())), new LocalizedString?(Strings.ErrorAssigneeComputerNotUnique(this.Computer.ToString())));
                }
                RoleHelper.ValidateRoleAssignmentUser(adrecipient, new Task.TaskErrorLoggingDelegate(base.WriteError), false);
                roleAssigneeType = ExchangeRoleAssignment.RoleAssigneeTypeFromADRecipient(adrecipient);
                adobject         = adrecipient;
            }
            ((IDirectorySession)base.DataSession).LinkResolutionServer = adobject.OriginatingServer;
            RoleHelper.PrepareNewRoleAssignmentWithUniqueNameAndDefaultScopes(this.Name, this.DataObject, this.role, adobject.Id, adobject.OrganizationId, roleAssigneeType, this.Delegating.IsPresent ? RoleAssignmentDelegationType.Delegating : RoleAssignmentDelegationType.Regular, this.ConfigurationSession, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskErrorLoggingDelegate(base.WriteError));
            if (this.role.IsUnscopedTopLevel && this.UnScopedTopLevel)
            {
                this.skipHRoleCheck = true;
                if (this.Delegating)
                {
                    this.DataObject.RoleAssignmentDelegationType = RoleAssignmentDelegationType.DelegatingOrgWide;
                }
            }
            else
            {
                RoleHelper.AnalyzeAndStampCustomizedWriteScopes(this, this.DataObject, this.role, this.ConfigurationSession, new DataAccessHelper.GetDataObjectDelegate(base.GetDataObject <ExchangeOrganizationalUnit>), new DataAccessHelper.GetDataObjectDelegate(base.GetDataObject <ManagementScope>), ref this.skipHRoleCheck, ref exchangeOrganizationalUnit, ref this.customRecipientScope, ref this.customConfigScope);
            }
            TaskLogger.LogExit();
            return(this.DataObject);
        }
Exemple #2
0
		protected override void ResolveLocalSecondaryIdentities()
		{
			base.ResolveLocalSecondaryIdentities();
			Mailbox mailbox = (Mailbox)this.GetDynamicParameters();
			if (this.RemoveManagedFolderAndPolicy)
			{
				mailbox.ManagedFolderMailboxPolicy = null;
			}
			if (base.Fields.IsModified(MailboxSchema.RetentionPolicy))
			{
				if (this.RetentionPolicy != null)
				{
					RetentionPolicy retentionPolicy = (RetentionPolicy)base.GetDataObject<RetentionPolicy>(this.RetentionPolicy, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorRetentionPolicyNotFound(this.RetentionPolicy.ToString())), new LocalizedString?(Strings.ErrorRetentionPolicyNotUnique(this.RetentionPolicy.ToString())), ExchangeErrorCategory.Client);
					mailbox.RetentionPolicy = (ADObjectId)retentionPolicy.Identity;
					mailbox.ManagedFolderMailboxPolicy = null;
				}
				else
				{
					mailbox.RetentionPolicy = null;
				}
			}
			base.SetReferenceParameter<RecipientIdParameter>(MailboxSchema.ForwardingAddress, this.ForwardingAddress, mailbox, new GetRecipientDelegate<RecipientIdParameter>(this.GetRecipient));
			if (base.Fields.IsModified(MailboxSchema.OfflineAddressBook))
			{
				if (this.OfflineAddressBook != null)
				{
					OfflineAddressBook offlineAddressBook = (OfflineAddressBook)base.GetDataObject<OfflineAddressBook>(this.OfflineAddressBook, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorOfflineAddressBookNotFound(this.OfflineAddressBook.ToString())), new LocalizedString?(Strings.ErrorOfflineAddressBookNotUnique(this.OfflineAddressBook.ToString())), ExchangeErrorCategory.Client);
					mailbox.OfflineAddressBook = (ADObjectId)offlineAddressBook.Identity;
				}
				else
				{
					mailbox.OfflineAddressBook = null;
				}
			}
			if (base.Fields.IsModified(ADRecipientSchema.AddressBookPolicy))
			{
				AddressBookMailboxPolicyIdParameter addressBookMailboxPolicyIdParameter = (AddressBookMailboxPolicyIdParameter)base.Fields[ADRecipientSchema.AddressBookPolicy];
				if (addressBookMailboxPolicyIdParameter != null)
				{
					AddressBookMailboxPolicy addressBookMailboxPolicy = (AddressBookMailboxPolicy)base.GetDataObject<AddressBookMailboxPolicy>(addressBookMailboxPolicyIdParameter, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotFound(addressBookMailboxPolicyIdParameter.ToString())), new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotUnique(addressBookMailboxPolicyIdParameter.ToString())), ExchangeErrorCategory.Client);
					mailbox[ADRecipientSchema.AddressBookPolicy] = (ADObjectId)addressBookMailboxPolicy.Identity;
				}
				else
				{
					mailbox[ADRecipientSchema.AddressBookPolicy] = null;
				}
			}
			if (base.Fields.IsModified(ADRecipientSchema.ThrottlingPolicy))
			{
				if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
				{
					base.WriteError(new TaskInvalidOperationException(Strings.ErrorLinkOpOnDehydratedTenant("ThrottlingPolicy")), ExchangeErrorCategory.Context, this.DataObject.Identity);
				}
				ThrottlingPolicyIdParameter throttlingPolicyIdParameter = (ThrottlingPolicyIdParameter)base.Fields[ADRecipientSchema.ThrottlingPolicy];
				if (throttlingPolicyIdParameter != null)
				{
					ThrottlingPolicy throttlingPolicy = (ThrottlingPolicy)base.GetDataObject<ThrottlingPolicy>(throttlingPolicyIdParameter, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorThrottlingPolicyNotFound(throttlingPolicyIdParameter.ToString())), new LocalizedString?(Strings.ErrorThrottlingPolicyNotUnique(throttlingPolicyIdParameter.ToString())), ExchangeErrorCategory.Client);
					mailbox[ADRecipientSchema.ThrottlingPolicy] = (ADObjectId)throttlingPolicy.Identity;
				}
				else
				{
					mailbox[ADRecipientSchema.ThrottlingPolicy] = null;
				}
			}
			if (base.Fields.IsModified(ADUserSchema.SharingPolicy))
			{
				if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
				{
					base.WriteError(new LocalizedException(Strings.ErrorLinkOpOnDehydratedTenant("SharingPolicy")), ExchangeErrorCategory.Client, this.DataObject);
				}
				SharingPolicyIdParameter sharingPolicyIdParameter = (SharingPolicyIdParameter)base.Fields[ADUserSchema.SharingPolicy];
				if (sharingPolicyIdParameter != null)
				{
					SharingPolicy sharingPolicy = (SharingPolicy)base.GetDataObject<SharingPolicy>(sharingPolicyIdParameter, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorSharingPolicyNotFound(sharingPolicyIdParameter.ToString())), new LocalizedString?(Strings.ErrorSharingPolicyNotUnique(sharingPolicyIdParameter.ToString())), ExchangeErrorCategory.Client);
					mailbox[ADUserSchema.SharingPolicy] = (ADObjectId)sharingPolicy.Identity;
				}
				else
				{
					mailbox[ADUserSchema.SharingPolicy] = null;
				}
			}
			if (base.Fields.IsModified(ADUserSchema.RemoteAccountPolicy))
			{
				RemoteAccountPolicyIdParameter remoteAccountPolicyIdParameter = (RemoteAccountPolicyIdParameter)base.Fields[ADUserSchema.RemoteAccountPolicy];
				if (remoteAccountPolicyIdParameter != null)
				{
					RemoteAccountPolicy remoteAccountPolicy = (RemoteAccountPolicy)base.GetDataObject<RemoteAccountPolicy>(remoteAccountPolicyIdParameter, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorRemoteAccountPolicyNotFound(remoteAccountPolicyIdParameter.ToString())), new LocalizedString?(Strings.ErrorRemoteAccountPolicyNotUnique(remoteAccountPolicyIdParameter.ToString())), ExchangeErrorCategory.Client);
					mailbox[ADUserSchema.RemoteAccountPolicy] = (ADObjectId)remoteAccountPolicy.Identity;
				}
				else
				{
					mailbox[ADUserSchema.RemoteAccountPolicy] = null;
				}
			}
			if (base.Fields.IsModified(ADRecipientSchema.RoleAssignmentPolicy))
			{
				MailboxPolicyIdParameter mailboxPolicyIdParameter = (MailboxPolicyIdParameter)base.Fields[ADRecipientSchema.RoleAssignmentPolicy];
				if (mailboxPolicyIdParameter != null)
				{
					IConfigurationSession tenantLocalConfigSession = RecipientTaskHelper.GetTenantLocalConfigSession(base.CurrentOrganizationId, base.ExecutingUserOrganizationId, base.RootOrgContainerId);
					RoleAssignmentPolicy roleAssignmentPolicy = (RoleAssignmentPolicy)base.GetDataObject<RoleAssignmentPolicy>(mailboxPolicyIdParameter, tenantLocalConfigSession, null, new LocalizedString?(Strings.ErrorRoleAssignmentPolicyNotFound(mailboxPolicyIdParameter.ToString())), new LocalizedString?(Strings.ErrorRoleAssignmentPolicyNotUnique(mailboxPolicyIdParameter.ToString())), ExchangeErrorCategory.Client);
					mailbox[ADRecipientSchema.RoleAssignmentPolicy] = (ADObjectId)roleAssignmentPolicy.Identity;
				}
				else
				{
					mailbox[ADRecipientSchema.RoleAssignmentPolicy] = null;
				}
			}
			if (base.Fields.IsModified(ADRecipientSchema.MailboxPlan))
			{
				if (this.MailboxPlan != null)
				{
					ADUser aduser = base.ProvisioningCache.TryAddAndGetOrganizationDictionaryValue<ADUser, string>(CannedProvisioningCacheKeys.CacheKeyMailboxPlanIdParameterId, base.CurrentOrganizationId, this.MailboxPlan.RawIdentity, () => (ADUser)base.GetDataObject<ADUser>(this.MailboxPlan, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxPlanNotFound(this.MailboxPlan.ToString())), new LocalizedString?(Strings.ErrorMailboxPlanNotUnique(this.MailboxPlan.ToString())), ExchangeErrorCategory.Client));
					MailboxTaskHelper.ValidateMailboxPlanRelease(aduser, new Task.ErrorLoggerDelegate(base.WriteError));
					mailbox[ADRecipientSchema.MailboxPlan] = (ADObjectId)aduser.Identity;
					return;
				}
				mailbox[ADRecipientSchema.MailboxPlan] = null;
			}
		}
        protected override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            ADRecipient adrecipient = (ADRecipient)base.PrepareDataObject();

            if (base.IsProvisioningLayerAvailable)
            {
                Fqdn value = (Fqdn)base.UserSpecifiedParameters["DomainController"];
                try
                {
                    base.UserSpecifiedParameters["DomainController"] = this.globalCatalog;
                    ProvisioningLayer.UpdateAffectedIConfigurable(this, RecipientTaskHelper.ConvertRecipientToPresentationObject(adrecipient), false);
                    goto IL_82;
                }
                finally
                {
                    base.UserSpecifiedParameters["DomainController"] = value;
                }
            }
            base.WriteError(new InvalidOperationException(Strings.ErrorNoProvisioningHandlerAvailable), (ErrorCategory)1012, null);
IL_82:
            if (RecipientType.UserMailbox == adrecipient.RecipientType)
            {
                ADUser aduser = (ADUser)adrecipient;
                if (string.IsNullOrEmpty(aduser.ServerLegacyDN))
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Mailbox).Name, adrecipient.Identity.ToString(), MailEnabledRecipientSchema.LegacyExchangeDN.Name)), (ErrorCategory)1009, this.Identity);
                }
                Server server = this.configurationSession.FindServerByLegacyDN(aduser.ServerLegacyDN);
                if (server != null)
                {
                    if (!server.IsExchange2007OrLater)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorCannotUpdateLegacyMailbox(this.Identity.ToString())), (ErrorCategory)1010, this.Identity);
                    }
                    else if (RecipientTaskHelper.IsE15OrLater(server.VersionNumber))
                    {
                        if (adrecipient.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2012))
                        {
                            adrecipient.SetExchangeVersion(ExchangeObjectVersion.Exchange2012);
                        }
                    }
                    else if (server.IsE14OrLater)
                    {
                        if (adrecipient.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2010))
                        {
                            adrecipient.SetExchangeVersion(ExchangeObjectVersion.Exchange2010);
                        }
                    }
                    else if (adrecipient.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2007))
                    {
                        adrecipient.SetExchangeVersion(ExchangeObjectVersion.Exchange2007);
                    }
                }
                SetMailboxBase <MailboxIdParameter, Mailbox> .StampMailboxTypeDetails(adrecipient, true);

                MailboxTaskHelper.StampMailboxRecipientDisplayType(adrecipient);
                if (server != null && server.IsE14OrLater)
                {
                    NetID netID = aduser.NetID;
                    if (netID != null)
                    {
                        aduser.NetID = netID;
                    }
                }
                if (aduser.RoleAssignmentPolicy == null && RecipientTypeDetails.None == (aduser.RecipientTypeDetails & (RecipientTypeDetails.PublicFolder | RecipientTypeDetails.SystemMailbox | RecipientTypeDetails.ArbitrationMailbox | RecipientTypeDetails.DiscoveryMailbox | RecipientTypeDetails.AuditLogMailbox)))
                {
                    RoleAssignmentPolicy roleAssignmentPolicy = RecipientTaskHelper.FindDefaultRoleAssignmentPolicy(RecipientTaskHelper.GetTenantLocalConfigSession(base.CurrentOrganizationId, base.ExecutingUserOrganizationId, base.RootOrgContainerId), new Task.ErrorLoggerDelegate(base.WriteError), Strings.ErrorDefaultRoleAssignmentPolicyNotUnique, Strings.ErrorDefaultRoleAssignmentPolicyNotFound);
                    if (roleAssignmentPolicy != null)
                    {
                        aduser.RoleAssignmentPolicy = (ADObjectId)roleAssignmentPolicy.Identity;
                    }
                }
            }
            TaskLogger.LogExit();
            return(adrecipient);
        }