Exemplo n.º 1
0
 internal static void ParseUsers(XmlReader reader, bool isMultiTenant, out List <string> qualifiedUsers, out List <string> droppedUsers)
 {
     qualifiedUsers = new List <string>();
     droppedUsers   = new List <string>();
     while (reader.ReadToFollowing("entry"))
     {
         if (reader.ReadToFollowing("content") && reader.ReadToFollowing("m:properties") && reader.ReadToFollowing("d:UserId"))
         {
             string text  = null;
             string text2 = null;
             bool   flag  = true;
             reader.Read();
             while (flag)
             {
                 if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("d:NameId", StringComparison.OrdinalIgnoreCase))
                 {
                     text = reader.ReadElementContentAsString();
                 }
                 else if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("d:NameIdIssuer", StringComparison.OrdinalIgnoreCase))
                 {
                     text2 = reader.ReadElementContentAsString();
                 }
                 else
                 {
                     flag = ((reader.NodeType != XmlNodeType.EndElement || !reader.Name.Equals("d:UserId", StringComparison.OrdinalIgnoreCase)) && reader.Read());
                 }
             }
             if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2))
             {
                 string             text3 = text2.ToLowerInvariant();
                 SecurityIdentifier securityIdentifier;
                 if (isMultiTenant)
                 {
                     NetID netID;
                     if ((text3.Equals("urn:federation:microsoftonline") || text3.Equals("urn:office:idp:orgid")) && NetID.TryParse(text, out netID))
                     {
                         qualifiedUsers.Add(text);
                     }
                     else
                     {
                         droppedUsers.Add(text);
                     }
                 }
                 else if (text3.Equals("urn:office:idp:activedirectory") && MembershipSynchronizer.TryParseSid(text, out securityIdentifier))
                 {
                     qualifiedUsers.Add(text);
                 }
                 else
                 {
                     droppedUsers.Add(text);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public override void Begin(object state)
 {
     try
     {
         GrayException.MapAndReportGrayExceptions(delegate()
         {
             base.SafeInitializeLoggingStream();
             MembershipSynchronizer membershipSynchronizer = new MembershipSynchronizer(this, base.SyncInfoEntry.MailboxSession, base.SyncInfoEntry.MailboxPrincipal.MailboxInfo.OrganizationId, this.teamMailboxSecurityRefresher, base.SyncInfoEntry.ResourceMonitor, base.SyncInfoEntry.SiteUrl, this.credentials, ((TeamMailboxSyncConfiguration)base.Config).UseOAuth, ((TeamMailboxSyncConfiguration)base.Config).HttpDebugEnabled, this.syncCycleLogStream);
             membershipSynchronizer.BeginExecute(new AsyncCallback(this.OnMembershipSynchronizationCompleted), membershipSynchronizer);
         });
     }
     catch (GrayException lastError)
     {
         base.LastError = lastError;
         this.End();
     }
 }
Exemplo n.º 3
0
        private void OnMembershipSynchronizationCompleted(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new InvalidOperationException("TeamMailboxSyncJob.OnMembershipSynchronizationCompleted: asyncResult cannot be null here.");
            }
            MembershipSynchronizer membershipSynchronizer = asyncResult.AsyncState as MembershipSynchronizer;

            if (membershipSynchronizer == null)
            {
                throw new InvalidOperationException("TeamMailboxSyncJob.OnMembershipSynchronizationCompleted: asyncResult.AsyncState is not MembershipSynchronizer");
            }
            membershipSynchronizer.EndExecute(asyncResult);
            if (membershipSynchronizer.LastError != null)
            {
                base.LastError = membershipSynchronizer.LastError;
            }
            this.End();
        }
Exemplo n.º 4
0
 public UsersToUpdateShowInMyClient(IList <ADObjectId> usersToAdd, IList <ADObjectId> usersToRemove, MembershipSynchronizer membershipSynchronizer)
 {
     this.membershipSynchronizer = membershipSynchronizer;
     foreach (ADObjectId id in usersToAdd)
     {
         this.Add(id, true);
     }
     foreach (ADObjectId id2 in usersToRemove)
     {
         this.Add(id2, false);
     }
     this.usersEnumerator = this.users.GetEnumerator();
 }
Exemplo n.º 5
0
        protected virtual Exception ProcessNewOwnersAndMembers(Guid mailboxGuid, List <ADObjectId> newOwners, List <ADObjectId> newMembers)
        {
            Exception ex = null;

            try
            {
                this.mailbox = (this.recipientSession.FindByExchangeGuid(mailboxGuid) as ADUser);
                if (this.mailbox == null)
                {
                    throw new ObjectNotFoundException(new LocalizedString("Cannot find the team mailbox by mailbox guid " + mailboxGuid));
                }
                this.tm = TeamMailbox.FromDataObject(this.mailbox);
            }
            catch (ADTransientException ex2)
            {
                ex = ex2;
            }
            catch (ADExternalException ex3)
            {
                ex = ex3;
            }
            catch (ADOperationException ex4)
            {
                ex = ex4;
            }
            catch (DataValidationException ex5)
            {
                ex = ex5;
            }
            catch (ObjectNotFoundException ex6)
            {
                ex = ex6;
            }
            if (ex != null)
            {
                ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: Failed to find team mailbox {0}", (this.mailbox == null) ? mailboxGuid.ToString() : this.mailbox.PrimarySmtpAddress.ToString()), ex);
                return(ex);
            }
            this.membershipHelper = new TeamMailboxMembershipHelper(this.tm, this.recipientSession);
            TeamMailboxNotificationHelper teamMailboxNotificationHelper = null;

            if (this.isFirstSync)
            {
                teamMailboxNotificationHelper = new TeamMailboxNotificationHelper(this.tm, this.recipientSession);
                ADObjectId adobjectId = (this.tm.OwnersAndMembers.Count > 0) ? this.tm.OwnersAndMembers[0] : null;
                try
                {
                    if (adobjectId != null)
                    {
                        List <ADObjectId> list = MembershipSynchronizer.ListForSingleId(adobjectId);
                        ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: the following users have been added to team mailbox {0}: {1}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list)));
                        int count = this.tm.Owners.Count;
                        teamMailboxNotificationHelper.SendNotification(list, TeamMailboxNotificationType.MemberInvitation);
                    }
                }
                catch (StorageTransientException ex7)
                {
                    ex = ex7;
                }
                catch (StoragePermanentException ex8)
                {
                    ex = ex8;
                }
                if (ex != null)
                {
                    ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed sending notifications for team mailbox {0}", this.mailbox.PrimarySmtpAddress), ex);
                }
            }
            new List <ADObjectId>();
            IList <ADObjectId> newUserList = TeamMailbox.MergeUsers(newOwners, newMembers);
            IList <ADObjectId> userList;
            IList <ADObjectId> list2;
            bool flag = this.membershipHelper.UpdateTeamMailboxUserList(this.tm.Owners, newOwners, out userList, out list2);
            IList <ADObjectId> list3;
            IList <ADObjectId> list4;
            bool flag2 = this.membershipHelper.UpdateTeamMailboxUserList(this.tm.OwnersAndMembers, newUserList, out list3, out list4);

            if (flag || flag2)
            {
                TeamMailbox.DiffUsers(list3, userList);
                try
                {
                    this.membershipHelper.SetTeamMailboxUserPermissions(list3, list4, null, true);
                }
                catch (OverflowException ex9)
                {
                    ex = ex9;
                }
                catch (COMException ex10)
                {
                    ex = ex10;
                }
                catch (UnauthorizedAccessException ex11)
                {
                    ex = ex11;
                }
                catch (TransientException ex12)
                {
                    ex = ex12;
                }
                catch (DataSourceOperationException ex13)
                {
                    ex = ex13;
                }
                if (ex != null)
                {
                    ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed setting AD permissions for team mailbox {0}", this.mailbox.PrimarySmtpAddress), ex);
                    return(ex);
                }
                ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: the following users have been added to team mailbox {0}: {1}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list3)));
                ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: the following users have been removed from team mailbox {0}: {1}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list4)));
                try
                {
                    this.teamMailboxSecurityRefresher.Refresh(this.mailbox, this.recipientSession);
                }
                catch (DatabaseNotFoundException ex14)
                {
                    ex = ex14;
                }
                catch (ObjectNotFoundException ex15)
                {
                    ex = ex15;
                }
                if (ex != null)
                {
                    ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed setting team mailbox {0} store permissions for userToAdd {1} and usersToRemove {2}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list3), MembershipSynchronizer.GetUsersString(list4)), ex);
                }
                if (teamMailboxNotificationHelper == null)
                {
                    teamMailboxNotificationHelper = new TeamMailboxNotificationHelper(this.tm, this.recipientSession);
                }
                try
                {
                    teamMailboxNotificationHelper.SendNotification(list3, TeamMailboxNotificationType.MemberInvitation);
                }
                catch (StorageTransientException ex16)
                {
                    ex = ex16;
                }
                catch (StoragePermanentException ex17)
                {
                    ex = ex17;
                }
                if (ex != null)
                {
                    ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed sending member invitation for team mailbox {0}", this.mailbox.PrimarySmtpAddress), ex);
                }
                this.usersToUpdateShowInMyClient = new MembershipSynchronizer.UsersToUpdateShowInMyClient(list3, list4, this);
                while (this.usersToUpdateShowInMyClient.UpdateNextBatch())
                {
                    TimeSpan timeSpan;
                    this.IsThrottleDelayNeeded(out timeSpan);
                }
            }
            return(ex);
        }
Exemplo n.º 6
0
        protected virtual void OnGetUsersComplete(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new InvalidOperationException("OnGetUsersComplete: asyncResult or the AsynState cannot be null here.");
            }
            if (base.HandleShutDown())
            {
                return;
            }
            Exception ex        = null;
            XmlReader xmlReader = this.EndGetUsers((ICancelableAsyncResult)asyncResult, out ex);

            if (ex != null)
            {
                this.executionAsyncResult.InvokeCallback(ex);
                return;
            }
            List <ADObjectId> list    = new List <ADObjectId>();
            bool          flag        = false;
            Guid          mailboxGuid = this.Job.SyncInfoEntry.MailboxGuid;
            List <string> list2       = new List <string>();
            List <string> list3       = new List <string>();

            try
            {
                using (xmlReader)
                {
                    MembershipSynchronizer.ParseUsers(xmlReader, MembershipSynchronizer.isMultiTenant, out list2, out list3);
                }
            }
            catch (XmlException value)
            {
                this.executionAsyncResult.InvokeCallback(value);
                return;
            }
            foreach (string text in list2)
            {
                try
                {
                    Exception  ex2;
                    ADRawEntry adrawEntry = TeamMailboxNameIdResolver.Resolve(this.recipientSession, text, out ex2);
                    if (ex2 != null)
                    {
                        ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.OnGetUsersComplete: Skip the update for user {0} because we failed to resolve it", text), ex2);
                    }
                    else if (adrawEntry != null)
                    {
                        if (TeamMailboxMembershipHelper.IsUserQualifiedType(adrawEntry))
                        {
                            if (this.newOwners.Count + list.Count >= 1800)
                            {
                                flag = true;
                                break;
                            }
                            list.Add(adrawEntry.Id);
                        }
                        else
                        {
                            ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.OnGetUsersComplete: Drop unqualified owner {0} for team mailbox {1}", adrawEntry.Id, mailboxGuid));
                        }
                    }
                }
                catch (NonUniqueRecipientException exception)
                {
                    ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.OnGetUsersComplete: Skip the update for user {0} because of NonUniqueRecipientException", text), exception);
                }
            }
            if (!this.doneDownloadingOwners)
            {
                this.newOwners             = list;
                this.doneDownloadingOwners = true;
                this.BeginDownloadUsers(new AsyncCallback(this.OnGetUsersComplete), false);
                return;
            }
            this.newMembers = list;
            if (flag)
            {
                ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.OnGetUsersComplete: the total user count is more than TotalOwnersAndMembersLimit ({0}), updated {1} users only for team mailbox {2}.", 1800, 1800, mailboxGuid), new NotSupportedException());
            }
            Exception value2 = this.ProcessNewOwnersAndMembers(mailboxGuid, this.newOwners, this.newMembers);

            this.executionAsyncResult.InvokeCallback(value2);
        }