internal override void ParseSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider) { if (!AddressBookEntryId.IsAddressBookEntryId(context.InitiatorEntryId)) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: InitiatorEntryId is invalid.", context.UserLegacyDN); throw new InvalidSharingDataException("InitiatorEntryId", HexConverter.ByteArrayToHexString(context.InitiatorEntryId)); } if (!string.IsNullOrEmpty(sharingMessageProvider.FolderId)) { try { context.FolderId = StoreObjectId.FromHexEntryId(sharingMessageProvider.FolderId, ObjectClass.GetObjectType(context.FolderClass)); } catch (CorruptDataException) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: FolderId is invalid: {1}", context.UserLegacyDN, sharingMessageProvider.FolderId); throw new InvalidSharingDataException("FolderId", sharingMessageProvider.FolderId); } } if (!string.IsNullOrEmpty(sharingMessageProvider.MailboxId)) { byte[] array = HexConverter.HexStringToByteArray(sharingMessageProvider.MailboxId); if (StoreEntryId.TryParseStoreEntryIdMailboxDN(array) == null) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: MailboxId is invalid: {1}", context.UserLegacyDN, sharingMessageProvider.MailboxId); throw new InvalidSharingDataException("MailboxId", sharingMessageProvider.MailboxId); } context.MailboxId = array; } }
private FreeBusyAccess?GetFreeBusy(SharingContext context) { if (context.DataType != SharingDataType.Calendar) { return(null); } SharingContextDetailLevel sharingDetail = context.SharingDetail; switch (sharingDetail) { case SharingContextDetailLevel.AvailabilityOnly: return(new FreeBusyAccess?(FreeBusyAccess.Basic)); case SharingContextDetailLevel.Limited: case SharingContextDetailLevel.FullDetails: break; case (SharingContextDetailLevel)3: goto IL_48; default: if (sharingDetail != SharingContextDetailLevel.Editor) { goto IL_48; } break; } return(new FreeBusyAccess?(FreeBusyAccess.Details)); IL_48: throw new ArgumentOutOfRangeException("context"); }
private SharedFolderData GetMatchingSharedFolderData(SharingContext context, ADRecipient mailboxOwner) { SharedFolderDataEncryption sharedFolderDataEncryption = new SharedFolderDataEncryption(ExternalAuthentication.GetCurrent()); bool flag = false; ExTraceGlobals.SharingTracer.TraceDebug <ADRecipient>((long)this.GetHashCode(), "{0}: Decrypting the encrypted shared folder data.", mailboxOwner); foreach (EncryptedSharedFolderData encryptedSharedFolderData in context.EncryptedSharedFolderDataCollection) { SharedFolderData sharedFolderData = sharedFolderDataEncryption.TryDecrypt(encryptedSharedFolderData); if (sharedFolderData != null) { if (SharingProviderHandlerExternal.TryFindMatchingRecipient(sharedFolderData, mailboxOwner) != null) { ExTraceGlobals.SharingTracer.TraceDebug <ADRecipient>((long)this.GetHashCode(), "{0}: Get the decrypted shared folder data.", mailboxOwner); return(sharedFolderData); } flag = true; } } ExTraceGlobals.SharingTracer.TraceError <ADRecipient>((long)this.GetHashCode(), "{0}: Failed to decrypt shared folder data.", mailboxOwner); if (flag) { throw new InvalidExternalSharingSubscriberException(); } throw new InvalidSharingDataException("SharedFolderData", string.Empty); }
internal override void ParseSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider) { Uri uri = null; if (!PublishingUrl.IsAbsoluteUriString(sharingMessageProvider.BrowseUrl, out uri)) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: BrowseUrl is invalid: {1}", context.UserLegacyDN, sharingMessageProvider.BrowseUrl); throw new InvalidSharingDataException("BrowseUrl", sharingMessageProvider.BrowseUrl); } context.BrowseUrl = sharingMessageProvider.BrowseUrl; if (context.DataType == SharingDataType.Calendar) { if (string.IsNullOrEmpty(sharingMessageProvider.ICalUrl)) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: ICalUrl is missing: {1}", context.UserLegacyDN, sharingMessageProvider.ICalUrl); throw new InvalidSharingDataException("ICalUrl", string.Empty); } if (!PublishingUrl.IsAbsoluteUriString(sharingMessageProvider.ICalUrl, out uri)) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: ICalUrl is invalid: {1}", context.UserLegacyDN, sharingMessageProvider.ICalUrl); throw new InvalidSharingDataException("ICalUrl", sharingMessageProvider.ICalUrl); } context.ICalUrl = sharingMessageProvider.ICalUrl; } }
private PermissionLevel GetPermissionLevel(SharingContext context) { SharingContextPermissions sharingPermissions = context.SharingPermissions; if (sharingPermissions != SharingContextPermissions.Reviewer) { if (sharingPermissions != SharingContextPermissions.Editor) { throw new ArgumentOutOfRangeException("context"); } if (!context.IsPrimary) { return(PermissionLevel.Editor); } if (context.DataType == SharingDataType.Calendar || context.SharingDetail == SharingContextDetailLevel.Editor) { return(PermissionLevel.Editor); } throw new NotSupportedException("Cannot retrieve permission level when having an editor on defualt non calendar folder"); } else { if (context.DataType != SharingDataType.Calendar || context.SharingDetail == SharingContextDetailLevel.FullDetails) { return(PermissionLevel.Reviewer); } return(PermissionLevel.None); } }
private PermissionLevel GetPermissionLevel(SharingContext context) { if (context.DataType != SharingDataType.Calendar || context.SharingDetail == SharingContextDetailLevel.FullDetails || context.SharingDetail == SharingContextDetailLevel.Editor) { return(PermissionLevel.Reviewer); } return(PermissionLevel.None); }
private PublishingSubscriptionData CreateSubscriptionData(SharingContext context) { if (context.ICalUrl == null) { throw new InvalidSharingDataException("ICalUrl", string.Empty); } return(new PublishingSubscriptionData(context.DataType.PublishName, new Uri(context.ICalUrl, UriKind.Absolute), context.FolderName, null)); }
internal SharingMessageProvider CreateSharingMessageProvider(SharingContext context) { Util.ThrowOnNullArgument(context, "context"); SharingMessageProvider sharingMessageProvider = this.CreateSharingMessageProvider(); this.sharingProviderHandler.FillSharingMessageProvider(context, sharingMessageProvider); return(sharingMessageProvider); }
internal override void FillSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider) { sharingMessageProvider.BrowseUrl = context.BrowseUrl.ToString(); if (context.ICalUrl != null) { sharingMessageProvider.ICalUrl = context.ICalUrl.ToString(); } }
internal CheckRecipientsResults CheckRecipients(ADRecipient mailboxOwner, SharingContext context, string[] recipients) { Util.ThrowOnNullArgument(context, "context"); CheckRecipientsResults checkRecipientsResults = this.sharingProviderHandler.CheckRecipients(mailboxOwner, recipients); context.AvailableSharingProviders[this] = checkRecipientsResults; return(checkRecipientsResults); }
internal SubscribeResults PerformSubscribe(MailboxSession mailboxSession, SharingContext context) { Util.ThrowOnNullArgument(mailboxSession, "mailboxSession"); Util.ThrowOnNullArgument(context, "context"); if (!context.SharingMessageType.IsInvitationOrAcceptOfRequest) { throw new InvalidOperationException("Only can subscribe on invitation or acceptofrequest message."); } return(this.InternalPerformSubscribe(mailboxSession, context)); }
internal void PerformRevocation(MailboxSession mailboxSession, SharingContext context) { Util.ThrowOnNullArgument(mailboxSession, "mailboxSession"); Util.ThrowOnNullArgument(context, "context"); if (!context.SharingMessageType.IsRequest) { throw new InvalidOperationException("Only can revoke on request message."); } context.FolderId = mailboxSession.GetDefaultFolderId(context.DataType.DefaultFolderType); this.InternalPerformRevocation(mailboxSession, context); }
private FreeBusyAccess GetFreeBusy(SharingContext context) { switch (context.SharingDetail) { case SharingContextDetailLevel.AvailabilityOnly: return(FreeBusyAccess.Basic); case SharingContextDetailLevel.Limited: return(FreeBusyAccess.Details); case SharingContextDetailLevel.FullDetails: return(FreeBusyAccess.Details); } throw new ArgumentOutOfRangeException("context"); }
private FolderPermissionContext(MailboxSession mailboxSession, SharingContext sharingContext) { Util.ThrowOnNullArgument(mailboxSession, "mailboxSession"); Util.ThrowOnNullArgument(sharingContext, "sharingContext"); Util.ThrowOnNullArgument(sharingContext.FolderId, "sharingContext.FolderId"); if (FolderPermissionContext.activeContexts.ContainsKey(sharingContext)) { throw new InvalidOperationException("FolderPermissionContext has been created for this SharingContext."); } this.disposeTracker = this.GetDisposeTracker(); this.mailboxSession = mailboxSession; this.sharingContext = sharingContext; this.folderId = sharingContext.FolderId; this.permissionsToAddOrChange = new Dictionary <PermissionSecurityPrincipal, MemberRights>(); this.permissionsToRemove = new HashSet <PermissionSecurityPrincipal>(); this.refCount = 0; FolderPermissionContext.activeContexts.Add(sharingContext, this); }
internal abstract void ParseSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider);
protected abstract SubscribeResults InternalPerformSubscribe(MailboxSession mailboxSession, SharingContext context);
internal SharingContextSerializerLegacy(SharingContext context) { Util.ThrowOnNullArgument(context, "context"); this.context = context; }
internal SubscribeResults PerformSubscribe(MailboxSession mailboxSession, SharingContext context) { return(this.sharingProviderHandler.PerformSubscribe(mailboxSession, context)); }
protected override void InternalPerformRevocation(MailboxSession mailboxSession, SharingContext context) { using (FolderPermissionContext current = FolderPermissionContext.GetCurrent(mailboxSession, context)) { ValidRecipient recipient = new ValidRecipient(context.InitiatorSmtpAddress, null); PermissionSecurityPrincipal principal = this.CreatePermissionSecurityPrincipal(recipient, mailboxSession.MailboxOwner); current.RemovePermission(principal); } }
protected abstract void InternalPerformRevocation(MailboxSession mailboxSession, SharingContext context);
protected override PerformInvitationResults InternalPerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator) { PermissionLevel permissionLevel = this.GetPermissionLevel(context); FreeBusyAccess? freeBusy = this.GetFreeBusy(context); using (FolderPermissionContext current = FolderPermissionContext.GetCurrent(mailboxSession, context)) { foreach (ValidRecipient recipient in recipients) { PermissionSecurityPrincipal principal = this.CreatePermissionSecurityPrincipal(recipient, mailboxSession.MailboxOwner); current.AddOrChangePermission(principal, permissionLevel, freeBusy); } } return(new PerformInvitationResults(recipients)); }
protected override PerformInvitationResults InternalPerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator) { ExternalAuthentication current = ExternalAuthentication.GetCurrent(); if (!current.Enabled) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: The organization is not federated for external sharing.", context.InitiatorSmtpAddress); return(new PerformInvitationResults(new InvalidSharingRecipientsException(ValidRecipient.ConvertToStringArray(recipients), new OrganizationNotFederatedException()))); } SharedFolderDataEncryption sharedFolderDataEncryption = new SharedFolderDataEncryption(current); string text = StoreId.StoreIdToEwsId(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, context.FolderId); PerformInvitationResults result; using (ExternalUserCollection externalUsers = mailboxSession.GetExternalUsers()) { PerformInvitationResults performInvitationResults = null; EncryptionResults encryptionResults = null; Exception ex = null; try { encryptionResults = sharedFolderDataEncryption.Encrypt(mailboxSession.MailboxOwner, mailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid), externalUsers, recipients, context.InitiatorSmtpAddress, context.FolderClass, text, frontEndLocator); } catch (UserWithoutFederatedProxyAddressException ex2) { ex = ex2; } catch (InvalidFederatedOrganizationIdException ex3) { ex = ex3; } catch (StoragePermanentException ex4) { ex = ex4; } if (ex != null) { ExTraceGlobals.SharingTracer.TraceError <string, Exception>((long)this.GetHashCode(), "{0}: Error occurred when trying to encrypt. Exception = {1}", context.InitiatorSmtpAddress, ex); result = new PerformInvitationResults(new InvalidSharingRecipientsException(ValidRecipient.ConvertToStringArray(recipients), ex)); } else { if (encryptionResults.InvalidRecipients != null && encryptionResults.InvalidRecipients.Length > 0) { InvalidSharingRecipientsException exception = new InvalidSharingRecipientsException(encryptionResults.InvalidRecipients); if (encryptionResults.InvalidRecipients.Length == recipients.Length) { return(new PerformInvitationResults(exception)); } performInvitationResults = new PerformInvitationResults(recipients, exception); recipients = performInvitationResults.SucceededRecipients; } else { performInvitationResults = new PerformInvitationResults(recipients); } PermissionLevel permissionLevel = this.GetPermissionLevel(context); FreeBusyAccess? freeBusy = this.GetFreeBusy(context); using (FolderPermissionContext current2 = FolderPermissionContext.GetCurrent(mailboxSession, context)) { foreach (ValidRecipient validRecipient in recipients) { PermissionSecurityPrincipal principal = this.CreatePermissionSecurityPrincipal(validRecipient.SmtpAddress, externalUsers); current2.AddOrChangePermission(principal, permissionLevel, freeBusy); ExternalUser externalUser = externalUsers.FindReachUserWithOriginalSmtpAddress(new SmtpAddress(validRecipient.SmtpAddress)); if (externalUser != null) { current2.RemovePermission(new PermissionSecurityPrincipal(externalUser)); } } } context.FolderEwsId = text; context.EncryptedSharedFolderDataCollection = encryptionResults.EncryptedSharedFolderDataCollection; result = performInvitationResults; } } return(result); }
internal override void FillSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider) { sharingMessageProvider.FolderId = context.FolderId.ToHexEntryId(); sharingMessageProvider.MailboxId = HexConverter.ByteArrayToHexString(context.MailboxId); }
protected abstract PerformInvitationResults InternalPerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator);
internal PerformInvitationResults PerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator) { Util.ThrowOnNullArgument(mailboxSession, "mailboxSession"); Util.ThrowOnNullArgument(context, "context"); Util.ThrowOnNullArgument(recipients, "recipients"); Util.ThrowOnNullArgument(frontEndLocator, "frontEndLocator"); if (recipients.Length == 0) { return(PerformInvitationResults.Ignored); } if (!context.SharingMessageType.IsInvitationOrAcceptOfRequest) { return(PerformInvitationResults.Ignored); } return(this.InternalPerformInvitation(mailboxSession, context, recipients, frontEndLocator)); }
internal PerformInvitationResults PerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator) { return(this.sharingProviderHandler.PerformInvitation(mailboxSession, context, recipients, frontEndLocator)); }
internal void PerformRevocation(MailboxSession mailboxSession, SharingContext context) { this.sharingProviderHandler.PerformRevocation(mailboxSession, context); }
protected override SubscribeResults InternalPerformSubscribe(MailboxSession mailboxSession, SharingContext context) { return(new SubscribeResultsInternal(context.DataType, context.InitiatorSmtpAddress, context.InitiatorName, context.FolderName, context.FolderId, context.MailboxId)); }
internal static FolderPermissionContext GetCurrent(MailboxSession mailboxSession, SharingContext sharingContext) { FolderPermissionContext folderPermissionContext; if (!FolderPermissionContext.activeContexts.ContainsKey(sharingContext)) { ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingContext>(0L, "{0}: Create new FolderPermissionContext for SharingContext {1}.", mailboxSession.MailboxOwner, sharingContext); folderPermissionContext = new FolderPermissionContext(mailboxSession, sharingContext); } else { ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, SharingContext>(0L, "{0}: Get existing FolderPermissionContext for SharingContext {1}.", mailboxSession.MailboxOwner, sharingContext); folderPermissionContext = FolderPermissionContext.activeContexts[sharingContext]; } folderPermissionContext.refCount++; folderPermissionContext.enabled = true; return(folderPermissionContext); }
internal void ParseSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider) { Util.ThrowOnNullArgument(context, "context"); Util.ThrowOnNullArgument(sharingMessageProvider, "sharingMessageProvider"); this.sharingProviderHandler.ParseSharingMessageProvider(context, sharingMessageProvider); }