protected override SharingBindingData CreateDataObjectFromItem(object[] properties) { VersionedId versionedId = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <VersionedId>(properties, 1); if (versionedId == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal>((long)this.GetHashCode(), "{0}: Binding is missing ID", this.mailboxSession.MailboxOwner); return(null); } string text = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 12); if (text == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing sharingLocalType", this.mailboxSession.MailboxOwner, versionedId); return(null); } SharingDataType sharingDataType = SharingDataType.FromContainerClass(text); if (sharingDataType == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId, string>((long)this.GetHashCode(), "{0}: Binding {1} has invalid sharingLocalType: {2}", this.mailboxSession.MailboxOwner, versionedId, text); return(null); } string text2 = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 8); if (text2 == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing initiatorName", this.mailboxSession.MailboxOwner, versionedId); return(null); } string text3 = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 9); if (text3 == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing initiatorSmtpAddress", this.mailboxSession.MailboxOwner, versionedId); return(null); } string text4 = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 7); if (text4 == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing remoteFolderName", this.mailboxSession.MailboxOwner, versionedId); return(null); } string text5 = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 18); if (text5 == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing remoteFolderId", this.mailboxSession.MailboxOwner, versionedId); return(null); } string text6 = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 10); if (text6 == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing localFolderName", this.mailboxSession.MailboxOwner, versionedId); return(null); } string text7 = SharingItemManagerBase <SharingBindingData> .TryGetPropertyRef <string>(properties, 11); if (text7 == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing localFolderUid", this.mailboxSession.MailboxOwner, versionedId); return(null); } StoreObjectId localFolderId; try { localFolderId = StoreObjectId.FromHexEntryId(text7, sharingDataType.StoreObjectType); } catch (CorruptDataException) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} has invalid localFolderUid", this.mailboxSession.MailboxOwner, versionedId); return(null); } int?num = SharingItemManagerBase <SharingBindingData> .TryGetPropertyVal <int>(properties, 3); if (num == null) { ExTraceGlobals.SharingTracer.TraceError <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing flavor", this.mailboxSession.MailboxOwner, versionedId); return(null); } bool isDefaultFolderShared = 0 != (num.Value & 131072); DateTime? lastSyncTimeUtc = null; ExDateTime?exDateTime = SharingItemManagerBase <SharingBindingData> .TryGetPropertyVal <ExDateTime>(properties, 15); if (exDateTime == null) { ExTraceGlobals.SharingTracer.TraceDebug <IExchangePrincipal, VersionedId>((long)this.GetHashCode(), "{0}: Binding {1} is missing lastSyncTime", this.mailboxSession.MailboxOwner, versionedId); } else { lastSyncTimeUtc = new DateTime?((DateTime)exDateTime.Value.ToUtc()); } return(new SharingBindingData(versionedId, sharingDataType, text2, text3, text4, text5, text6, localFolderId, isDefaultFolderShared, lastSyncTimeUtc)); }
private void ReadFromMessageProperties(MessageItem messageItem) { SharingFlavor?valueAsNullable = messageItem.GetValueAsNullable <SharingFlavor>(InternalSchema.SharingFlavor); if (valueAsNullable == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingFlavor is missing", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingFlavor"); } this.context.SharingFlavor = valueAsNullable.Value; SharingCapabilities?valueAsNullable2 = messageItem.GetValueAsNullable <SharingCapabilities>(InternalSchema.SharingCapabilities); if (valueAsNullable2 == null) { ExTraceGlobals.SharingTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}: SharingCapabilities is missing, use default value", messageItem.Session.UserLegacyDN); this.context.SetDefaultCapabilities(); } else { this.context.SharingCapabilities = valueAsNullable2.Value; } string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.SharingInitiatorName, null); if (valueOrDefault == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingInitiatorName is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingInitiatorName"); } this.context.InitiatorName = valueOrDefault; string valueOrDefault2 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingInitiatorSmtp, null); if (valueOrDefault2 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingInitiatorSmtp is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingInitiatorSmtp"); } if (!SmtpAddress.IsValidSmtpAddress(valueOrDefault2)) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingInitiatorSmtp is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault2); throw new InvalidSharingMessageException("SharingInitiatorSmtp"); } this.context.InitiatorSmtpAddress = valueOrDefault2; byte[] valueOrDefault3 = messageItem.GetValueOrDefault <byte[]>(InternalSchema.SharingInitiatorEntryId, null); if (valueOrDefault3 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingInitiatorEntryId is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingInitiatorEntryId"); } if (!AddressBookEntryId.IsAddressBookEntryId(valueOrDefault3)) { ExTraceGlobals.SharingTracer.TraceError <string, byte[]>((long)this.GetHashCode(), "{0}: SharingInitiatorEntryId is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault3); throw new InvalidSharingMessageException("SharingInitiatorEntryId"); } this.context.InitiatorEntryId = valueOrDefault3; string valueOrDefault4 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteType, null); if (valueOrDefault4 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteType is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingRemoteType"); } if (SharingDataType.FromContainerClass(valueOrDefault4) == null) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingRemoteType is invalid: {1}.", messageItem.Session.UserLegacyDN, valueOrDefault4); throw new InvalidSharingMessageException("SharingRemoteType"); } this.context.FolderClass = valueOrDefault4; string valueOrDefault5 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteName, null); if (valueOrDefault5 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteName is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingRemoteName"); } this.context.FolderName = valueOrDefault5; string valueOrDefault6 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteUid, null); if (valueOrDefault6 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteUid is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingRemoteUid"); } try { this.context.FolderId = StoreObjectId.FromHexEntryId(valueOrDefault6, ObjectClass.GetObjectType(valueOrDefault4)); } catch (CorruptDataException) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingRemoteUid is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault6); throw new InvalidSharingMessageException("SharingRemoteUid"); } string valueOrDefault7 = messageItem.GetValueOrDefault <string>(InternalSchema.SharingRemoteStoreUid, null); if (valueOrDefault7 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingRemoteStoreUid is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingRemoteStoreUid"); } byte[] array = null; try { array = HexConverter.HexStringToByteArray(valueOrDefault7); } catch (FormatException) { } if (array == null || StoreEntryId.TryParseStoreEntryIdMailboxDN(array) == null) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: SharingRemoteStoreUid is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault7); throw new InvalidSharingMessageException("SharingRemoteStoreUid"); } this.context.MailboxId = array; SharingContextPermissions?valueAsNullable3 = messageItem.GetValueAsNullable <SharingContextPermissions>(InternalSchema.SharingPermissions); if (valueAsNullable3 != null) { this.context.SharingPermissions = valueAsNullable3.Value; } SharingContextDetailLevel?valueAsNullable4 = messageItem.GetValueAsNullable <SharingContextDetailLevel>(InternalSchema.SharingDetail); if (valueAsNullable4 != null) { this.context.SharingDetail = valueAsNullable4.Value; return; } if (this.context.DataType == SharingDataType.Calendar) { this.context.SharingDetail = SharingContextDetailLevel.FullDetails; } }
private void ReadFromMessageXProperties(MessageItem messageItem) { string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingFlavor, null); if (valueOrDefault == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingFlavor is missing", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("XSharingFlavor"); } try { this.context.SharingFlavor = (SharingFlavor)int.Parse(valueOrDefault, NumberStyles.HexNumber); } catch (FormatException) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: XSharingFlavor is invalid: {1}", messageItem.Session.UserLegacyDN, valueOrDefault); throw new InvalidSharingMessageException("XSharingFlavor"); } string valueOrDefault2 = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingRemoteType, null); if (valueOrDefault2 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingRemoteType is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("XSharingRemoteType"); } if (SharingDataType.FromPublishName(valueOrDefault2) == null) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: XSharingRemoteType is invalid: {1}.", messageItem.Session.UserLegacyDN, valueOrDefault2); throw new InvalidSharingMessageException("XSharingRemoteType"); } string valueOrDefault3 = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingLocalType, null); if (valueOrDefault3 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingLocalType is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("XSharingLocalType"); } if (SharingDataType.FromContainerClass(valueOrDefault3) == null) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: XSharingLocalType is invalid: {1}.", messageItem.Session.UserLegacyDN, valueOrDefault3); throw new InvalidSharingMessageException("XSharingLocalType"); } this.context.FolderClass = valueOrDefault3; string valueOrDefault4 = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingRemoteName, null); if (valueOrDefault4 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingRemoteName is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("XSharingRemoteName"); } this.context.FolderName = valueOrDefault4; Uri uri = null; string valueOrDefault5 = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingBrowseUrl, null); if (string.IsNullOrEmpty(valueOrDefault5)) { ExTraceGlobals.SharingTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}: XSharingBrowseUrl is missing or empty.", messageItem.Session.UserLegacyDN); } else { if (!PublishingUrl.IsAbsoluteUriString(valueOrDefault5, out uri)) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: XSharingBrowseUrl is not well formed : {1}", messageItem.Session.UserLegacyDN, valueOrDefault5); throw new InvalidSharingMessageException("XSharingBrowseUrl"); } this.context.BrowseUrl = valueOrDefault5; } string valueOrDefault6 = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingRemotePath, null); if (valueOrDefault6 == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingRemotePath is missing.", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("XSharingRemotePath"); } if (!PublishingUrl.IsAbsoluteUriString(valueOrDefault6, out uri)) { ExTraceGlobals.SharingTracer.TraceError <string, string>((long)this.GetHashCode(), "{0}: XSharingRemotePath is not well formed : {1}", messageItem.Session.UserLegacyDN, valueOrDefault6); throw new InvalidSharingMessageException("XSharingRemotePath"); } this.context.ICalUrl = valueOrDefault6; }
public EncryptionResults Encrypt(IExchangePrincipal mailboxOwner, IRecipientSession recipientSession, ExternalUserCollection externalUserCollection, ValidRecipient[] recipients, string sender, string containerClass, string folderId, IFrontEndLocator frontEndLocator) { SharingDataType sharingDataType = SharingDataType.FromContainerClass(containerClass); if (sharingDataType == null || !sharingDataType.IsExternallySharable) { throw new ArgumentOutOfRangeException("containerClass"); } ADUser aduser = DirectoryHelper.ReadADRecipient(mailboxOwner.MailboxInfo.MailboxGuid, mailboxOwner.MailboxInfo.IsArchive, recipientSession) as ADUser; if (aduser == null) { SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption, string>((long)this.GetHashCode(), "{0}: The Active Directory user was not found. Sender={1}.", this, sender); throw new ObjectNotFoundException(ServerStrings.ADUserNotFound); } ProxyAddress item = new SmtpProxyAddress(sender, false); if (!aduser.EmailAddresses.Contains(item)) { SharedFolderDataEncryption.Tracer.TraceError <SharedFolderDataEncryption, string>((long)this.GetHashCode(), "{0}: The SMTP address was not found in the user AD object for this mailbox. Sender={1}.", this, sender); throw new ObjectNotFoundException(ServerStrings.ADUserNotFound); } SharingPolicy sharingPolicy = DirectoryHelper.ReadSharingPolicy(mailboxOwner.MailboxInfo.MailboxGuid, mailboxOwner.MailboxInfo.IsArchive, recipientSession); SharedFolderDataEncryption.Tracer.TraceDebug <SharedFolderDataEncryption, object>((long)this.GetHashCode(), "{0}: Sharing policy to be applied to this user: {1}", this, (sharingPolicy == null) ? "<null>" : sharingPolicy.Id); SharingPolicyAction sharingPolicyActions = SharedFolderDataEncryption.GetSharingPolicyActions(sharingDataType.StoreObjectType); SharedFolderDataRecipient[] externalIdentities = SharedFolderDataEncryption.GetExternalIdentities(externalUserCollection, recipients); List <InvalidRecipient> list = new List <InvalidRecipient>(); Dictionary <TokenTarget, List <SharedFolderDataRecipient> > dictionary = new Dictionary <TokenTarget, List <SharedFolderDataRecipient> >(externalIdentities.Length, SharedFolderDataEncryption.TokenTargetComparer); for (int i = 0; i < recipients.Length; i++) { SharedFolderDataRecipient item2 = externalIdentities[i]; ValidRecipient validRecipient = recipients[i]; SmtpAddress smtpAddress = new SmtpAddress(validRecipient.SmtpAddress); string domain = smtpAddress.Domain; if (sharingPolicy == null || !sharingPolicy.IsAllowedForAnySharing(domain, sharingPolicyActions)) { SharedFolderDataEncryption.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Sharing policy does not allow user to share with domain {0}", domain); list.Add(new InvalidRecipient(validRecipient.SmtpAddress, InvalidRecipientResponseCodeType.SystemPolicyBlocksSharingWithThisRecipient)); } else { SmtpAddress smtpAddress2 = new SmtpAddress(validRecipient.SmtpAddressForEncryption); TokenTarget tokenTarget = TargetUriResolver.Resolve(smtpAddress2.Domain, aduser.OrganizationId); if (tokenTarget == null) { list.Add(new InvalidRecipient(validRecipient.SmtpAddress, InvalidRecipientResponseCodeType.RecipientOrganizationNotFederated)); } else { List <SharedFolderDataRecipient> list2; if (!dictionary.TryGetValue(tokenTarget, out list2)) { list2 = new List <SharedFolderDataRecipient>(1); dictionary.Add(tokenTarget, list2); } list2.Add(item2); } } } List <EncryptedSharedFolderData> list3 = new List <EncryptedSharedFolderData>(dictionary.Count); SharedFolderData sharedFolderData = new SharedFolderData(); sharedFolderData.DataType = sharingDataType.ExternalName; sharedFolderData.FolderId = folderId; sharedFolderData.SharingUrl = this.GetSharingUrl(aduser, frontEndLocator); sharedFolderData.FederationUri = this.externalAuthentication.TokenValidator.TargetUri.ToString(); sharedFolderData.SenderSmtpAddress = sender; DelegationTokenRequest delegationTokenRequest = new DelegationTokenRequest { FederatedIdentity = aduser.GetFederatedIdentity(), EmailAddress = aduser.GetFederatedSmtpAddress(new SmtpAddress(sender)).ToString(), Offer = Offer.SharingInviteMessage }; SecurityTokenService securityTokenService = this.externalAuthentication.GetSecurityTokenService(aduser.OrganizationId); foreach (KeyValuePair <TokenTarget, List <SharedFolderDataRecipient> > keyValuePair in dictionary) { delegationTokenRequest.Target = keyValuePair.Key; sharedFolderData.Recipients = keyValuePair.Value.ToArray(); try { RequestedToken requestedToken = securityTokenService.IssueToken(delegationTokenRequest); list3.Add(this.Encrypt(requestedToken, sharedFolderData)); } catch (WSTrustException ex) { foreach (SharedFolderDataRecipient sharedFolderDataRecipient in sharedFolderData.Recipients) { list.Add(new InvalidRecipient(sharedFolderDataRecipient.SmtpAddress, SharedFolderDataEncryption.GetResponseCodeFromException(ex), ex.ToString())); } } } return(new EncryptionResults(list3.ToArray(), list.ToArray())); }
protected override bool InternalValidateCompatibility(Folder folderToShare) { return(SharingDataType.FromContainerClass(folderToShare.ClassName) != null); }
protected override bool InternalValidateCompatibility(Folder folderToShare) { SharingDataType sharingDataType = SharingDataType.FromContainerClass(folderToShare.ClassName); return(sharingDataType != null && sharingDataType.IsExternallySharable); }