Esempio n. 1
0
 /// <summary>
 /// Manages Streaming Notifications for Exchange Users. Automatically assigns subscriptions to adequate CAS connections.
 /// </summary>
 /// <param name="credentials">Credentials with permission to impersonate the user mailboxes for all the subscriptions this instance will manage.</param>
 /// <param name="exchangeVersion">The version of the target Exchange server. Must be 2010 SP1 or higher</param>
 /// <param name="onNotificationEvent">The Action to invoke when Notifications arrive</param>
 public StreamingListener(ExchangeCredentials credentials, ExchangeVersion exchangeVersion, Action<SubscriptionNotificationEventCollection> onNotificationEvent)
 {
     _onNotificationEvent = onNotificationEvent;
     if ((int)exchangeVersion < 2)
         throw new ArgumentException("ExchangeVersion must be 2010 SP1 or higher");
     _exchangeVersion = exchangeVersion;
     this._credentials = credentials;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExchangeServiceBase"/> class.
 /// </summary>
 /// <param name="service">The other service.</param>
 /// <param name="requestedServerVersion">The requested server version.</param>
 internal ExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)
     : this(requestedServerVersion)
 {
     this.useDefaultCredentials = service.useDefaultCredentials;
     this.credentials           = service.credentials;
     this.traceEnabled          = service.traceEnabled;
     this.traceListener         = service.traceListener;
     this.traceFlags            = service.traceFlags;
     this.timeout                  = service.timeout;
     this.preAuthenticate          = service.preAuthenticate;
     this.userAgent                = service.userAgent;
     this.acceptGzipEncoding       = service.acceptGzipEncoding;
     this.keepAlive                = service.keepAlive;
     this.connectionGroupName      = service.connectionGroupName;
     this.timeZone                 = service.timeZone;
     this.httpHeaders              = service.httpHeaders;
     this.ewsHttpWebRequestFactory = service.ewsHttpWebRequestFactory;
 }
Esempio n. 3
0
        internal ExchangeCredentials AdjustLinuxAuthentication(Uri url, ExchangeCredentials serviceCredentials)
        {
            if (!(serviceCredentials is WebCredentials))
            {
                // Nothing to adjust
                return(serviceCredentials);
            }

            var networkCredentials = ((WebCredentials)serviceCredentials).Credentials as NetworkCredential;

            if (networkCredentials != null)
            {
                CredentialCache credentialCache = new CredentialCache();
                credentialCache.Add(url, "NTLM", networkCredentials);
                credentialCache.Add(url, "Digest", networkCredentials);
                credentialCache.Add(url, "Basic", networkCredentials);

                serviceCredentials = credentialCache;
            }
            return(serviceCredentials);
        }
        /// <summary>
        /// Creates an HttpWebRequest instance and initializes it with the appropriate parameters,
        /// based on the configuration of this service object.
        /// </summary>
        /// <param name="url">The URL that the HttpWebRequest should target.</param>
        /// <param name="acceptGzipEncoding">If true, ask server for GZip compressed content.</param>
        /// <param name="allowAutoRedirect">If true, redirection responses will be automatically followed.</param>
        /// <returns>A initialized instance of HttpWebRequest.</returns>
        internal IEwsHttpWebRequest PrepareHttpWebRequestForUrl(
            Uri url,
            bool acceptGzipEncoding,
            bool allowAutoRedirect)
        {
            // Verify that the protocol is something that we can handle
            if ((url.Scheme != Uri.UriSchemeHttp) && (url.Scheme != Uri.UriSchemeHttps))
            {
                throw new ServiceLocalException(string.Format(Strings.UnsupportedWebProtocol, url.Scheme));
            }

            IEwsHttpWebRequest request = this.HttpWebRequestFactory.CreateRequest(url);

            request.PreAuthenticate = this.PreAuthenticate;
            request.Timeout         = this.Timeout;
            this.SetContentType(request);
            request.Method              = "POST";
            request.UserAgent           = this.UserAgent;
            request.AllowAutoRedirect   = allowAutoRedirect;
            request.CookieContainer     = this.CookieContainer;
            request.KeepAlive           = this.keepAlive;
            request.ConnectionGroupName = this.connectionGroupName;

            if (acceptGzipEncoding)
            {
                request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
            }

            if (!string.IsNullOrEmpty(this.clientRequestId))
            {
                request.Headers.Add("client-request-id", this.clientRequestId);
                if (this.returnClientRequestId)
                {
                    request.Headers.Add("return-client-request-id", "true");
                }
            }

            if (this.webProxy != null)
            {
                request.Proxy = this.webProxy;
            }

            if (this.HttpHeaders.Count > 0)
            {
                this.HttpHeaders.ForEach((kv) => request.Headers.Add(kv.Key, kv.Value));
            }

            request.UseDefaultCredentials = this.UseDefaultCredentials;
            if (!request.UseDefaultCredentials)
            {
                ExchangeCredentials serviceCredentials = this.Credentials;
                if (serviceCredentials == null)
                {
                    throw new ServiceLocalException(Strings.CredentialsRequired);
                }

                // Make sure that credentials have been authenticated if required
                serviceCredentials.PreAuthenticate();

                // Apply credentials to the request
                serviceCredentials.PrepareWebRequest(request);
            }

            this.httpResponseHeaders.Clear();

            return(request);
        }
Esempio n. 5
0
 private ExchangeService CreateImpersonatedService(ImpersonatedUserId UserId,ExchangeCredentials exchangeCredentials)
 {
     return new ExchangeService(this.exchangeVersion) { Credentials = exchangeCredentials, ImpersonatedUserId=UserId };
 }
Esempio n. 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="exchangeCredentials"></param>
 /// <param name="exchangeVersion"></param>
 public FolderChanges(ExchangeCredentials exchangeCredentials, ExchangeVersion exchangeVersion)
     : this(exchangeCredentials)
 {
     this.exchangeVersion = exchangeVersion;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance with specified Exchange credentials. Defaults to Exchange2010_SP1 Server version.
 /// </summary>
 /// <param name="exchangeCredentials">Credentials with permission to impersonate relevant user mailboxes</param>
 public FolderChanges(ExchangeCredentials exchangeCredentials)
 {
     this.exchangeCredentials = exchangeCredentials;
 }
Esempio n. 8
0
        /// <summary>
        /// Creates an HttpWebRequest instance and initializes it with the appropriate parameters,
        /// based on the configuration of this service object.
        /// </summary>
        /// <param name="url">The URL that the HttpWebRequest should target.</param>
        /// <param name="acceptGzipEncoding">If true, ask server for GZip compressed content.</param>
        /// <param name="allowAutoRedirect">If true, redirection responses will be automatically followed.</param>
        /// <returns>A initialized instance of HttpWebRequest.</returns>
        internal IEwsHttpWebRequest PrepareHttpWebRequestForUrl(
            Uri url,
            bool acceptGzipEncoding,
            bool allowAutoRedirect)
        {
            // Verify that the protocol is something that we can handle
            if ((url.Scheme != "http") && (url.Scheme != "https"))
            {
                throw new ServiceLocalException(string.Format(Strings.UnsupportedWebProtocol, url.Scheme));
            }

            IEwsHttpWebRequest request = this.HttpWebRequestFactory.CreateRequest(url);

            request.PreAuthenticate = this.PreAuthenticate;
            request.Timeout         = this.Timeout;
            this.SetContentType(request);
            request.Method              = "POST";
            request.UserAgent           = this.UserAgent;
            request.AllowAutoRedirect   = allowAutoRedirect;
            request.CookieContainer     = this.CookieContainer;
            request.KeepAlive           = this.keepAlive;
            request.ConnectionGroupName = this.connectionGroupName;

            if (acceptGzipEncoding)
            {
                request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip,deflate";
            }

            if (!string.IsNullOrEmpty(this.clientRequestId))
            {
                request.Headers["client-request-id"] = this.clientRequestId;
                if (this.returnClientRequestId)
                {
                    request.Headers["return-client-request-id"] = "true";
                }
            }

            if (this.webProxy != null)
            {
                request.Proxy = this.webProxy;
            }

            if (this.HttpHeaders.Count > 0)
            {
                this.HttpHeaders.ForEach((kv) => request.Headers[kv.Key] = kv.Value);
            }

            request.UseDefaultCredentials = this.UseDefaultCredentials;
            if (!request.UseDefaultCredentials)
            {
                ExchangeCredentials serviceCredentials = this.Credentials;
                if (serviceCredentials == null)
                {
                    throw new ServiceLocalException(Strings.CredentialsRequired);
                }

#if NETSTANDARD2_0
                // Temporary fix for authentication on Linux platform
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    serviceCredentials = AdjustLinuxAuthentication(url, serviceCredentials);
                }
#endif

                // Make sure that credentials have been authenticated if required
                serviceCredentials.PreAuthenticate();

                // Apply credentials to the request
                serviceCredentials.PrepareWebRequest(request);
            }

            lock (this.httpResponseHeaders)
            {
                this.httpResponseHeaders.Clear();
            }

            return(request);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExchangeServiceBase"/> class.
 /// </summary>
 /// <param name="service">The other service.</param>
 /// <param name="requestedServerVersion">The requested server version.</param>
 internal ExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)
     : this(requestedServerVersion)
 {
     this.useDefaultCredentials = service.useDefaultCredentials;
     this.credentials = service.credentials;
     this.traceEnabled = service.traceEnabled;
     this.traceListener = service.traceListener;
     this.traceFlags = service.traceFlags;
     this.timeout = service.timeout;
     this.preAuthenticate = service.preAuthenticate;
     this.userAgent = service.userAgent;
     this.acceptGzipEncoding = service.acceptGzipEncoding;
     this.keepAlive = service.keepAlive;
     this.connectionGroupName = service.connectionGroupName;
     this.timeZone = service.timeZone;
     this.httpHeaders = service.httpHeaders;
     this.ewsHttpWebRequestFactory = service.ewsHttpWebRequestFactory;
 }
Esempio n. 10
0
 /// <summary>
 /// Manages Streaming Notifications for Exchange Users. Automatically assigns subscriptions to adequate CAS connections. Exchange Version is assumed to be 2010_SP1
 /// </summary>
 /// <param name="credentials">Credentials with permission to impersonate the user mailboxes for all the subscriptions this instance will manage.</param>
 /// <param name="onNotificationEvent">The Action to invoke when Notifications for any subscription arrive.</param>
 public StreamingListener(ExchangeCredentials credentials, Action<SubscriptionNotificationEventCollection> onNotificationEvent)
 {
     _onNotificationEvent = onNotificationEvent;
     _exchangeVersion = ExchangeVersion.Exchange2010_SP1;
     this._credentials = credentials;
 }