From c6fb2f9e04a2cae456ea266e8e473a693dbf09de Mon Sep 17 00:00:00 2001 From: Mike Noordermeer Date: Thu, 5 Mar 2015 13:29:45 +0100 Subject: [PATCH 01/37] Remove any cookies/state after resetting authentication of ExchangeServiceBase. This prevents an old authentication from being reused by proxy firewalls like TMG. --- .../webservices/data/ExchangeServiceBase.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/microsoft/exchange/webservices/data/ExchangeServiceBase.java b/src/main/java/microsoft/exchange/webservices/data/ExchangeServiceBase.java index 5abc10117..f4b35e17d 100644 --- a/src/main/java/microsoft/exchange/webservices/data/ExchangeServiceBase.java +++ b/src/main/java/microsoft/exchange/webservices/data/ExchangeServiceBase.java @@ -23,12 +23,14 @@ package microsoft.exchange.webservices.data; +import org.apache.http.client.CookieStore; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; @@ -131,7 +133,7 @@ public abstract class ExchangeServiceBase implements Closeable { protected CloseableHttpClient httpClient; - protected HttpClientContext httpContext = HttpClientContext.create(); + protected HttpClientContext httpContext; protected HttpClientWebRequest request = null; @@ -151,6 +153,7 @@ public abstract class ExchangeServiceBase implements Closeable { protected ExchangeServiceBase() { setUseDefaultCredentials(true); initializeHttpClient(); + initializeHttpContext(); } protected ExchangeServiceBase(ExchangeVersion requestedServerVersion) { @@ -195,7 +198,14 @@ private void initializeHttpClient() { httpClient = httpClientBuilder.build(); } - @Override + private void initializeHttpContext() { + // Use an own cookie store, instead of the httpClient's global store, so cookies get reset on reinitialization + CookieStore cookieStore = new BasicCookieStore(); + httpContext = HttpClientContext.create(); + httpContext.setCookieStore(cookieStore); + } + + @Override public void close() { try { httpClient.close(); @@ -579,6 +589,9 @@ public ExchangeCredentials getCredentials() { public void setCredentials(ExchangeCredentials credentials) { this.credentials = credentials; this.useDefaultCredentials = false; + + // Reset the httpContext, to remove any existing authentication cookies from subsequent requests + initializeHttpContext(); } /** @@ -605,8 +618,11 @@ public void setUseDefaultCredentials(boolean value) { if (value) { this.credentials = null; } - } + // Reset the httpContext, to remove any existing authentication cookies from subsequent requests + initializeHttpContext(); + } + /** * Gets the timeout used when sending HTTP requests and when receiving HTTP * responses, in milliseconds. From dfe00eecbbe1557a1b9ac34e6ec0f66a56a53e3f Mon Sep 17 00:00:00 2001 From: Mike Noordermeer Date: Thu, 5 Mar 2015 13:40:55 +0100 Subject: [PATCH 02/37] Update pom.xml for Eveoh settings. --- .idea/codeStyleSettings.xml | 16 ++++++++++++++ .idea/misc.xml | 1 + pom.xml | 44 ++++++++----------------------------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml index ddacdf3e8..1b2ecbcf1 100644 --- a/.idea/codeStyleSettings.xml +++ b/.idea/codeStyleSettings.xml @@ -52,6 +52,14 @@ + + + + + + + +