Ejemplo n.º 1
0
 internal void SetExternalResources(bool failOnError)
 {
     if (!AADClientFactory.IsAADEnabled())
     {
         this.AddVerboseLog("AADClient is not enabled. Skipping SetExternalResources step.");
         return;
     }
     using (new StopwatchPerformanceTracker("GroupMailboxContext.PublishExchangeResources", GenericCmdletInfoDataLogger.Instance))
     {
         try
         {
             new GroupMailboxExchangeResourcesPublisher(this.groupMailbox, this.GetActivityId()).Publish(new int?(0));
             this.AddVerboseLog("Published ExternalResources to AAD.");
             if (!this.groupMailbox.GroupMailboxExternalResourcesSet)
             {
                 this.groupMailbox.GroupMailboxExternalResourcesSet = true;
                 this.adSession.Save(this.groupMailbox);
             }
             this.AddVerboseLog("Set GroupMailboxExternalResourcesSet to true");
         }
         catch (LocalizedException ex)
         {
             if (failOnError)
             {
                 this.errorHandler(new LocalizedException(new LocalizedString("Failed to set exchangeResources in AAD: " + ex.ToString()), ex), ExchangeErrorCategory.ServerTransient, null);
             }
             else
             {
                 this.warningHandler(new LocalizedString("Failed to set exchangeResources in AAD: " + ex.ToString()));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public UnifiedGroupsTask(ADUser accessingUser, IRecipientSession adSession, Guid activityId)
 {
     this.AccessingUser = accessingUser;
     this.ADSession     = adSession;
     this.AADClient     = AADClientFactory.Create(accessingUser);
     this.ActivityId    = activityId;
 }
Ejemplo n.º 3
0
 private static IAadClient CreateAadClient(OrganizationId organizationId, GraphProxyVersions graphProxyVersion)
 {
     if (TestHooks.GraphApi_GetAadClient != null)
     {
         return(TestHooks.GraphApi_GetAadClient(organizationId));
     }
     return(AADClientFactory.Create(organizationId, graphProxyVersion));
 }
Ejemplo n.º 4
0
        private IAadClient GetAADClient(MailboxAssociation association)
        {
            if (AADClientTestHooks.GraphApi_GetAadClient != null)
            {
                return(AADClientTestHooks.GraphApi_GetAadClient());
            }
            ADUser user = association.User.FindAdUser();

            return(AADClientFactory.Create(user));
        }
Ejemplo n.º 5
0
        private AADClient CreateAADClient(ADUser user)
        {
            AADClient aadclient = AADClientFactory.Create(user);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            return(aadclient);
        }
Ejemplo n.º 6
0
        // Token: 0x0600152B RID: 5419 RVA: 0x00078E20 File Offset: 0x00077020
        internal static bool IsGroupMailboxExchangeResourcesVersionOutdated(int?resourcesVersion, Guid mailboxGuid)
        {
            if (!AADClientFactory.IsAADEnabled())
            {
                GroupMailboxAssistantType.Tracer.TraceDebug <Guid>(0L, "GroupMailboxAssistantType.IsGroupMailboxExchangeResourcesVersionOutdated: AAD is not enabled for mailbox {0}, skipping resource publishing.", mailboxGuid);
                return(false);
            }
            bool flag = GroupMailboxExchangeResourcesPublisher.IsPublishedVersionOutdated(resourcesVersion);

            GroupMailboxAssistantType.Tracer.TraceDebug <Guid, bool>(0L, "GroupMailboxAssistantType.IsGroupMailboxExchangeResourcesVersionOutdated:  {0} - {1}", mailboxGuid, flag);
            return(flag);
        }
Ejemplo n.º 7
0
        protected override void InternalProcessRecord()
        {
            AADClient aadclient = AADClientFactory.Create(base.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
                return;
            }
            if (this.Identity != null)
            {
                Group group;
                try
                {
                    group = aadclient.GetGroup(this.Identity.Value.ToString(), true);
                }
                catch (AADException ex)
                {
                    base.WriteVerbose("GetGroup failed with exception: {0}", new object[]
                    {
                        ex
                    });
                    base.WriteError(new TaskException(Strings.ErrorUnableToGetUnifiedGroup), base.GetErrorCategory(ex), null);
                    return;
                }
                aadclient.Service.LoadProperty(group, "createdOnBehalfOf");
                aadclient.Service.LoadProperty(group, "members");
                aadclient.Service.LoadProperty(group, "owners");
                this.WriteAADGroupObject(group);
                return;
            }
            try
            {
                foreach (Group group2 in aadclient.GetGroups())
                {
                    this.WriteAADGroupObject(group2);
                }
            }
            catch (AADException ex2)
            {
                base.WriteVerbose("GetGroups failed with exception: {0}", new object[]
                {
                    ex2
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToGetUnifiedGroup), base.GetErrorCategory(ex2), null);
            }
        }
Ejemplo n.º 8
0
        private void UpdateFromGroupMailbox()
        {
            ADUser aduser       = this.recipientSession.FindADUserByExternalDirectoryObjectId(this.Identity.ToString());
            ADUser ownerFromAAD = this.GetOwnerFromAAD(aduser, this.recipientSession);

            string[] members     = base.GetMembers(aduser, this.recipientSession, "Set-UnifiedGroup");
            string[] owners      = base.GetOwners(aduser, null, this.recipientSession);
            string   description = (aduser.Description != null && aduser.Description.Count > 0) ? aduser.Description[0] : string.Empty;

            string[]  exchangeResources = this.GetExchangeResources(aduser);
            AADClient aadclient         = AADClientFactory.Create(ownerFromAAD);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            this.UpdateGroup(aduser.DisplayName, description, exchangeResources, aduser.ExternalDirectoryObjectId, aadclient);
            base.AddOwnersInAAD(owners, aadclient, aduser.ExternalDirectoryObjectId);
            base.AddMembersInAAD(members, aadclient, aduser.ExternalDirectoryObjectId);
        }
Ejemplo n.º 9
0
        protected override void InternalProcessRecord()
        {
            if (base.Fields.IsModified("SyncGroupMailbox") && this.SyncGroupMailbox)
            {
                this.UpdateFromGroupMailbox();
                return;
            }
            ADUser groupMailbox = this.recipientSession.FindADUserByExternalDirectoryObjectId(this.Identity.ToString());
            ADUser ownerFromAAD = this.GetOwnerFromAAD(groupMailbox, this.recipientSession);

            string[]  exchangeResources = this.GetExchangeResources(groupMailbox);
            AADClient aadclient         = AADClientFactory.Create(ownerFromAAD);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            this.UpdateGroup(this.DisplayName, this.Description, exchangeResources, this.Identity.ToString(), aadclient);
            base.AddOwnersInAAD(this.addOwners, aadclient, this.Identity.ToString());
            base.RemoveOwnersInAAD(this.removeOwners, aadclient, this.Identity.ToString());
            base.AddMembersInAAD(this.addMembers, aadclient, this.Identity.ToString());
            base.RemoveMembersInAAD(this.removeMembers, aadclient, this.Identity.ToString());
        }
Ejemplo n.º 10
0
        protected override void InternalProcessRecord()
        {
            AADClient aadclient = AADClientFactory.Create(base.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            try
            {
                base.WriteVerbose("Calling DeleteGroup", new object[0]);
                aadclient.DeleteGroup(this.Identity.ToString());
                base.WriteVerbose("DeleteGroup succeeded", new object[0]);
            }
            catch (AADException ex)
            {
                base.WriteVerbose("DeleteGroup failed with exception: {0}", new object[]
                {
                    ex
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToRemove(this.Identity.ToString())), base.GetErrorCategory(ex), null);
            }
        }
        // Token: 0x06001B78 RID: 7032 RVA: 0x000691F4 File Offset: 0x000673F4
        private bool IsModernGroupUnique()
        {
            bool      result    = false;
            Stopwatch stopwatch = Stopwatch.StartNew();
            AADClient aadclient = AADClientFactory.Create(base.CallContext.ADRecipientSessionContext.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                return(true);
            }
            try
            {
                result = aadclient.IsAliasUnique(this.request.Alias);
                this.LogElapsedTime(CreateModernGroupCommandMetadata.AADAliasQueryTime, new TimeSpan?(stopwatch.Elapsed));
            }
            catch (AADException ex)
            {
                this.LogElapsedTime(CreateModernGroupCommandMetadata.AADAliasQueryTime, new TimeSpan?(stopwatch.Elapsed));
                ExTraceGlobals.ModernGroupsTracer.TraceError <SmtpAddress, AADException>((long)this.GetHashCode(), "CreateUnifiedGroupCommand: User: {0}. Exception: {1}. AADClient.IsAliasUnique failed", base.CallContext.AccessingPrincipal.MailboxInfo.PrimarySmtpAddress, ex);
                base.CallContext.ProtocolLog.Set(CreateModernGroupCommandMetadata.Exception, ex);
            }
            return(result);
        }
Ejemplo n.º 12
0
        private ADUser GetOwnerFromAAD(ADUser groupMailbox, IRecipientSession recipientSession)
        {
            Group     group     = null;
            AADClient aadclient = AADClientFactory.Create(base.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                base.WriteError(new TaskException(Strings.ErrorUnableToSessionWithAAD), ExchangeErrorCategory.Client, null);
            }
            try
            {
                group = aadclient.GetGroup(groupMailbox.ExternalDirectoryObjectId, true);
                aadclient.Service.LoadProperty(group, "owners");
            }
            catch (AADException ex)
            {
                base.WriteVerbose("Failed to get group owner from AAD with exception: {0}", new object[]
                {
                    ex
                });
                base.WriteError(new TaskException(Strings.ErrorUnableToGetGroupOwners), base.GetErrorCategory(ex), null);
            }
            if (group.owners != null)
            {
                foreach (DirectoryObject directoryObject in group.owners)
                {
                    ADUser aduser = recipientSession.FindADUserByExternalDirectoryObjectId(directoryObject.objectId);
                    if (aduser != null)
                    {
                        return(aduser);
                    }
                }
            }
            base.WriteError(new TaskException(Strings.ErrorUnableToGetGroupOwners), ExchangeErrorCategory.Client, null);
            return(null);
        }
Ejemplo n.º 13
0
        public bool Publish(int?publishedVersion)
        {
            if (!GroupMailboxExchangeResourcesPublisher.IsPublishedVersionOutdated(publishedVersion))
            {
                return(true);
            }
            MailboxUrls mailboxUrls = new MailboxUrls(ExchangePrincipal.FromADUser(this.groupADUser, null), true);
            AADClient   aadclient   = AADClientFactory.Create(this.groupADUser.OrganizationId, GraphProxyVersions.Version14);

            if (aadclient == null)
            {
                string value = string.Format("AADClient was null for organization {0} and group {1}", this.groupADUser.OrganizationId, this.groupADUser.ExternalDirectoryObjectId);
                throw new LocalizedException(new LocalizedString(value));
            }
            if (publishedVersion == null)
            {
                Group group = aadclient.GetGroup(this.groupADUser.ExternalDirectoryObjectId, false);
                if (group == null)
                {
                    FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag>
                    {
                        {
                            FederatedDirectoryLogSchema.TraceTag.TaskName,
                            "PublishResourcesToAAD"
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.ActivityId,
                            this.activityId
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.CurrentAction,
                            "GetGroupFromAAD"
                        },
                        {
                            FederatedDirectoryLogSchema.TraceTag.Message,
                            string.Format("Unable to find group in AAD. ExternalId={0}", this.groupADUser.ExternalDirectoryObjectId)
                        }
                    });
                    return(false);
                }
                string[] array;
                if (group.exchangeResources == null)
                {
                    array = new string[0];
                }
                else
                {
                    array = (from s in @group.exchangeResources
                             select s.ToLower()).ToArray <string>();
                }
                string[] array2 = array;
                string[] array3 = (from s in mailboxUrls.ToExchangeResources()
                                   select s.ToLower()).ToArray <string>();
                if (array2.Length == array3.Length && array2.Except(array3).Count <string>() == 0)
                {
                    return(true);
                }
            }
            string[] exchangeResources = mailboxUrls.ToExchangeResources();
            aadclient.UpdateGroup(this.groupADUser.ExternalDirectoryObjectId, null, exchangeResources, null, null);
            this.TryNotifySharePointForExchangeResources(mailboxUrls);
            return(true);
        }