Ejemplo n.º 1
0
        internal ADObjectId GetDefaultRetentionPolicyId(ADObject user, SharedConfiguration sharedConfig)
        {
            if (OrganizationId.ForestWideOrgId.Equals(user.OrganizationId))
            {
                return(null);
            }
            bool flag = false;

            if (user[OrgPersonPresentationObjectSchema.RecipientTypeDetails] != null && (RecipientTypeDetails)user[OrgPersonPresentationObjectSchema.RecipientTypeDetails] == RecipientTypeDetails.ArbitrationMailbox)
            {
                flag = true;
            }
            OrganizationId organizationId = user.OrganizationId;
            ADObjectId     adobjectId     = null;

            if (!flag)
            {
                if (this.defaultRetentionPolicyIds.TryGetValue(organizationId, out adobjectId))
                {
                    return(adobjectId);
                }
            }
            try
            {
                IConfigurationSession   scopedSession          = this.GenerateIConfigurationSessionForShareableObjects(organizationId, sharedConfig);
                IList <RetentionPolicy> defaultRetentionPolicy = SharedConfiguration.GetDefaultRetentionPolicy(scopedSession, flag, null, 1);
                if (defaultRetentionPolicy != null && defaultRetentionPolicy.Count > 0)
                {
                    adobjectId = defaultRetentionPolicy[0].Id;
                }
                else
                {
                    adobjectId = null;
                }
                if (!flag)
                {
                    this.defaultRetentionPolicyIds.Add(organizationId, adobjectId);
                }
            }
            catch (DataSourceTransientException exception)
            {
                base.WriteError(exception, ErrorCategory.ReadError, null);
                return(null);
            }
            return(adobjectId);
        }
Ejemplo n.º 2
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);
        }
 public static IList <RetentionPolicy> GetDefaultPolicies(IConfigurationSession session, bool isArbitrationMailbox)
 {
     return(SharedConfiguration.GetDefaultRetentionPolicy(session, isArbitrationMailbox, RetentionPolicyUtility.sortBy, int.MaxValue));
 }