Example #1
0
        protected override void StampItemFromDataObject(Item item, SharingBindingData bindingData)
        {
            item[BindingItemSchema.SharingInitiatorName]  = bindingData.InitiatorName;
            item[BindingItemSchema.SharingInitiatorSmtp]  = bindingData.InitiatorSmtpAddress;
            item[BindingItemSchema.SharingRemoteName]     = bindingData.RemoteFolderName;
            item[BindingItemSchema.SharingRemoteFolderId] = bindingData.RemoteFolderId;
            item[BindingItemSchema.SharingLocalName]      = bindingData.LocalFolderName;
            if (bindingData.LastSyncTimeUtc != null)
            {
                item[BindingItemSchema.SharingLastSync] = new ExDateTime(ExTimeZone.UtcTimeZone, bindingData.LastSyncTimeUtc.Value.ToUniversalTime());
            }
            item[BindingItemSchema.SharingRemoteType] = (item[BindingItemSchema.SharingLocalType] = bindingData.DataType.ContainerClass);
            StoreObjectId storeObjectId = StoreId.GetStoreObjectId(bindingData.LocalFolderId);

            bindingData.LocalFolderId = storeObjectId;
            item[BindingItemSchema.SharingLocalUid]         = storeObjectId.ToHexEntryId();
            item[BindingItemSchema.SharingLocalFolderEwsId] = StoreId.StoreIdToEwsId(this.mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, storeObjectId);
            int num = 11;

            if (bindingData.IsDefaultFolderShared)
            {
                num |= 131072;
            }
            item[BindingItemSchema.SharingFlavor]       = num;
            item[BindingItemSchema.SharingRoamLog]      = SharingContextRoamLog.UnroamedBinding;
            item[BindingItemSchema.SharingStatus]       = SharingContextStatus.Configured;
            item[BindingItemSchema.SharingProviderGuid] = SharingBindingManager.ExternalSharingProviderGuid;
            item[BindingItemSchema.SharingProviderName] = "Microsoft Exchange";
            item[BindingItemSchema.SharingProviderUrl]  = "http://www.microsoft.com/exchange/";
            item[StoreObjectSchema.ItemClass]           = "IPM.Sharing.Binding.In";
        }
Example #2
0
        private static string[] GetPropertyValueToSave(MailboxSession mailboxSession, StoreId sourceFolderId, OwaViewFilter viewFilter, string fromFilter)
        {
            List <string> list = new List <string>();
            string        item = string.Empty;

            try
            {
                item = StoreId.StoreIdToEwsId(mailboxSession.MailboxGuid, sourceFolderId);
            }
            catch (Exception)
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "[OwaFilterState::GetPropertyValueToSave] id of property was not valid EWS id");
                return(null);
            }
            int    num  = (int)viewFilter;
            string text = (!string.IsNullOrEmpty(fromFilter)) ? (':' + fromFilter) : string.Empty;

            list.Add(item);
            list.Add(string.Concat(new object[]
            {
                num.ToString(),
                ':',
                15.1,
                text
            }));
            return(list.ToArray());
        }
Example #3
0
        private static string GetOwaFilteredViewSearchFolderName(MailboxSession mailboxSession, OwaSearchContext searchContext)
        {
            string text  = StoreId.StoreIdToEwsId(mailboxSession.MailboxGuid, searchContext.FolderIdToSearch);
            string text2 = (!string.IsNullOrEmpty(searchContext.FromFilter)) ? searchContext.FromFilter.GetHashCode().ToString("X") : string.Empty;

            return(string.Concat(new object[]
            {
                "OwaFV",
                15.1,
                searchContext.ViewFilter,
                text2,
                text
            }));
        }
Example #4
0
        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);
        }
        private static void SyncInternal(MailboxSession mailboxSession, ExDateTime lastSyncTime, StoreId folderId, string folderDisplayname, SecurityAccessToken securityAccessToken)
        {
            RefreshSharingFolderClient.Tracer.TraceDebug <string, IExchangePrincipal>(0L, "Sync sharing folder {0} from mailbox {1}", folderDisplayname, mailboxSession.MailboxOwner);
            if (!RefreshSharingFolderClient.CanSyncNow(lastSyncTime))
            {
                return;
            }
            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                RefreshSharingFolderClient.Tracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due exception {0}", NetworkServiceImpersonator.Exception);
                return;
            }
            string id = StoreId.StoreIdToEwsId(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, folderId);
            IList <WebServicesService> list;

            try
            {
                ClientAccessType clientAccessType = RefreshSharingFolderClient.ClientAccessType;
                RefreshSharingFolderClient.Tracer.TraceDebug <ClientAccessType>(0L, "Will try to discover the URL for EWS with the following client access type: {0}", clientAccessType);
                ServiceTopology currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\RefreshSharingFolderClient.cs", "SyncInternal", 153);
                list = currentServiceTopology.FindAll <WebServicesService>(mailboxSession.MailboxOwner, clientAccessType, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Sharing\\RefreshSharingFolderClient.cs", "SyncInternal", 154);
            }
            catch (LocalizedException arg)
            {
                RefreshSharingFolderClient.Tracer.TraceError <IExchangePrincipal, LocalizedException>(0L, "Unable to discover internal URL for EWS for mailbox {0} due exception {1}", mailboxSession.MailboxOwner, arg);
                return;
            }
            if (list.Count != 0)
            {
                string text = list[0].Url.ToString();
                RefreshSharingFolderClient.Tracer.TraceDebug <string>(0L, "Using {0} to call BeginRefreshSharingFolder", text);
                ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding("RefreshSharingFolder", new RemoteCertificateValidationCallback(RefreshSharingFolderClient.CertificateErrorHandler));
                exchangeServiceBinding.Url = text;
                exchangeServiceBinding.RequestServerVersionValue         = new RequestServerVersion();
                exchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
                exchangeServiceBinding.UserAgent     = WellKnownUserAgent.GetEwsNegoAuthUserAgent("RefreshSharingFolder");
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
                exchangeServiceBinding.Authenticator.AdditionalSoapHeaders.Add(new SerializedSecurityContextType
                {
                    UserSid             = securityAccessToken.UserSid,
                    GroupSids           = RefreshSharingFolderClient.SidStringAndAttributesConverter(securityAccessToken.GroupSids),
                    RestrictedGroupSids = RefreshSharingFolderClient.SidStringAndAttributesConverter(securityAccessToken.RestrictedGroupSids),
                    PrimarySmtpAddress  = mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()
                });
                Exception ex = null;
                try
                {
                    exchangeServiceBinding.BeginRefreshSharingFolder(new RefreshSharingFolderType
                    {
                        SharingFolderId = new FolderIdType
                        {
                            Id = id
                        }
                    }, new AsyncCallback(RefreshSharingFolderClient.TraceResponse), exchangeServiceBinding);
                }
                catch (SoapException ex2)
                {
                    ex = ex2;
                }
                catch (WebException ex3)
                {
                    ex = ex3;
                }
                catch (IOException ex4)
                {
                    ex = ex4;
                }
                catch (InvalidOperationException ex5)
                {
                    ex = ex5;
                }
                catch (LocalizedException ex6)
                {
                    ex = ex6;
                }
                if (ex != null)
                {
                    RefreshSharingFolderClient.Tracer.TraceError <StoreId, IExchangePrincipal, Exception>(0L, "Unable to sync sharing folder {0} in mailbox {1}. Exception {2}", folderId, mailboxSession.MailboxOwner, ex);
                }
                return;
            }
            RefreshSharingFolderClient.Tracer.TraceError <IExchangePrincipal>(0L, "Unable to find internal URL for EWS for mailbox {0}", mailboxSession.MailboxOwner);
        }