Ejemplo n.º 1
0
        internal static List <Tuple <string, KeyType> > GetAddKeysFromObject(ADObject adObject)
        {
            ArgumentValidator.ThrowIfNull("adObject", adObject);
            ObjectType objectTypeFor             = CacheUtils.GetObjectTypeFor(adObject.GetType(), true);
            List <Tuple <string, KeyType> > list = new List <Tuple <string, KeyType> >();

            if (!string.IsNullOrEmpty(adObject.DistinguishedName))
            {
                list.Add(new Tuple <string, KeyType>(adObject.DistinguishedName.ToLower(), KeyType.DistinguishedName));
            }
            if (!Guid.Empty.Equals(adObject.Guid))
            {
                list.Add(new Tuple <string, KeyType>(adObject.Guid.ToString(), KeyType.Guid));
            }
            ObjectType objectType = objectTypeFor;

            if (objectType <= ObjectType.OWAMiniRecipient)
            {
                if (objectType <= ObjectType.FederatedOrganizationId)
                {
                    switch (objectType)
                    {
                    case ObjectType.ExchangeConfigurationUnit:
                        list.Add(new Tuple <string, KeyType>(adObject.Id.Parent.Name, KeyType.Name));
                        list.Add(new Tuple <string, KeyType>(((ExchangeConfigurationUnit)adObject).ExternalDirectoryOrganizationId, KeyType.ExternalDirectoryOrganizationId));
                        return(list);

                    case ObjectType.Recipient:
                    {
                        list.AddRange(KeyBuilder.GetSidKeys(adObject));
                        list.AddRange(KeyBuilder.GetExchangeGuidKeys(adObject));
                        string text = (string)adObject[ADRecipientSchema.LegacyExchangeDN];
                        if (!string.IsNullOrEmpty(text))
                        {
                            list.Add(new Tuple <string, KeyType>(text, KeyType.LegacyExchangeDN));
                        }
                        list.AddRange(KeyBuilder.GetExchangeEmailAddressesKeys(adObject));
                        return(list);
                    }

                    case ObjectType.ExchangeConfigurationUnit | ObjectType.Recipient:
                        return(list);

                    case ObjectType.AcceptedDomain:
                        list.Add(new Tuple <string, KeyType>(adObject.Name, KeyType.Name));
                        return(list);

                    default:
                        if (objectType != ObjectType.FederatedOrganizationId)
                        {
                            return(list);
                        }
                        list.Add(new Tuple <string, KeyType>(adObject.Id.Parent.DistinguishedName, KeyType.OrgCUDN));
                        return(list);
                    }
                }
                else
                {
                    if (objectType == ObjectType.MiniRecipient)
                    {
                        if ((adObject as MiniRecipient).NetID != null)
                        {
                            list.Add(KeyBuilder.LookupKeysFromNetId((adObject as MiniRecipient).NetID.ToString()));
                        }
                        ProxyAddressCollection proxyAddressCollection = (ProxyAddressCollection)adObject[ADRecipientSchema.EmailAddresses];
                        if (proxyAddressCollection != null)
                        {
                            foreach (ProxyAddress proxyAddress in proxyAddressCollection)
                            {
                                list.AddRange(KeyBuilder.LookupKeysFromProxyAddress(proxyAddress));
                            }
                        }
                        list.AddRange(KeyBuilder.GetSidKeys(adObject));
                        return(list);
                    }
                    if (objectType != ObjectType.TransportMiniRecipient && objectType != ObjectType.OWAMiniRecipient)
                    {
                        return(list);
                    }
                }
            }
            else if (objectType <= ObjectType.StorageMiniRecipient)
            {
                if (objectType != ObjectType.ActiveSyncMiniRecipient && objectType != ObjectType.StorageMiniRecipient)
                {
                    return(list);
                }
            }
            else if (objectType != ObjectType.LoadBalancingMiniRecipient)
            {
                if (objectType == ObjectType.MiniRecipientWithTokenGroups)
                {
                    list.AddRange(KeyBuilder.GetSidKeys(adObject));
                    return(list);
                }
                if (objectType != ObjectType.FrontEndMiniRecipient)
                {
                    return(list);
                }
                list.AddRange(KeyBuilder.GetExchangeGuidKeys(adObject));
                return(list);
            }
            ProxyAddressCollection proxyAddressCollection2 = (ProxyAddressCollection)adObject[ADRecipientSchema.EmailAddresses];

            if (proxyAddressCollection2 != null)
            {
                foreach (ProxyAddress proxyAddress2 in proxyAddressCollection2)
                {
                    list.AddRange(KeyBuilder.LookupKeysFromProxyAddress(proxyAddress2));
                }
            }
            list.AddRange(KeyBuilder.GetSidKeys(adObject));
            return(list);
        }