Exemple #1
0
 protected static bool QueueTask(UnifiedGroupsTask task)
 {
     return(ThreadPool.QueueUserWorkItem(delegate(object state)
     {
         try
         {
             GrayException.MapAndReportGrayExceptions(delegate()
             {
                 task.RunWithLogging();
             });
         }
         catch (GrayException arg)
         {
             UnifiedGroupsTask.Tracer.TraceError <Guid, GrayException>(0L, "ActivityId: {0}. GrayException: {1}", task.ActivityId, arg);
             FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
             {
                 {
                     FederatedDirectoryLogSchema.TraceTag.TaskName,
                     task.TaskName
                 },
                 {
                     FederatedDirectoryLogSchema.TraceTag.ActivityId,
                     task.ActivityId
                 },
                 {
                     FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                     task.CurrentAction
                 },
                 {
                     FederatedDirectoryLogSchema.TraceTag.Message,
                     "GrayException: " + arg
                 }
             });
         }
     }));
 }
Exemple #2
0
 protected override void RunInternal()
 {
     UnifiedGroupsTask.Tracer.TraceDebug <Guid, string, string>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: User {1} is updating group {2}", base.ActivityId, this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), this.ExternalDirectoryObjectId ?? this.SmtpAddress);
     base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.ResolveExternalIdentities;
     if (base.IsAADEnabled || base.IsSharePointEnabled)
     {
         this.GetIdentitiesForParameters();
     }
     UpdateUnifiedGroupTask.UpdateAADLinkResults updateAADLinkResults = null;
     base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.AADUpdate;
     if (base.IsAADEnabled)
     {
         UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Updating group in AAD", base.ActivityId);
         updateAADLinkResults = this.UpdateAAD();
         UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Finished updating group in AAD", base.ActivityId);
         base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.SharePointUpdate;
         if (base.IsSharePointEnabled)
         {
             UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Enqueueing job to notify SharePoint about group update", base.ActivityId);
             UpdateSiteCollectionTask task = new UpdateSiteCollectionTask(base.AccessingUser, base.ADSession, base.ActivityId)
             {
                 Description               = this.Description,
                 DisplayName               = this.DisplayName,
                 AddedOwners               = this.GetSucceededLinkExternalIds(this.addedOwnersIdentities, updateAADLinkResults.FailedAddedOwners),
                 RemovedOwners             = this.GetSucceededLinkExternalIds(this.removedOwnersIdentities, updateAADLinkResults.FailedRemovedOwners),
                 AddedMembers              = this.GetSucceededLinkExternalIds(this.addedMembersIdentities, updateAADLinkResults.FailedAddedMembers),
                 RemovedMembers            = this.GetSucceededLinkExternalIds(this.removedMembersIdentities, updateAADLinkResults.FailedRemovedMembers),
                 ExternalDirectoryObjectId = this.ExternalDirectoryObjectId
             };
             bool flag = UnifiedGroupsTask.QueueTask(task);
             UnifiedGroupsTask.Tracer.TraceDebug <Guid, bool>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Finished enqueueing job to notify SharePoint about group update. queued: {1}", base.ActivityId, flag);
             if (!flag)
             {
                 UnifiedGroupsTask.Tracer.TraceError <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Failed to queue job to notify SharePoint about group update", base.ActivityId);
                 FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
                 {
                     {
                         FederatedDirectoryLogSchema.TraceTag.TaskName,
                         this.TaskName
                     },
                     {
                         FederatedDirectoryLogSchema.TraceTag.ActivityId,
                         base.ActivityId
                     },
                     {
                         FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                         base.CurrentAction
                     },
                     {
                         FederatedDirectoryLogSchema.TraceTag.Message,
                         "Failed to queue job to notify SharePoint about group update. ExternalDirectoryObjectId: " + this.ExternalDirectoryObjectId
                     }
                 });
             }
         }
         else
         {
             UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: SharePoint is not enabled, skipping notification about group creation", base.ActivityId);
         }
     }
     base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.ExchangeUpdate;
     UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Updating group in Exchange", base.ActivityId);
     try
     {
         this.UpdateGroupMailbox(updateAADLinkResults);
     }
     catch (ExchangeAdaptorException arg)
     {
         if (updateAADLinkResults == null || !updateAADLinkResults.ContainsFailure())
         {
             throw;
         }
         FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
         {
             {
                 FederatedDirectoryLogSchema.TraceTag.TaskName,
                 this.TaskName
             },
             {
                 FederatedDirectoryLogSchema.TraceTag.ActivityId,
                 base.ActivityId
             },
             {
                 FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                 base.CurrentAction
             },
             {
                 FederatedDirectoryLogSchema.TraceTag.Message,
                 string.Format("AAD partially failed and Exchange threw an exception. ExternalDirectoryObjectId: {0}, {1}", this.ExternalDirectoryObjectId ?? this.SmtpAddress, arg)
             }
         });
     }
     UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: Finished updating group in Exchange", base.ActivityId);
     FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
     {
         {
             FederatedDirectoryLogSchema.TraceTag.TaskName,
             this.TaskName
         },
         {
             FederatedDirectoryLogSchema.TraceTag.ActivityId,
             base.ActivityId
         },
         {
             FederatedDirectoryLogSchema.TraceTag.CurrentAction,
             base.CurrentAction
         },
         {
             FederatedDirectoryLogSchema.TraceTag.Message,
             string.Format("Updated group. ExternalDirectoryObjectId: {0}, By: {1}", this.ExternalDirectoryObjectId ?? this.SmtpAddress, this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString())
         }
     });
     this.ThrowIfPartialSuccess(updateAADLinkResults);
     base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.Completed;
 }
Exemple #3
0
        protected override void RunInternal()
        {
            this.CreationDiagnostics.Start();
            UnifiedGroupsTask.Tracer.TraceDebug((long)this.GetHashCode(), "ActivityId={0}. UpdateUnifiedGroupTask.Run: User {1} is creating a group. Name: {2}, Alias: {3}", new object[]
            {
                base.ActivityId,
                this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString(),
                this.Name,
                this.Alias
            });
            this.CreationDiagnostics.CmdletLogCorrelationId = base.ActivityId;
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.AADCreate;
            UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Creating group in AAD", base.ActivityId);
            this.ExternalDirectoryObjectId = this.CreateAAD();
            UnifiedGroupsTask.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Finished creating group in AAD. ExternalDirectoryObjectId: {1}", base.ActivityId, this.ExternalDirectoryObjectId);
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.AADAddOwnerAsMember;
            UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Adding owner as member in AAD", base.ActivityId);
            try
            {
                this.AddOwnerAsMember(this.ExternalDirectoryObjectId, base.AccessingUser.ExternalDirectoryObjectId);
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Finished adding owner as member in AAD", base.ActivityId);
            }
            catch (AADException ex)
            {
                UnifiedGroupsTask.Tracer.TraceError <Guid, AADException>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Adding owner as member in AAD failed: {1}", base.ActivityId, ex);
                FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.ExceptionTag>
                {
                    {
                        FederatedDirectoryLogSchema.ExceptionTag.TaskName,
                        this.TaskName
                    },
                    {
                        FederatedDirectoryLogSchema.ExceptionTag.ActivityId,
                        base.ActivityId
                    },
                    {
                        FederatedDirectoryLogSchema.ExceptionTag.ExceptionType,
                        ex.GetType()
                    },
                    {
                        FederatedDirectoryLogSchema.ExceptionTag.ExceptionDetail,
                        ex
                    },
                    {
                        FederatedDirectoryLogSchema.ExceptionTag.CurrentAction,
                        base.CurrentAction
                    },
                    {
                        FederatedDirectoryLogSchema.ExceptionTag.Message,
                        "Adding owner as member in AAD failed"
                    }
                });
            }
            this.CreationDiagnostics.RecordAADTime();
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.AADCompleteCallback;
            if (this.AADComplete != null)
            {
                try
                {
                    UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Calling AADComplete", base.ActivityId);
                    this.AADComplete();
                    UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Finished calling AADComplete", base.ActivityId);
                }
                catch (LocalizedException ex2)
                {
                    UnifiedGroupsTask.Tracer.TraceError <Guid, LocalizedException>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: AADComplete event failed: {1}", base.ActivityId, ex2);
                    FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.ExceptionTag>
                    {
                        {
                            FederatedDirectoryLogSchema.ExceptionTag.TaskName,
                            this.TaskName
                        },
                        {
                            FederatedDirectoryLogSchema.ExceptionTag.ActivityId,
                            base.ActivityId
                        },
                        {
                            FederatedDirectoryLogSchema.ExceptionTag.ExceptionType,
                            ex2.GetType()
                        },
                        {
                            FederatedDirectoryLogSchema.ExceptionTag.ExceptionDetail,
                            ex2
                        },
                        {
                            FederatedDirectoryLogSchema.ExceptionTag.CurrentAction,
                            base.CurrentAction
                        },
                        {
                            FederatedDirectoryLogSchema.ExceptionTag.Message,
                            "AADComplete event failed"
                        }
                    });
                }
            }
            this.CreationDiagnostics.RecordAADCompleteCallbackTime();
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.SharePointCreate;
            if (base.IsSharePointEnabled)
            {
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Queuing job to notify SharePoint about group creation", base.ActivityId);
                CreateSiteCollectionTask task = new CreateSiteCollectionTask(base.AccessingUser, base.ADSession, base.ActivityId)
                {
                    Name        = this.Name,
                    Alias       = this.Alias,
                    Description = this.Description,
                    Type        = this.Type,
                    ExternalDirectoryObjectId = this.ExternalDirectoryObjectId
                };
                bool flag = UnifiedGroupsTask.QueueTask(task);
                UnifiedGroupsTask.Tracer.TraceDebug <Guid, bool>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Finished queuing job to notify SharePoint about group creation. queued: {1}", base.ActivityId, flag);
                if (!flag)
                {
                    UnifiedGroupsTask.Tracer.TraceError <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Failed to queue job to notify SharePoint about group creation", base.ActivityId);
                    FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
                    {
                        {
                            FederatedDirectoryLogSchema.TraceTag.TaskName,
                            this.TaskName
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.ActivityId,
                            base.ActivityId
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                            base.CurrentAction
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.Message,
                            "Failed to queue job to notify SharePoint about group creation. ExternalDirectoryObjectId: " + this.ExternalDirectoryObjectId
                        }
                    });
                }
            }
            else
            {
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: SharePoint is not enabled, skipping notification about group creation", base.ActivityId);
            }
            this.CreationDiagnostics.RecordSharePointNotificationTime();
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.ExchangeCreate;
            UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Creating group in Exchange", base.ActivityId);
            GroupMailbox groupMailbox = this.CreateGroupMailbox(this.ExternalDirectoryObjectId);

            this.ADObjectGuid = groupMailbox.Guid;
            this.SmtpAddress  = groupMailbox.PrimarySmtpAddress.ToString();
            UnifiedGroupsTask.Tracer.TraceDebug <Guid, ObjectId>((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.Run: Finished creating group in Exchange. Identity: {1}", base.ActivityId, groupMailbox.Identity);
            this.CreationDiagnostics.RecordMailboxTime();
            this.CreationDiagnostics.MailboxCreatedSuccessfully = true;
            string text = this.EnsureGroupIsInDirectoryCache(groupMailbox);

            FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
            {
                {
                    FederatedDirectoryLogSchema.TraceTag.TaskName,
                    this.TaskName
                },
                {
                    FederatedDirectoryLogSchema.TraceTag.ActivityId,
                    base.ActivityId
                },
                {
                    FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                    base.CurrentAction
                },
                {
                    FederatedDirectoryLogSchema.TraceTag.Message,
                    string.Format("Created group. Name: {0}, Alias: {1}, Type: {2}, ExternalDirectoryObjectId: {3}, By: {4}. EnsureCached={5}", new object[]
                    {
                        this.Name,
                        this.Alias,
                        this.Type,
                        this.ExternalDirectoryObjectId,
                        this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress,
                        text
                    })
                }
            });
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.Completed;
            this.CreationDiagnostics.Stop();
        }
Exemple #4
0
 public UnifiedGroupsTask(ADUser accessingUser, IRecipientSession adSession) : this(accessingUser, adSession, UnifiedGroupsTask.GetActivityId())
 {
 }
Exemple #5
0
        protected override void RunInternal()
        {
            UnifiedGroupsTask.Tracer.TraceDebug <Guid, string, string>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: User {1} is deleting group {2}", base.ActivityId, this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), this.ExternalDirectoryObjectId ?? this.SmtpAddress);
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.AADDelete;
            try
            {
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Deleting group in AAD", base.ActivityId);
                this.DeleteAAD();
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Finished deleting group in AAD", base.ActivityId);
            }
            catch (AADDataException ex)
            {
                if (ex.Code != AADDataException.AADCode.Request_ResourceNotFound)
                {
                    throw;
                }
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Group not found in AAD", base.ActivityId);
            }
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.SharePointDelete;
            if (base.IsSharePointEnabled)
            {
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Enqueuing job to notify SharePoint about group deletion", base.ActivityId);
                DeleteSiteCollectionTask task = new DeleteSiteCollectionTask(base.AccessingUser, base.ADSession, base.ActivityId)
                {
                    ExternalDirectoryObjectId = this.ExternalDirectoryObjectId,
                    SmtpAddress = this.SmtpAddress
                };
                bool flag = UnifiedGroupsTask.QueueTask(task);
                UnifiedGroupsTask.Tracer.TraceDebug <Guid, bool>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Finished enqueuing job to notify SharePoint about group deletion. queued: {1}", base.ActivityId, flag);
                if (!flag)
                {
                    UnifiedGroupsTask.Tracer.TraceError <Guid>((long)this.GetHashCode(), "ActivityId={0}. Failed to queue job to notify SharePoint about group deletion", base.ActivityId);
                    FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
                    {
                        {
                            FederatedDirectoryLogSchema.TraceTag.TaskName,
                            this.TaskName
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.ActivityId,
                            base.ActivityId
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                            base.CurrentAction
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.Message,
                            "Failed to queue job to notify SharePoint about group deletion. ExternalDirectoryObjectId: " + this.ExternalDirectoryObjectId
                        }
                    });
                }
            }
            else
            {
                UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: SharePoint is not enabled, skipping notification about group creation", base.ActivityId);
            }
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.ExchangeDelete;
            UnifiedGroupsTask.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Enqueuing job to delete group in Exchange", base.ActivityId);
            bool flag2 = UnifiedGroupsTask.QueueTask(new DeleteGroupMailboxTask(base.AccessingUser, this.accessingPrincipal, base.ADSession)
            {
                ExternalDirectoryObjectId = this.ExternalDirectoryObjectId,
                SmtpAddress = this.SmtpAddress
            });

            UnifiedGroupsTask.Tracer.TraceDebug <Guid, bool>((long)this.GetHashCode(), "ActivityId={0}. DeleteUnifiedGroupTask.Run: Finished enqueuing job to delete group in Exchange. queued: {1}", base.ActivityId, flag2);
            if (!flag2)
            {
                UnifiedGroupsTask.Tracer.TraceError <Guid>((long)this.GetHashCode(), "ActivityId={0}. Failed to queue job to delete group in Exchange", base.ActivityId);
                FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
                {
                    {
                        FederatedDirectoryLogSchema.TraceTag.TaskName,
                        this.TaskName
                    },
                    {
                        FederatedDirectoryLogSchema.TraceTag.ActivityId,
                        base.ActivityId
                    },
                    {
                        FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                        base.CurrentAction
                    },
                    {
                        FederatedDirectoryLogSchema.TraceTag.Message,
                        string.Format("Failed to queue job to delete group in Exchange. ExternalDirectoryObjectId: {0}", this.ExternalDirectoryObjectId)
                    }
                });
            }
            FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
            {
                {
                    FederatedDirectoryLogSchema.TraceTag.TaskName,
                    this.TaskName
                },
                {
                    FederatedDirectoryLogSchema.TraceTag.ActivityId,
                    base.ActivityId
                },
                {
                    FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                    base.CurrentAction
                },
                {
                    FederatedDirectoryLogSchema.TraceTag.Message,
                    string.Format("Deleted group. ExternalDirectoryObjectId: {0}, By: {1}", this.ExternalDirectoryObjectId ?? this.SmtpAddress, this.accessingPrincipal.MailboxInfo.PrimarySmtpAddress.ToString())
                }
            });
            base.CurrentAction = UnifiedGroupsTask.UnifiedGroupsAction.Completed;
        }