Example #1
0
 protected override void InternalValidate()
 {
     base.InternalValidate();
     if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
     {
         base.WriteError(new ArgumentException(Strings.ErrorWriteOpOnDehydratedTenant), ErrorCategory.InvalidArgument, base.DataObject.Identity);
     }
 }
 protected override void InternalValidate()
 {
     base.InternalValidate();
     if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
     {
         base.WriteError(new ArgumentException(Strings.ErrorWriteOpOnDehydratedTenant), ErrorCategory.InvalidArgument, base.DataObject.Identity);
     }
     if (base.DataObject.IsDefault || base.DataObject.IsDefaultArbitrationMailbox)
     {
         base.WriteError(new InvalidOperationException(Strings.RemovingDefaultPolicyIsNotSupported(this.Identity.ToString())), ErrorCategory.WriteError, base.DataObject);
     }
 }
        protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
        {
            if (dataObject == null)
            {
                return(null);
            }
            ADUser user = (ADUser)dataObject;
            SharedConfiguration sharedConfig = null;

            if (SharedConfiguration.IsDehydratedConfiguration(user.OrganizationId) || (SharedConfiguration.GetSharedConfigurationState(user.OrganizationId) & SharedTenantConfigurationState.Static) != SharedTenantConfigurationState.UnSupported)
            {
                sharedConfig = base.ProvisioningCache.TryAddAndGetOrganizationData <SharedConfiguration>(CannedProvisioningCacheKeys.MailboxSharedConfigCacheKey, user.OrganizationId, () => SharedConfiguration.GetSharedConfiguration(user.OrganizationId));
            }
            if (null != user.MasterAccountSid)
            {
                user.LinkedMasterAccount = SecurityPrincipalIdParameter.GetFriendlyUserName(user.MasterAccountSid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                user.ResetChangeTracking();
            }
            Mailbox mailbox = new Mailbox(user);

            mailbox.propertyBag.SetField(MailboxSchema.Database, ADObjectIdResolutionHelper.ResolveDN(mailbox.Database));
            if (sharedConfig != null)
            {
                mailbox.SharedConfiguration = sharedConfig.SharedConfigId.ConfigurationUnit;
                if (mailbox.RoleAssignmentPolicy == null)
                {
                    mailbox.RoleAssignmentPolicy = base.ProvisioningCache.TryAddAndGetOrganizationData <ADObjectId>(CannedProvisioningCacheKeys.MailboxRoleAssignmentPolicyCacheKey, user.OrganizationId, () => sharedConfig.GetSharedRoleAssignmentPolicy());
                }
            }
            else if (mailbox.RoleAssignmentPolicy == null && !mailbox.ExchangeVersion.IsOlderThan(MailboxSchema.RoleAssignmentPolicy.VersionAdded))
            {
                ADObjectId defaultRoleAssignmentPolicy = RBACHelper.GetDefaultRoleAssignmentPolicy(user.OrganizationId);
                if (defaultRoleAssignmentPolicy != null)
                {
                    mailbox.RoleAssignmentPolicy = defaultRoleAssignmentPolicy;
                }
            }
            if (mailbox.SharingPolicy == null && !mailbox.propertyBag.IsReadOnlyProperty(MailboxSchema.SharingPolicy))
            {
                mailbox.SharingPolicy = base.GetDefaultSharingPolicyId(user, sharedConfig);
            }
            if (mailbox.RetentionPolicy == null && mailbox.ShouldUseDefaultRetentionPolicy && !mailbox.propertyBag.IsReadOnlyProperty(MailboxSchema.RetentionPolicy))
            {
                mailbox.RetentionPolicy = base.GetDefaultRetentionPolicyId(user, sharedConfig);
            }
            if (mailbox.Database != null && mailbox.UseDatabaseRetentionDefaults)
            {
                this.SetDefaultRetentionValues(mailbox);
            }
            mailbox.AdminDisplayVersion = Microsoft.Exchange.Data.Directory.SystemConfiguration.Server.GetServerVersion(mailbox.ServerName);
            return(mailbox);
        }
        // Token: 0x06000E5F RID: 3679 RVA: 0x000566F0 File Offset: 0x000548F0
        private static SharingPolicyCache InternalGet(OrganizationId orgId, ADObjectId policyId)
        {
            orgId    = (orgId ?? OrganizationId.ForestWideOrgId);
            policyId = (policyId ?? SharingPolicyCache.DynamicDefaultPolicy);
            bool flag = SharedConfiguration.IsDehydratedConfiguration(orgId);

            SharingPolicyCache.Tracer.TraceDebug <ADObjectId, string, OrganizationId>(0L, "Find Sharing policy {0} in {1} Org {2} ", policyId, flag ? "dehydrated" : "hydrated", orgId);
            if (!flag)
            {
                return(SharingPolicyCache.GetHydratedPolicyFromCacheOrAD(orgId, policyId));
            }
            return(SharingPolicyCache.GetDehydratedPolicyFromCacheOrAD(orgId, policyId));
        }
        public static SharingPolicy ReadSharingPolicy(Guid mailboxGuid, bool isArchive, IRecipientSession recipientSession)
        {
            ADRecipient adrecipient = DirectoryHelper.ReadADRecipient(mailboxGuid, isArchive, recipientSession);

            if (adrecipient == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
            }
            ADUser aduser = adrecipient as ADUser;

            if (aduser == null)
            {
                ExTraceGlobals.StorageTracer.TraceError <ADRecipient>((long)mailboxGuid.GetHashCode(), "ExchangePrincipal::ReadSharingPolicy. This is not an ADUser so policy doesn't apply. Recipient = {0}.", adrecipient);
                return(null);
            }
            ADObjectId        adobjectId = aduser.SharingPolicy;
            ADSessionSettings adsessionSettings;

            if (SharedConfiguration.IsDehydratedConfiguration(aduser.OrganizationId))
            {
                SharedConfiguration sharedConfiguration = SharedConfiguration.GetSharedConfiguration(aduser.OrganizationId);
                adsessionSettings = sharedConfiguration.GetSharedConfigurationSessionSettings();
            }
            else
            {
                adsessionSettings = aduser.OrganizationId.ToADSessionSettings();
                adsessionSettings.IsSharedConfigChecked = true;
            }
            IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, adsessionSettings, 248, "ReadSharingPolicy", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\DirectoryHelper.cs");

            if (adobjectId == null)
            {
                FederatedOrganizationId federatedOrganizationId = tenantOrTopologyConfigurationSession.GetFederatedOrganizationId(tenantOrTopologyConfigurationSession.SessionSettings.CurrentOrganizationId);
                if (federatedOrganizationId != null)
                {
                    adobjectId = federatedOrganizationId.DefaultSharingPolicyLink;
                }
            }
            SharingPolicy sharingPolicy = null;

            if (adobjectId != null)
            {
                sharingPolicy = tenantOrTopologyConfigurationSession.Read <SharingPolicy>(adobjectId);
                if (sharingPolicy == null)
                {
                    throw new ObjectNotFoundException(ServerStrings.SharingPolicyNotFound(adobjectId.Name));
                }
            }
            return(sharingPolicy);
        }
 protected override void InternalBeginProcessing()
 {
     TaskLogger.LogEnter();
     base.InternalBeginProcessing();
     if (this.RetentionPolicy != null)
     {
         if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
         {
             base.WriteError(new LocalizedException(Strings.ErrorLinkOpOnDehydratedTenant("RetentionPolicy")), ExchangeErrorCategory.Client, 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())));
         this.retentionPolicyId = (ADObjectId)retentionPolicy.Identity;
     }
     TaskLogger.LogExit();
 }
        private IConfigurationSession CreateConfigurationSession(MailboxSession mailboxSession)
        {
            OrganizationId        organizationId = mailboxSession.MailboxOwner.MailboxInfo.OrganizationId;
            IConfigurationSession configurationSession;

            if (SharedConfiguration.IsDehydratedConfiguration(organizationId))
            {
                configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(organizationId);
                configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(true, ConsistencyMode.IgnoreInvalid, configurationSession.SessionSettings, 742, "CreateConfigurationSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxFolder\\GetMailboxFolderStatistics.cs");
            }
            else
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, organizationId, base.ExecutingUserOrganizationId, false);
                configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, true, ConsistencyMode.PartiallyConsistent, sessionSettings, 755, "CreateConfigurationSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxFolder\\GetMailboxFolderStatistics.cs");
            }
            return(configurationSession);
        }
Example #8
0
        protected override IConfigDataProvider CreateSession()
        {
            if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
            {
                return(SharedConfiguration.CreateScopedToSharedConfigADSession(base.CurrentOrganizationId));
            }
            IConfigurationSession result;

            if (!MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
            {
                result = (IConfigurationSession)base.CreateSession();
            }
            else
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);
                result = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, sessionSettings, 597, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Elc\\SetRetentionPolicyTag.cs");
            }
            return(result);
        }
        protected override IConfigDataProvider CreateSession()
        {
            IConfigurationSession configurationSession;

            if (!this.IgnoreDehydratedFlag && SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
            {
                configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(base.CurrentOrganizationId);
                return(DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, configurationSession.SessionSettings, 527, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxPolicies\\RetentionPolicyTasks.cs"));
            }
            if (!MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
            {
                configurationSession = (IConfigurationSession)base.CreateSession();
            }
            else
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);
                configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, sessionSettings, 546, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxPolicies\\RetentionPolicyTasks.cs");
            }
            return(configurationSession);
        }
        protected override void StampChangesOn(IConfigurable dataObject)
        {
            TaskLogger.LogEnter();
            ADRecipient adrecipient = (ADRecipient)dataObject;

            if (this.ThrottlingPolicy != null)
            {
                if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
                {
                    base.WriteError(new ArgumentException(Strings.ErrorLinkOpOnDehydratedTenant("ThrottlingPolicy")), ErrorCategory.InvalidArgument, (this.DataObject != null) ? this.DataObject.Identity : null);
                }
                ThrottlingPolicy throttlingPolicy = (ThrottlingPolicy)base.GetDataObject <ThrottlingPolicy>(this.ThrottlingPolicy, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorThrottlingPolicyNotFound(this.ThrottlingPolicy.ToString())), new LocalizedString?(Strings.ErrorThrottlingPolicyNotUnique(this.ThrottlingPolicy.ToString())));
                adrecipient.ThrottlingPolicy = (ADObjectId)throttlingPolicy.Identity;
            }
            else
            {
                adrecipient.ThrottlingPolicy = null;
            }
            base.StampChangesOn(adrecipient);
            TaskLogger.LogExit();
        }
Example #11
0
        private IList <TeamMailboxProvisioningPolicy> GetTeamMailboxPolicies()
        {
            OrganizationId        currentOrganizationId = base.CurrentOrganizationId;
            IConfigurationSession session = this.ConfigurationSession;

            if (SharedConfiguration.IsDehydratedConfiguration(currentOrganizationId) || (SharedConfiguration.GetSharedConfigurationState(currentOrganizationId) & SharedTenantConfigurationState.Static) != SharedTenantConfigurationState.UnSupported)
            {
                ADSessionSettings   adsessionSettings   = null;
                SharedConfiguration sharedConfiguration = SharedConfiguration.GetSharedConfiguration(currentOrganizationId);
                if (sharedConfiguration != null)
                {
                    adsessionSettings = sharedConfiguration.GetSharedConfigurationSessionSettings();
                }
                if (adsessionSettings == null)
                {
                    adsessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, currentOrganizationId, base.ExecutingUserOrganizationId, false);
                    adsessionSettings.IsSharedConfigChecked = true;
                }
                session = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, true, ConsistencyMode.PartiallyConsistent, base.NetCredential, adsessionSettings, 732, "GetTeamMailboxPolicies", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\TeamMailbox\\NewSiteMailbox.cs");
            }
            return(DefaultTeamMailboxProvisioningPolicyUtility.GetDefaultPolicies(session));
        }
Example #12
0
        internal static void LoadTagsInOrg(OrganizationId orgId, Dictionary <Guid, AdTagData> allTags)
        {
            IConfigurationSession configurationSession;

            if (SharedConfiguration.IsDehydratedConfiguration(orgId))
            {
                configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(orgId);
            }
            else
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(orgId);
                configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.PartiallyConsistent, sessionSettings, 375, "LoadTagsInOrg", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\ELC\\AdTagReader.cs");
            }
            ADPagedReader <RetentionPolicyTag> allAdTags = configurationSession.FindPaged <RetentionPolicyTag>(null, QueryScope.SubTree, null, null, 0);

            AdReader.Tracer.TraceDebug(0L, "Found Policy Tags in the AD.");
            List <RetentionPolicyTag> theGoodTags = AdTagReader.GetTheGoodTags(allAdTags);

            foreach (RetentionPolicyTag retentionPolicyTag in theGoodTags)
            {
                AdTagData value = AdTagReader.FetchTagContentSettings(retentionPolicyTag);
                allTags[retentionPolicyTag.RetentionId] = value;
            }
        }
Example #13
0
 protected override void InternalBeginProcessing()
 {
     TaskLogger.LogEnter();
     base.InternalBeginProcessing();
     if (this.SharedTenantConfigurationMode == SharedTenantConfigurationMode.Static || (this.SharedTenantConfigurationMode == SharedTenantConfigurationMode.Dehydrateable && SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId)))
     {
         this.sharedConfig = SharedConfiguration.GetSharedConfiguration(base.CurrentOrganizationId);
     }
     TaskLogger.LogExit();
 }
        protected override IConfigurable PrepareDataObject()
        {
            if (!this.IgnoreDehydratedFlag && SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
            {
                base.WriteError(new ArgumentException(Strings.ErrorWriteOpOnDehydratedTenant), ErrorCategory.InvalidArgument, this.DataObject.Identity);
            }
            RetentionPolicyTag    retentionPolicyTag = (RetentionPolicyTag)base.PrepareDataObject();
            IConfigurationSession session            = base.DataSession as IConfigurationSession;

            retentionPolicyTag.SetId(session, base.Name);
            if (base.ParameterSetName == "UpgradeManagedFolder" && this.ElcFolderToUpgrade != null)
            {
                retentionPolicyTag.LegacyManagedFolder             = this.ElcFolderToUpgrade.Id;
                retentionPolicyTag.LocalizedRetentionPolicyTagName = this.ElcFolderToUpgrade.LocalizedFolderName;
                retentionPolicyTag.Comment                   = this.ElcFolderToUpgrade.Comment;
                retentionPolicyTag.LocalizedComment          = this.ElcFolderToUpgrade.LocalizedComment;
                retentionPolicyTag.MustDisplayCommentEnabled = this.ElcFolderToUpgrade.MustDisplayCommentEnabled;
                retentionPolicyTag.Type = this.ElcFolderToUpgrade.FolderType;
            }
            if (base.Fields.Contains("LocalizedRetentionPolicyTagName"))
            {
                retentionPolicyTag.LocalizedRetentionPolicyTagName = this.LocalizedRetentionPolicyTagName;
            }
            if (base.Fields.Contains("Comment"))
            {
                retentionPolicyTag.Comment = this.Comment;
            }
            if (base.Fields.Contains("LocalizedComment"))
            {
                retentionPolicyTag.LocalizedComment = this.LocalizedComment;
            }
            if (base.Fields.Contains("MustDisplayCommentEnabled"))
            {
                retentionPolicyTag.MustDisplayCommentEnabled = this.MustDisplayCommentEnabled;
            }
            if (base.Fields.Contains("Type"))
            {
                retentionPolicyTag.Type = this.Type;
            }
            if (base.Fields.Contains("RetentionId"))
            {
                retentionPolicyTag.RetentionId = this.RetentionId;
            }
            if (retentionPolicyTag.Type == ElcFolderType.ManagedCustomFolder)
            {
                retentionPolicyTag.Type = ElcFolderType.Personal;
            }
            retentionPolicyTag.SystemTag = this.SystemTag;
            if (NewRetentionPolicyTag.MessageClassNameMaps.ContainsKey(this.contentSettingsObject.MessageClass))
            {
                this.contentSettingsObject.MessageClass = NewRetentionPolicyTag.MessageClassNameMaps[this.contentSettingsObject.MessageClass];
            }
            if (!NewRetentionPolicyTag.MessageClassNameMaps.Values.Contains(this.contentSettingsObject.MessageClass, StringComparer.OrdinalIgnoreCase))
            {
                base.WriteError(new RetentionPolicyTagTaskException(Strings.MessageClassIsNotValid(this.contentSettingsObject.MessageClass)), ErrorCategory.InvalidArgument, null);
            }
            string text = base.Name;

            if (text.Length > 60)
            {
                text = text.Substring(0, 60);
            }
            text += "_cs";
            this.contentSettingsObject.SetId(retentionPolicyTag.Id.GetChildId(text));
            if (base.ParameterSetName != "UpgradeManagedFolder")
            {
                this.contentSettingsObject.RetentionEnabled = this.RetentionEnabled;
            }
            if (this.JournalingEnabled && this.AddressForJournaling != null)
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, base.OrganizationId.ToADSessionSettings(), 481, "PrepareDataObject", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Elc\\NewRetentionPolicyTag.cs");
                ADRecipient       adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(this.AddressForJournaling, tenantOrRootOrgRecipientSession, null, new LocalizedString?(Strings.ErrorMailboxAddressNotFound(this.AddressForJournaling.ToString())), new LocalizedString?(Strings.ErrorMailboxAddressNotUnique(this.AddressForJournaling.ToString())));
                if (adrecipient.EmailAddresses == null || adrecipient.EmailAddresses.FindPrimary(ProxyAddressPrefix.Smtp) == null)
                {
                    base.WriteError(new ArgumentException(Strings.SmtpAddressMissingForAutocopy(this.AddressForJournaling.ToString()), "AddressForJournaling"), ErrorCategory.InvalidData, this);
                }
                this.contentSettingsObject.AddressForJournaling = adrecipient.Id;
            }
            if (this.DataObject.Type != ElcFolderType.All && this.DataObject.Type != ElcFolderType.Personal && this.DataObject.Type != ElcFolderType.RecoverableItems && this.RetentionAction == RetentionActionType.MoveToArchive)
            {
                base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorMoveToArchiveAppliedToSystemFolder), ErrorCategory.InvalidArgument, null);
            }
            return(retentionPolicyTag);
        }
Example #15
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;
			}
		}
Example #16
0
 protected override void InternalValidate()
 {
     base.InternalValidate();
     if (base.HasErrors)
     {
         return;
     }
     if (Datacenter.IsMicrosoftHostedOnly(false))
     {
         List <RetentionPolicy> allRetentionPolicies = AdPolicyReader.GetAllRetentionPolicies(this.ConfigurationSession, base.OrganizationId);
         if (allRetentionPolicies.Count >= 100)
         {
             base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorTenantRetentionPolicyLimitReached(100)), ErrorCategory.InvalidOperation, this.DataObject);
         }
     }
     if (this.IsDefault && this.IsDefaultArbitrationMailbox)
     {
         base.WriteError(new ArgumentException(Strings.ErrorMultipleDefaultRetentionPolicy), ErrorCategory.InvalidArgument, this.DataObject.Identity);
     }
     if (!this.IgnoreDehydratedFlag && SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
     {
         base.WriteError(new ArgumentException(Strings.ErrorWriteOpOnDehydratedTenant), ErrorCategory.InvalidArgument, this.DataObject.Identity);
     }
     if (this.IsDefault && this.IsDefaultArbitrationMailbox)
     {
         base.WriteError(new ArgumentException(Strings.ErrorMultipleDefaultRetentionPolicy), ErrorCategory.InvalidArgument, this.DataObject.Identity);
     }
     if (this.IsDefault)
     {
         this.DataObject.IsDefault    = true;
         this.existingDefaultPolicies = RetentionPolicyUtility.GetDefaultPolicies((IConfigurationSession)base.DataSession, false);
     }
     else if (this.IsDefaultArbitrationMailbox)
     {
         this.DataObject.IsDefaultArbitrationMailbox = true;
         this.existingDefaultPolicies = RetentionPolicyUtility.GetDefaultPolicies((IConfigurationSession)base.DataSession, true);
     }
     if (this.existingDefaultPolicies != null && this.existingDefaultPolicies.Count > 0)
     {
         this.updateExistingDefaultPolicies = true;
     }
     if (this.RetentionPolicyTagLinks != null)
     {
         this.DataObject.RetentionPolicyTagLinks.Clear();
         PresentationRetentionPolicyTag[] array = (from x in (from x in this.RetentionPolicyTagLinks
                                                              select(RetentionPolicyTag) base.GetDataObject <RetentionPolicyTag>(x, base.DataSession, null, new LocalizedString?(Strings.ErrorRetentionTagNotFound(x.ToString())), new LocalizedString?(Strings.ErrorAmbiguousRetentionPolicyTagId(x.ToString())))).Distinct(new ADObjectComparer <RetentionPolicyTag>())
                                                   select new PresentationRetentionPolicyTag(x)).ToArray <PresentationRetentionPolicyTag>();
         RetentionPolicyValidator.ValicateDefaultTags(this.DataObject, array, new Task.TaskErrorLoggingDelegate(base.WriteError));
         RetentionPolicyValidator.ValidateSystemFolderTags(this.DataObject, array, new Task.TaskErrorLoggingDelegate(base.WriteError));
         array.ForEach(delegate(PresentationRetentionPolicyTag x)
         {
             this.DataObject.RetentionPolicyTagLinks.Add(x.Id);
         });
     }
     if (base.Fields.Contains("RetentionId"))
     {
         this.DataObject.RetentionId = this.RetentionId;
         string policyName;
         if (!(base.DataSession as IConfigurationSession).CheckForRetentionPolicyWithConflictingRetentionId(this.DataObject.RetentionId, out policyName))
         {
             base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorRetentionIdConflictsWithRetentionPolicy(this.DataObject.RetentionId.ToString(), policyName)), ErrorCategory.InvalidOperation, this.DataObject);
         }
     }
 }
Example #17
0
        protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
        {
            ReducedRecipient reducedRecipient = (ReducedRecipient)dataObject;

            if (reducedRecipient == null)
            {
                return(null);
            }
            if (this.ShouldReadProperties(new ADPropertyDefinition[]
            {
                ReducedRecipientSchema.OwaMailboxPolicy,
                ReducedRecipientSchema.SharingPolicy,
                ReducedRecipientSchema.RetentionPolicy
            }) && reducedRecipient.RecipientType == Microsoft.Exchange.Data.Directory.Recipient.RecipientType.UserMailbox)
            {
                SharedConfiguration sharedConfig = null;
                if (SharedConfiguration.IsDehydratedConfiguration(reducedRecipient.OrganizationId) || (SharedConfiguration.GetSharedConfigurationState(reducedRecipient.OrganizationId) & SharedTenantConfigurationState.Static) != SharedTenantConfigurationState.UnSupported)
                {
                    sharedConfig = SharedConfiguration.GetSharedConfiguration(reducedRecipient.OrganizationId);
                }
                if (this.ShouldReadProperties(new ADPropertyDefinition[]
                {
                    ReducedRecipientSchema.OwaMailboxPolicy
                }) && reducedRecipient.OwaMailboxPolicy == null)
                {
                    ADObjectId defaultOwaMailboxPolicyId = this.GetDefaultOwaMailboxPolicyId(reducedRecipient);
                    if (defaultOwaMailboxPolicyId != null)
                    {
                        reducedRecipient.OwaMailboxPolicy = defaultOwaMailboxPolicyId;
                    }
                }
                if (this.ShouldReadProperties(new ADPropertyDefinition[]
                {
                    ReducedRecipientSchema.SharingPolicy
                }) && reducedRecipient.SharingPolicy == null)
                {
                    reducedRecipient.SharingPolicy = base.GetDefaultSharingPolicyId(reducedRecipient, sharedConfig);
                }
                if (this.ShouldReadProperties(new ADPropertyDefinition[]
                {
                    ReducedRecipientSchema.RetentionPolicy
                }) && reducedRecipient.RetentionPolicy == null && reducedRecipient.ShouldUseDefaultRetentionPolicy)
                {
                    reducedRecipient.RetentionPolicy = base.GetDefaultRetentionPolicyId(reducedRecipient, sharedConfig);
                }
            }
            if (this.ShouldReadProperties(new ADPropertyDefinition[]
            {
                ReducedRecipientSchema.ActiveSyncMailboxPolicy,
                ReducedRecipientSchema.ActiveSyncMailboxPolicyIsDefaulted
            }) && reducedRecipient.ActiveSyncMailboxPolicy == null && !reducedRecipient.ExchangeVersion.IsOlderThan(ReducedRecipientSchema.ActiveSyncMailboxPolicy.VersionAdded))
            {
                ADObjectId defaultPolicyId = base.GetDefaultPolicyId(reducedRecipient);
                if (defaultPolicyId != null)
                {
                    reducedRecipient.ActiveSyncMailboxPolicy            = defaultPolicyId;
                    reducedRecipient.ActiveSyncMailboxPolicyIsDefaulted = true;
                }
            }
            if (this.ShouldReadProperties(new ADPropertyDefinition[]
            {
                ReducedRecipientSchema.AuthenticationType
            }) && reducedRecipient.OrganizationId.ConfigurationUnit != null)
            {
                SmtpAddress windowsLiveID = reducedRecipient.WindowsLiveID;
                if (reducedRecipient.WindowsLiveID.Domain != null && !reducedRecipient.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2010))
                {
                    reducedRecipient.AuthenticationType = MailboxTaskHelper.GetNamespaceAuthenticationType(reducedRecipient.OrganizationId, reducedRecipient.WindowsLiveID.Domain);
                }
            }
            if (this.ShouldReadProperties(new ADPropertyDefinition[]
            {
                ReducedRecipientSchema.Capabilities
            }))
            {
                reducedRecipient.PopulateCapabilitiesProperty();
            }
            return(reducedRecipient);
        }
Example #18
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            if ("Linked" == base.ParameterSetName)
            {
                try
                {
                    NetworkCredential userForestCredential = (this.LinkedCredential == null) ? null : this.LinkedCredential.GetNetworkCredential();
                    this.linkedUserSid = MailboxTaskHelper.GetAccountSidFromAnotherForest(this.LinkedMasterAccount, this.LinkedDomainController, userForestCredential, this.ResourceForestSession, new MailboxTaskHelper.GetUniqueObject(base.GetDataObject <ADUser>), new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                }
                catch (PSArgumentException exception)
                {
                    base.ThrowTerminatingError(exception, ErrorCategory.InvalidArgument, this.LinkedCredential);
                }
            }
            if (this.ManagedFolderMailboxPolicy != null)
            {
                ManagedFolderMailboxPolicy managedFolderMailboxPolicy = (ManagedFolderMailboxPolicy)base.GetDataObject <ManagedFolderMailboxPolicy>(this.ManagedFolderMailboxPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorManagedFolderMailboxPolicyNotFound(this.ManagedFolderMailboxPolicy.ToString())), new LocalizedString?(Strings.ErrorManagedFolderMailboxPolicyNotUnique(this.ManagedFolderMailboxPolicy.ToString())));
                this.elcPolicyId = (ADObjectId)managedFolderMailboxPolicy.Identity;
            }
            if (this.RetentionPolicy != null)
            {
                if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
                {
                    base.WriteError(new LocalizedException(Strings.ErrorLinkOpOnDehydratedTenant("RetentionPolicy")), ExchangeErrorCategory.Client, null);
                }
                RetentionPolicy retentionPolicy = (RetentionPolicy)base.GetDataObject <RetentionPolicy>(this.RetentionPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorRetentionPolicyNotFound(this.RetentionPolicy.ToString())), new LocalizedString?(Strings.ErrorRetentionPolicyNotUnique(this.RetentionPolicy.ToString())));
                this.retentionPolicyId = retentionPolicy.Id;
            }
            if (this.ActiveSyncMailboxPolicy != null)
            {
                MobileMailboxPolicy mobileMailboxPolicy = (MobileMailboxPolicy)base.GetDataObject <MobileMailboxPolicy>(this.ActiveSyncMailboxPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorMobileMailboxPolicyNotFound(this.ActiveSyncMailboxPolicy.ToString())), new LocalizedString?(Strings.ErrorMobileMailboxPolicyNotUnique(this.ActiveSyncMailboxPolicy.ToString())));
                this.mobilePolicyId = (ADObjectId)mobileMailboxPolicy.Identity;
            }
            if (this.AddressBookPolicy != null)
            {
                AddressBookMailboxPolicy addressBookMailboxPolicy = (AddressBookMailboxPolicy)base.GetDataObject <AddressBookMailboxPolicy>(this.AddressBookPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotFound(this.AddressBookPolicy.ToString())), new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotUnique(this.AddressBookPolicy.ToString())), ExchangeErrorCategory.Client);
                this.addressBookPolicyId = (ADObjectId)addressBookMailboxPolicy.Identity;
            }
            MailboxTaskHelper.ValidateMailboxIsDisconnected(this.GlobalCatalogSession, this.DataObject.MailboxGuid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
            if (!this.Archive)
            {
                ConnectMailbox.CheckLegacyDNNotInUse(this.DataObject.Identity, this.DataObject.LegacyDN, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            if (this.User != null)
            {
                this.userToConnect = (ADUser)base.GetDataObject <ADUser>(this.User, this.RecipientSession, null, new LocalizedString?(Strings.ErrorRecipientNotFound(this.User.ToString())), new LocalizedString?(Strings.ErrorRecipientNotUnique(this.User.ToString())));
                if (this.Archive)
                {
                    ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
                }
                else if (RecipientType.User != this.userToConnect.RecipientType)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorNoMatchedUserTypeFound(RecipientType.User.ToString(), this.User.ToString(), this.userToConnect.RecipientType.ToString())), ErrorCategory.InvalidArgument, this.User);
                }
            }
            else if (!this.Archive)
            {
                if ("ValidateOnly" == base.ParameterSetName)
                {
                    this.matchedUsers = this.FindMatchedUser(this.DataObject, null);
                }
                else
                {
                    this.matchedUsers = this.FindMatchedUser(this.DataObject, new bool?("User" == base.ParameterSetName));
                }
                if ("ValidateOnly" != base.ParameterSetName)
                {
                    if (this.matchedUsers.Length == 0)
                    {
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorNoMatchedUserFound), ErrorCategory.InvalidArgument, this.Identity);
                    }
                    else if (this.matchedUsers.Length > 1)
                    {
                        this.WriteWarning(Strings.ErrorMultipleMatchedUser(this.Identity.ToString()));
                        this.needListMatchingUser = true;
                    }
                    else
                    {
                        this.userToConnect = (ADUser)this.matchedUsers[0];
                        this.userToConnect = (ADUser)this.RecipientSession.Read(this.userToConnect.Id);
                        if (this.userToConnect == null)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorNoMatchedUserFound), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        if (this.Archive)
                        {
                            ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
                        }
                    }
                }
            }
            else
            {
                this.userToConnect = this.FindArchiveUser(this.DataObject, this.RecipientSession, new Task.TaskErrorLoggingDelegate(base.WriteError));
                ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
            }
            if (this.userToConnect != null && !this.Archive)
            {
                if ("User" == base.ParameterSetName)
                {
                    if ((this.userToConnect.UserAccountControl & UserAccountControlFlags.AccountDisabled) != UserAccountControlFlags.None && this.DataObject.MailboxType == StoreMailboxType.Private)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorAccountDisabledForUserMailbox), ErrorCategory.InvalidArgument, this.userToConnect);
                    }
                }
                else if ((this.userToConnect.UserAccountControl & UserAccountControlFlags.AccountDisabled) == UserAccountControlFlags.None)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorAccountEnabledForNonUserMailbox), ErrorCategory.InvalidArgument, this.userToConnect);
                }
                if (!string.IsNullOrEmpty(this.Alias))
                {
                    this.alias = this.Alias;
                }
                else
                {
                    this.alias = RecipientTaskHelper.GenerateUniqueAlias(this.globalCatalogSession, this.userToConnect.OrganizationId, this.userToConnect.Name, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                }
            }
            if (this.Archive && this.userToConnect.ManagedFolderMailboxPolicy != null)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorNoArchiveWithManagedFolder(this.userToConnect.Name)), ErrorCategory.InvalidData, this.Identity);
            }
            if (this.DataObject.IsArchiveMailbox != null && this.Archive != this.DataObject.IsArchiveMailbox.Value)
            {
                if (this.Archive)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorDisconnectedMailboxNotArchive(this.Identity.ToString(), this.userToConnect.Name)), ErrorCategory.InvalidArgument, this.Identity);
                }
                else
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorDisconnectedMailboxNotPrimary(this.Identity.ToString(), this.userToConnect.Name)), ErrorCategory.InvalidArgument, this.Identity);
                }
            }
            ADSessionSettings sessionSettings = ADSessionSettings.FromCustomScopeSet(base.ScopeSet, ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);

            MapiTaskHelper.VerifyDatabaseIsWithinScope(sessionSettings, this.OwnerMailboxDatabase, new Task.ErrorLoggerDelegate(base.WriteError));
            TaskLogger.LogExit();
        }
Example #19
0
        internal static Dictionary <Guid, AdTagData> GetTagsInPolicy(MailboxSession session, ADUser aduser, Dictionary <Guid, AdTagData> allAdTags)
        {
            if (allAdTags == null || allAdTags.Count == 0 || aduser == null)
            {
                return(null);
            }
            string     arg        = session.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString();
            ADObjectId adobjectId = aduser.RetentionPolicy;

            if (adobjectId == null && aduser.ShouldUseDefaultRetentionPolicy && aduser.OrganizationId != null && !OrganizationId.ForestWideOrgId.Equals(aduser.OrganizationId))
            {
                IConfigurationSession scopedSession;
                if (SharedConfiguration.IsDehydratedConfiguration(aduser.OrganizationId))
                {
                    scopedSession = SharedConfiguration.CreateScopedToSharedConfigADSession(aduser.OrganizationId);
                }
                else
                {
                    scopedSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.FullyConsistent, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(aduser.OrganizationId), 149, "GetTagsInPolicy", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\ELC\\AdTagReader.cs");
                }
                IList <RetentionPolicy> defaultRetentionPolicy = SharedConfiguration.GetDefaultRetentionPolicy(scopedSession, aduser, null, 1);
                if (defaultRetentionPolicy != null && defaultRetentionPolicy.Count > 0)
                {
                    adobjectId = defaultRetentionPolicy[0].Id;
                }
            }
            if (adobjectId == null)
            {
                AdReader.Tracer.TraceDebug <string>(0L, "Mailbox '{0}' does not have an ELC Mailbox policy.", arg);
                return(null);
            }
            IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.FullyConsistent, ADSessionSettings.FromAllTenantsOrRootOrgAutoDetect(adobjectId), 175, "GetTagsInPolicy", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\ELC\\AdTagReader.cs");
            RetentionPolicy       retentionPolicy = tenantOrTopologyConfigurationSession.Read <RetentionPolicy>(adobjectId);

            if (retentionPolicy == null)
            {
                AdReader.Tracer.TraceDebug <string, ADObjectId>(0L, "Mailbox '{0}' no matching ELC Mailbox policy for Template '{1}'.", arg, adobjectId);
                return(null);
            }
            MultiValuedProperty <ADObjectId> retentionPolicyTagLinks = retentionPolicy.RetentionPolicyTagLinks;
            Dictionary <Guid, AdTagData>     dictionary = new Dictionary <Guid, AdTagData>();
            List <AdTagData> list  = new List <AdTagData>();
            List <AdTagData> list2 = new List <AdTagData>();
            int num = 0;
            Dictionary <Guid, AdTagData> dictionary2 = new Dictionary <Guid, AdTagData>();

            foreach (Guid key in allAdTags.Keys)
            {
                AdTagData adTagData = allAdTags[key];
                dictionary2[adTagData.Tag.Guid] = adTagData;
            }
            foreach (ADObjectId adobjectId2 in retentionPolicyTagLinks)
            {
                if (!dictionary2.ContainsKey(adobjectId2.ObjectGuid))
                {
                    AdReader.Tracer.TraceDebug <string, string>(0L, "Mailbox '{0}' has link '{1}' in policy to a tag that could not be found in the AD. Skipping user.", arg, adobjectId2.DistinguishedName);
                    throw new IWTransientException(Strings.descTagNotInAD(adobjectId2.DistinguishedName));
                }
                AdTagData adTagData2 = dictionary2[adobjectId2.ObjectGuid];
                if (adTagData2.Tag.Type == ElcFolderType.All)
                {
                    if (ElcMailboxHelper.IsArchiveTag(adTagData2, false))
                    {
                        AdReader.Tracer.TraceDebug <string, string>(0L, "Mailbox '{0}'. Tag {1} is a default archive tag.", arg, adTagData2.Tag.Name);
                        list2.Add(adTagData2);
                    }
                    else if (adTagData2.Tag.IsPrimary)
                    {
                        AdReader.Tracer.TraceDebug <string, string>(0L, "Mailbox '{0}'. Tag {1} is the primary default retention tag.", arg, adTagData2.Tag.Name);
                        list.Insert(0, adTagData2);
                        num++;
                    }
                    else
                    {
                        AdReader.Tracer.TraceDebug <string, string>(0L, "Mailbox '{0}'. Tag {1} is a default retention tag.", arg, adTagData2.Tag.Name);
                        list.Add(adTagData2);
                    }
                }
                else
                {
                    dictionary[adobjectId2.ObjectGuid] = dictionary2[adobjectId2.ObjectGuid];
                }
            }
            if (list2.Count > 0)
            {
                AdReader.Tracer.TraceDebug <string, string, int>(0L, "Mailbox '{0}' with policy '{1}' has {2} default MTA tags.", arg, retentionPolicy.Id.DistinguishedName, list2.Count);
                list2.Sort(delegate(AdTagData x, AdTagData y)
                {
                    if (x.ContentSettings.Count != 1)
                    {
                        return(1);
                    }
                    if (y.ContentSettings.Count != 1)
                    {
                        return(-1);
                    }
                    return(x.ContentSettings.Single <KeyValuePair <Guid, ContentSetting> >().Value.MessageClass.Length - y.ContentSettings.Single <KeyValuePair <Guid, ContentSetting> >().Value.MessageClass.Length);
                });
                AdTagData firstArchiveTag = new AdTagData();
                firstArchiveTag.Tag             = list2[0].Tag;
                firstArchiveTag.ContentSettings = new SortedDictionary <Guid, ContentSetting>();
                list2.SelectMany((AdTagData x) => x.ContentSettings.Values).ForEach(delegate(ContentSetting x)
                {
                    firstArchiveTag.ContentSettings[x.Guid] = x;
                });
                dictionary[firstArchiveTag.Tag.Guid] = firstArchiveTag;
            }
            if (list.Count > 0)
            {
                if (num > 1)
                {
                    AdReader.Tracer.TraceDebug <string, string>(0L, "Mailbox '{0}' has policy '{1}' with corrupted default tags (Primary default should be 1). Skipping user.", arg, retentionPolicy.Id.DistinguishedName);
                    throw new IWPermanentException(Strings.descPrimaryDefaultCorrupted(retentionPolicy.Id.DistinguishedName, num));
                }
                if (num == 0 && list.Count > 1)
                {
                    list.Sort(delegate(AdTagData x, AdTagData y)
                    {
                        if (x.ContentSettings.Count != 1)
                        {
                            return(1);
                        }
                        if (y.ContentSettings.Count != 1)
                        {
                            return(-1);
                        }
                        return(x.ContentSettings.Single <KeyValuePair <Guid, ContentSetting> >().Value.MessageClass.Length - y.ContentSettings.Single <KeyValuePair <Guid, ContentSetting> >().Value.MessageClass.Length);
                    });
                }
                for (int i = 0; i < list.Count; i++)
                {
                    Guid guid = list[i].Tag.Guid;
                    dictionary[guid] = list[i];
                }
            }
            return(dictionary);
        }