private void DoAdCallAndTranslateExceptions(Action call, string methodName)
 {
     try
     {
         call();
     }
     catch (DataValidationException innerException)
     {
         throw new ObjectNotFoundException(ServerStrings.ADUserNotFound, innerException);
     }
     catch (DataSourceOperationException ex)
     {
         throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "{0}. Failed due to directory exception {1}.", new object[]
         {
             methodName,
             ex
         });
     }
     catch (DataSourceTransientException ex2)
     {
         throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "{0}. Failed due to directory exception {1}.", new object[]
         {
             methodName,
             ex2
         });
     }
 }
示例#2
0
        internal static TResult ProtectedADCall <TResult>(Func <TResult> activeDirectoryCall)
        {
            TResult result;

            try
            {
                result = activeDirectoryCall();
            }
            catch (DataSourceOperationException ex)
            {
                throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "StorageGlobals::{0} failed due to directory exception {1}.", new object[]
                {
                    activeDirectoryCall,
                    ex
                });
            }
            catch (DataSourceTransientException ex2)
            {
                throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "StorageGlobals::{0} failed due to directory exception {1}.", new object[]
                {
                    activeDirectoryCall,
                    ex2
                });
            }
            catch (DataValidationException ex3)
            {
                throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex3, null, "StorageGlobals::{0} failed due to directory exception {1}.", new object[]
                {
                    activeDirectoryCall,
                    ex3
                });
            }
            return(result);
        }
示例#3
0
        public static T GetWithDirectoryExceptionTranslation <T>(Func <T> getter)
        {
            T result;

            try
            {
                result = getter();
            }
            catch (DataValidationException innerException)
            {
                throw new ObjectNotFoundException(ServerStrings.ADUserNotFound, innerException);
            }
            catch (DataSourceOperationException ex)
            {
                throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "{0}. Failed due to directory exception {1}.", new object[]
                {
                    ex
                });
            }
            catch (DataSourceTransientException ex2)
            {
                throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "{0}. Failed due to directory exception {1}.", new object[]
                {
                    ex2
                });
            }
            return(result);
        }
示例#4
0
 private static object[][] LookupInAD(Func <IRecipientSession> adRecipientSessionFactory, List <string> legacyDNs, params PropertyDefinition[] properties)
 {
     object[][] result;
     try
     {
         Result <ADRawEntry>[] array = adRecipientSessionFactory().FindByLegacyExchangeDNs(legacyDNs.ToArray(), properties);
         if (array.Length != legacyDNs.Count)
         {
             ExDiagnostics.FailFast(string.Format(CultureInfo.InvariantCulture, "Number of results in IRecipientSession.FindByLegacyExchangeDNs() is unexpected: {0} instead of {1}", new object[]
             {
                 array.Length,
                 legacyDNs.Count
             }), false);
         }
         result = Array.ConvertAll <Result <ADRawEntry>, object[]>(array, delegate(Result <ADRawEntry> entry)
         {
             if (entry.Data == null)
             {
                 return(null);
             }
             return(entry.Data.GetProperties(properties));
         });
     }
     catch (DataSourceOperationException ex)
     {
         throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "DistributionList.LookupInAD. Failed due to directory exception {0}.", new object[]
         {
             ex
         });
     }
     catch (DataSourceTransientException ex2)
     {
         throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "DistributionList.LookupInAD. Failed due to directory exception {0}.", new object[]
         {
             ex2
         });
     }
     return(result);
 }
示例#5
0
 private void UpdateJunkEmailContacts()
 {
     if (this.junkEmailUpdates.Count > 0)
     {
         MailboxSession mailboxSession = base.Session as MailboxSession;
         if (mailboxSession != null && mailboxSession.LogonType != LogonType.Delegated && mailboxSession.Capabilities.CanHaveJunkEmailRule && !mailboxSession.MailboxOwner.ObjectId.IsNullOrEmpty())
         {
             JunkEmailRule junkEmailRule = mailboxSession.JunkEmailRule;
             if (junkEmailRule.IsContactsFolderTrusted)
             {
                 try
                 {
                     junkEmailRule.SynchronizeContactsCache();
                     junkEmailRule.Save();
                 }
                 catch (JunkEmailValidationException)
                 {
                 }
                 catch (DataSourceOperationException ex)
                 {
                     throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, this, "Contact.UpdateJunkEmailContacts. Failed due to directory exception {0}.", new object[]
                     {
                         ex
                     });
                 }
                 catch (DataSourceTransientException ex2)
                 {
                     throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, this, "Contact.UpdateJunkEmailContacts. Failed due to directory exception {0}.", new object[]
                     {
                         ex2
                     });
                 }
             }
         }
     }
 }
示例#6
0
 private void LoadFrom(CoreFolder coreFolder)
 {
     using (IModifyTable permissionTable = coreFolder.GetPermissionTable(this.PermissionSet.ModifyTableOptions))
     {
         try
         {
             this.LoadFrom(new MapiAclTableAdapter(permissionTable));
         }
         catch (DataSourceOperationException ex)
         {
             throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "PermissionsTable.LoadFrom. Failed due to directory exception {0}.", new object[]
             {
                 ex
             });
         }
         catch (DataSourceTransientException ex2)
         {
             throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "PermissionsTable.LoadFrom. Failed due to directory exception {0}.", new object[]
             {
                 ex2
             });
         }
     }
 }
示例#7
0
        private void SaveSharingPartnership(MailboxSession mailboxSession)
        {
            if (mailboxSession == null)
            {
                return;
            }
            IRecipientSession recipientSession = null;
            ADUser            aduser           = null;

            foreach (Permission permission in this.permissions.Values)
            {
                if (permission.Principal.Type == PermissionSecurityPrincipal.SecurityPrincipalType.ExternalUserPrincipal && !permission.Principal.ExternalUser.IsReachUser)
                {
                    if (aduser == null)
                    {
                        recipientSession = mailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent);
                        ADRecipient adrecipient = recipientSession.Read(mailboxSession.MailboxOwner.ObjectId);
                        if (adrecipient == null)
                        {
                            throw new ObjectNotFoundException(ServerStrings.ADUserNotFound);
                        }
                        aduser = (adrecipient as ADUser);
                        if (aduser == null)
                        {
                            ExTraceGlobals.StorageTracer.TraceDebug <ADRecipient>((long)this.GetHashCode(), "PermissionTable::SaveSharingParterner. This is not an ADUser so SharingPartnerIdentities doesn't apply. Recipient = {0}.", adrecipient);
                            return;
                        }
                    }
                    string externalId = permission.Principal.ExternalUser.ExternalId;
                    if (!aduser.SharingPartnerIdentities.Contains(externalId))
                    {
                        try
                        {
                            aduser.SharingPartnerIdentities.Add(externalId);
                        }
                        catch (InvalidOperationException ex)
                        {
                            ExTraceGlobals.StorageTracer.TraceError <ADUser, InvalidOperationException>((long)this.GetHashCode(), "PermissionTable::SaveSharingParterner. Failed to add SharingPartnerIdentities on user {0} due to exception {1}.", aduser, ex);
                            throw new InvalidObjectOperationException(new LocalizedString(ex.Message), ex);
                        }
                    }
                }
            }
            if (aduser != null && aduser.SharingPartnerIdentities.Changed)
            {
                try
                {
                    recipientSession.Save(aduser);
                }
                catch (DataValidationException innerException)
                {
                    throw new CorruptDataException(ServerStrings.ExCannotSaveInvalidObject(aduser), innerException);
                }
                catch (DataSourceOperationException ex2)
                {
                    throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "PermissionTable::SaveSharingParterner(): Failed due to directory exception {0}.", new object[]
                    {
                        ex2
                    });
                }
                catch (DataSourceTransientException ex3)
                {
                    throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex3, null, "PermissionTable::SaveSharingParterner(): Failed due to directory exception {0}.", new object[]
                    {
                        ex3
                    });
                }
            }
        }