internal static MasterMailboxType CreateMasterMailboxData(IMailboxLocator master) { ArgumentValidator.ThrowIfNull("master", master); ADUser aduser = master.FindAdUser(); MasterMailboxType masterMailboxType = new MasterMailboxType { Alias = aduser.Alias, DisplayName = aduser.DisplayName, SmtpAddress = aduser.PrimarySmtpAddress.ToString(), MailboxType = master.LocatorType }; GroupMailboxLocator groupMailboxLocator = master as GroupMailboxLocator; if (groupMailboxLocator != null) { MailboxUrls mailboxUrls = new MailboxUrls(ExchangePrincipal.FromADUser(aduser, RemotingOptions.AllowCrossSite), false); masterMailboxType.GroupType = EwsAssociationDataConverter.Convert(groupMailboxLocator.GetGroupType()); masterMailboxType.GroupTypeSpecified = true; masterMailboxType.Description = ((aduser.Description != null && aduser.Description.Count > 0) ? aduser.Description[0] : string.Empty); masterMailboxType.Photo = groupMailboxLocator.GetThumbnailPhoto(); masterMailboxType.SharePointUrl = ((aduser.SharePointUrl != null) ? aduser.SharePointUrl.ToString() : string.Empty); masterMailboxType.InboxUrl = mailboxUrls.InboxUrl; masterMailboxType.CalendarUrl = mailboxUrls.CalendarUrl; masterMailboxType.DomainController = aduser.OriginatingServer; } return(masterMailboxType); }
private bool RedirectToOwaGroupPageIfPossible(IExchangePrincipal groupExchangePrincipal, CallContext callContext, HttpResponse response) { if (callContext.AccessingADUser.RecipientType != RecipientType.UserMailbox) { return(false); } IMailboxUrls mailboxUrls = new MailboxUrls(groupExchangePrincipal, false); string text = mailboxUrls.OwaUrl; if (string.IsNullOrEmpty(text)) { OwaServerTraceLogger.AppendToLog(new TraceLogEvent("GrEsRedir", null, "GroupSubscriptionHandler.RedirectToOwaGroupPageIfPossible", string.Format("Redirection attempt failed for user {0}: couldn't obtain Owa url", callContext.AccessingADUser.PrimarySmtpAddress))); return(false); } if (!text.EndsWith("/")) { text += "/"; } string domain = callContext.AccessingADUser.PrimarySmtpAddress.Domain; string text2 = text + string.Format("?realm={0}&exsvurl=1&path=/group/{1}/action/", domain, groupExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString()); if (this.operationType == ModernGroupMembershipOperationType.Escalate) { text2 += "subscribe"; } else { text2 += "unsubscribe"; } OwaServerTraceLogger.AppendToLog(new TraceLogEvent("GrEsRedir", null, "GroupSubscriptionHandler.RedirectToOwaGroupPageIfPossible", string.Format("Redirecting user {0} to Group page. Url:{1}", callContext.AccessingADUser.PrimarySmtpAddress, text2))); response.Redirect(text2); return(true); }
private string[] GetExchangeResources(ADUser groupMailbox) { try { MailboxUrls mailboxUrls = new MailboxUrls(ExchangePrincipal.FromADUser(groupMailbox, RemotingOptions.AllowCrossSite), true); return(mailboxUrls.ToExchangeResources()); } catch (LocalizedException ex) { base.WriteVerbose("Failed to get MailboxUrls with exception: {0}", new object[] { ex }); this.WriteWarning(Strings.WarningUnableToUpdateExchangeResources); } return(null); }
private void Initialize() { MailboxUrls owaMailboxUrls = MailboxUrls.GetOwaMailboxUrls(this.groupPrincipal); EscalationLinkBuilder escalationLinkBuilder = new EscalationLinkBuilder(this.groupPrincipal, owaMailboxUrls); this.groupInboxUrl = WelcomeToGroupMessageTemplate.GetInboxUrlForGroupMailbox(owaMailboxUrls.InboxUrl); this.groupCalendarUrl = WelcomeToGroupMessageTemplate.GetCalendarUrlForGroupMailbox(owaMailboxUrls.CalendarUrl); this.subscribeUrl = escalationLinkBuilder.GetEscalationLink(EscalationLinkType.Subscribe); this.unsubscribeUrl = escalationLinkBuilder.GetEscalationLink(EscalationLinkType.Unsubscribe); this.groupSharePointUrl = (new SharePointUrlResolver(this.groupMailbox).GetDocumentsUrl() ?? string.Empty); this.groupPhoto = WelcomeToGroupMessageTemplate.GetADThumbnailPhoto(this.groupMailbox, WelcomeMessageBodyData.GroupPhotoImageId, WelcomeMessageBodyData.GroupPhotoImageId + ".jpg"); this.executingUserPhoto = WelcomeToGroupMessageTemplate.GetADThumbnailPhoto(this.executingUser, WelcomeMessageBodyData.UserPhotoImageId, WelcomeMessageBodyData.UserPhotoImageId + ".jpg"); if (this.executingUser != null) { WelcomeToGroupMessageTemplate.Tracer.TraceDebug((long)this.GetHashCode(), "WelcomeToGroupMessageTemplate.WelcomeToGroupMessageTemplate: Executing user is known. Setting Sender=Group, From-executingUser."); this.emailSender = new Participant(this.groupMailbox); this.emailFrom = new Participant(this.executingUser); this.encodedExecutingUserDisplayName = AntiXssEncoder.HtmlEncode(this.emailFrom.DisplayName, false); return; } WelcomeToGroupMessageTemplate.Tracer.TraceDebug((long)this.GetHashCode(), "WelcomeToGroupMessageTemplate.WelcomeToGroupMessageTemplate: Executing user is unknown. From-executingUser, sender won't be set."); this.emailFrom = new Participant(this.groupMailbox); }
protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject) { if (dataObject == null) { return(null); } ADUser aduser = (ADUser)dataObject; IRecipientSession recipientSession = (IRecipientSession)base.DataSession; GroupMailbox groupMailbox = GroupMailbox.FromDataObject(aduser); if ((this.IncludeMemberSyncStatus || this.IncludePermissionsVersion) && CmdletProxy.TryToProxyOutputObject(groupMailbox, base.CurrentTaskContext, aduser, false, this.ConfirmationMessage, CmdletProxy.AppendIdentityToProxyCmdlet(aduser))) { return(groupMailbox); } ExchangePrincipal exchangePrincipal = null; if (this.IncludeMailboxUrls) { try { exchangePrincipal = ExchangePrincipal.FromADUser(aduser, RemotingOptions.AllowCrossSite); MailboxUrls mailboxUrls = new MailboxUrls(exchangePrincipal, false); groupMailbox.InboxUrl = this.SuppressPiiDataAsNeeded(mailboxUrls.InboxUrl); groupMailbox.CalendarUrl = this.SuppressPiiDataAsNeeded(mailboxUrls.CalendarUrl); groupMailbox.PeopleUrl = this.SuppressPiiDataAsNeeded(mailboxUrls.PeopleUrl); groupMailbox.PhotoUrl = this.SuppressPiiDataAsNeeded(mailboxUrls.PhotoUrl); } catch (LocalizedException ex) { base.WriteWarning("Unable to get mailbox principal due exception: " + ex.Message); } } IdentityDetails[] ownersDetails = this.GetOwnersDetails(recipientSession, aduser); if (ownersDetails != null) { groupMailbox.OwnersDetails = ownersDetails; } ADRawEntry[] array = null; if (this.IncludeMembers) { array = this.GetMemberRawEntriesFromAD(recipientSession, aduser); IdentityDetails[] identityDetails = this.GetIdentityDetails(array); groupMailbox.MembersDetails = identityDetails; groupMailbox.Members = Array.ConvertAll <IdentityDetails, ADObjectId>(identityDetails, (IdentityDetails member) => member.Identity); } if (!this.IncludeMemberSyncStatus) { if (!this.IncludePermissionsVersion) { return(groupMailbox); } } try { if (exchangePrincipal == null) { exchangePrincipal = ExchangePrincipal.FromADUser(aduser, RemotingOptions.AllowCrossSite); } using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(exchangePrincipal, CultureInfo.InvariantCulture, "Client=Management;Action=Get-GroupMailbox")) { if (this.IncludeMemberSyncStatus) { if (array == null) { array = this.GetMemberRawEntriesFromAD(recipientSession, aduser); } ADObjectId[] membersInAD = Array.ConvertAll <ADRawEntry, ADObjectId>(array, (ADRawEntry member) => member.Id); ADObjectId[] membersFromMailbox = this.GetMembersFromMailbox(recipientSession, aduser, mailboxSession); groupMailbox.MembersSyncStatus = new GroupMailboxMembersSyncStatus(membersInAD, membersFromMailbox); if (base.NeedSuppressingPiiData) { groupMailbox.MembersSyncStatus.MembersInADOnly = SuppressingPiiData.Redact(groupMailbox.MembersSyncStatus.MembersInADOnly); groupMailbox.MembersSyncStatus.MembersInMailboxOnly = SuppressingPiiData.Redact(groupMailbox.MembersSyncStatus.MembersInMailboxOnly); } } if (this.IncludePermissionsVersion) { groupMailbox.PermissionsVersion = mailboxSession.Mailbox.GetValueOrDefault <int>(MailboxSchema.GroupMailboxPermissionsVersion, 0).ToString(); } } } catch (LocalizedException ex2) { base.WriteWarning("Unable to retrieve data from group mailbox due exception: " + ex2.Message); } return(groupMailbox); }
private void TryNotifySharePointForExchangeResources(MailboxUrls mailboxUrls) { OrganizationId orgId = this.groupADUser.OrganizationId; string externalDirectoryObjectId = this.groupADUser.ExternalDirectoryObjectId; Guid activityId = this.activityId; Stopwatch timer = Stopwatch.StartNew(); Task.Factory.StartNew(delegate() { ICredentials oauthCredentialsForAppToken = OAuthCredentials.GetOAuthCredentialsForAppToken(orgId, "dummyRealm"); using (SharePointNotification sharePointNotification = new SharePointNotification(SharePointNotification.NotificationType.Update, externalDirectoryObjectId, orgId, oauthCredentialsForAppToken, activityId)) { foreach (KeyValuePair <string, string> keyValuePair in mailboxUrls.ToExchangeResourcesDictionary()) { sharePointNotification.SetResourceValue(keyValuePair.Key, keyValuePair.Value, false); } sharePointNotification.Execute(); string value = string.Format("Success;Group={0};Org={1};ElapsedTime={2}", externalDirectoryObjectId, orgId, timer.ElapsedMilliseconds); FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.TraceTag> { { FederatedDirectoryLogSchema.TraceTag.TaskName, "UpdateSiteCollectionTask" }, { FederatedDirectoryLogSchema.TraceTag.ActivityId, activityId }, { FederatedDirectoryLogSchema.TraceTag.CurrentAction, "SharePointSetMailboxUrls" }, { FederatedDirectoryLogSchema.TraceTag.Message, value } }); } }).ContinueWith(delegate(Task t) { Exception ex = null; if (t.Exception != null) { ex = t.Exception.InnerException; } string value = string.Format("Failed;Group={0};Org={1};ElapsedTime={2}", externalDirectoryObjectId, orgId, timer.ElapsedMilliseconds); FederatedDirectoryLogger.AppendToLog(new SchemaBasedLogEvent <FederatedDirectoryLogSchema.ExceptionTag> { { FederatedDirectoryLogSchema.ExceptionTag.TaskName, "UpdateSiteCollectionTask" }, { FederatedDirectoryLogSchema.ExceptionTag.ActivityId, activityId }, { FederatedDirectoryLogSchema.ExceptionTag.CurrentAction, "SharePointSetMailboxUrls" }, { FederatedDirectoryLogSchema.ExceptionTag.ExceptionType, (ex != null) ? ex.GetType().ToString() : "Unknown" }, { FederatedDirectoryLogSchema.ExceptionTag.ExceptionDetail, ex }, { FederatedDirectoryLogSchema.ExceptionTag.Message, value } }); }, TaskContinuationOptions.OnlyOnFaulted); }
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); }
public static void WriteMessageToStream(StreamWriter writer, string senderDisplayName, string groupDisplayName, string attachedMessageBody, MailboxUrls mailboxUrls, CultureInfo cultureInfo) { writer.Write(GroupJoinRequestMessageBodyBuilder.RenderTemplate(senderDisplayName, groupDisplayName, attachedMessageBody, GroupJoinRequestMessageBodyBuilder.ConvertFragmentToQuery(mailboxUrls.PeopleUrl), cultureInfo)); }