private static ExchangeServiceBinding CreateBinding(string email)
		{
			NetworkServiceImpersonator.Initialize();
			if (NetworkServiceImpersonator.Exception != null)
			{
				ExTraceGlobals.ELCTracer.TraceError<LocalizedException>(0L, "Unable to impersonate network service to call EWS due to exception {0}", NetworkServiceImpersonator.Exception);
				throw new ElcUserConfigurationException(Strings.ElcUserConfigurationServiceBindingNotAvailable, NetworkServiceImpersonator.Exception);
			}
			ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding(new RemoteCertificateValidationCallback(StoreRetentionPolicyTagHelper.CertificateErrorHandler));
			exchangeServiceBinding.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent("MRMTask");
			exchangeServiceBinding.RequestServerVersionValue = new RequestServerVersion
			{
				Version = ExchangeVersionType.Exchange2010_SP1
			};
			StoreRetentionPolicyTagHelper.SetSecurityHeader(exchangeServiceBinding, email);
			return exchangeServiceBinding;
		}
Beispiel #2
0
        public ExchangeProxy(ISearchPolicy policy, GroupId groupId)
        {
            Recorder.Trace(5L, TraceType.InfoTrace, new object[]
            {
                "ExchangeProxy.ctor GroupId:",
                groupId,
                "GroupType:",
                groupId.GroupType,
                "Uri:",
                groupId.Uri
            });
            this.groupId = groupId;
            this.policy  = policy;
            ExchangeCredentials credentials;

            if (this.groupId.GroupType == GroupType.CrossPremise)
            {
                credentials = new OAuthCredentials(OAuthCredentials.GetOAuthCredentialsForAppToken(this.policy.CallerInfo.OrganizationId, groupId.Domain));
            }
            else
            {
                credentials = new WebCredentials();
            }
            string text = string.Format("{0}&FOUT=true", policy.CallerInfo.UserAgent);

            this.InitializeExchangeProxy(credentials, groupId.Uri, (long)groupId.ServerVersion);
            this.exchangeService.HttpHeaders[CertificateValidationManager.ComponentIdHeaderName] = typeof(IEwsClient).FullName;
            this.exchangeService.ClientRequestId = this.policy.CallerInfo.QueryCorrelationId.ToString();
            this.exchangeService.Timeout         = (int)TimeSpan.FromMinutes(this.policy.ThrottlingSettings.DiscoverySearchTimeoutPeriod).TotalMilliseconds;
            if (this.groupId.GroupType == GroupType.CrossPremise)
            {
                this.exchangeService.UserAgent       = text;
                this.exchangeService.ManagementRoles = new ManagementRoles(null, ExchangeProxy.mailboxSearchApplicationRole);
                return;
            }
            this.exchangeService.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent(string.Format("{0}-{1}", ExchangeProxy.crossServerUserAgent, text));
            if (this.policy.CallerInfo.CommonAccessToken != null && !this.policy.CallerInfo.IsOpenAsAdmin)
            {
                this.exchangeService.HttpHeaders["X-CommonAccessToken"] = this.policy.CallerInfo.CommonAccessToken.Serialize();
                if (this.policy.CallerInfo.UserRoles != null || this.policy.CallerInfo.ApplicationRoles != null)
                {
                    this.exchangeService.ManagementRoles = new ManagementRoles(this.policy.CallerInfo.UserRoles, this.policy.CallerInfo.ApplicationRoles);
                }
            }
        }
        public virtual IExchangeService CreateBinding(RemoteCertificateValidationCallback certificateErrorHandler)
        {
            bool flag = true;

            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                if (this.IsTraceEnabled(TraceType.ErrorTrace))
                {
                    this.Tracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due to exception {0}", NetworkServiceImpersonator.Exception);
                }
                flag = false;
            }
            ExchangeServiceBinding exchangeServiceBinding = new ExchangeServiceBinding(certificateErrorHandler);

            exchangeServiceBinding.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent("AuditLog");
            exchangeServiceBinding.RequestServerVersionValue = new RequestServerVersion
            {
                Version = ExchangeVersionType.Exchange2013
            };
            if (flag)
            {
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.CreateNetworkService();
            }
            else
            {
                exchangeServiceBinding.Authenticator = SoapHttpClientAuthenticator.Create(CredentialCache.DefaultCredentials);
            }
            exchangeServiceBinding.Authenticator.AdditionalSoapHeaders.Add(new OpenAsAdminOrSystemServiceType
            {
                ConnectingSID = new ConnectingSIDType
                {
                    Item = new PrimarySmtpAddressType
                    {
                        Value = this.GetSmtpAddress()
                    }
                },
                LogonType           = SpecialLogonType.SystemService,
                BudgetType          = (int)this.budgetType,
                BudgetTypeSpecified = true
            });
            return(exchangeServiceBinding);
        }
Beispiel #4
0
 public NonIndexableDiscoveryEwsClient(GroupId groupId, MailboxInfo[] mailboxes, ExTimeZone timeZone, CallerInfo caller)
 {
     Util.ThrowOnNull(groupId, "groupId");
     Util.ThrowOnNull(mailboxes, "mailboxes");
     Util.ThrowOnNull(timeZone, "timeZone");
     Util.ThrowOnNull(caller, "caller");
     this.groupId    = groupId;
     this.mailboxes  = mailboxes;
     this.callerInfo = caller;
     CertificateValidationManager.RegisterCallback(base.GetType().FullName, new RemoteCertificateValidationCallback(CertificateValidation.CertificateErrorHandler));
     this.service     = new ExchangeService(4, NonIndexableDiscoveryEwsClient.GetTimeZoneInfoFromExTimeZone(timeZone));
     this.service.Url = this.groupId.Uri;
     this.service.HttpHeaders[CertificateValidationManager.ComponentIdHeaderName] = base.GetType().FullName;
     if (this.groupId.GroupType != GroupType.CrossPremise)
     {
         this.service.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent(base.GetType().FullName);
     }
     this.service.ClientRequestId = this.callerInfo.QueryCorrelationId.ToString("N");
     this.Authenticate();
 }
Beispiel #5
0
        public DiscoveryEwsClient(GroupId groupId, MailboxInfo[] mailboxes, SearchCriteria searchCriteria, PagingInfo pagingInfo, CallerInfo caller)
        {
            this.groupId        = groupId;
            this.mailboxes      = mailboxes;
            this.searchCriteria = searchCriteria;
            this.pagingInfo     = pagingInfo;
            this.callerInfo     = caller;
            CertificateValidationManager.RegisterCallback(base.GetType().FullName, new RemoteCertificateValidationCallback(CertificateValidation.CertificateErrorHandler));
            this.service     = new ExchangeService(4, DiscoveryEwsClient.GetTimeZoneInfoFromExTimeZone(this.pagingInfo.TimeZone));
            this.service.Url = this.groupId.Uri;
            this.service.HttpHeaders[CertificateValidationManager.ComponentIdHeaderName] = base.GetType().FullName;
            string text = string.Format("{0}&FOUT=true", caller.UserAgent);

            if (this.groupId.GroupType != GroupType.CrossPremise)
            {
                this.service.UserAgent = WellKnownUserAgent.GetEwsNegoAuthUserAgent(string.Format("{0}-{1}", DiscoveryEwsClient.CrossServerUserAgent, text));
            }
            else
            {
                this.service.UserAgent = text;
            }
            this.service.ClientRequestId = this.callerInfo.QueryCorrelationId.ToString("N");
            this.Authenticate();
        }
        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);
        }