From 6084afffb52fe839e8fffbfe1393bedc474648cb Mon Sep 17 00:00:00 2001 From: mguessan Date: Sun, 24 Aug 2008 16:01:03 +0000 Subject: [PATCH] Improve login method : detect custom login form and destination url git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@132 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 120 ++++++++++++------ src/java/davmail/pop/PopConnection.java | 4 +- 2 files changed, 83 insertions(+), 41 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index fda16e7e..fd8d5ae4 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -201,42 +201,69 @@ public class ExchangeSession { HttpMethod initmethod = new GetMethod(url); wdr.executeHttpRequestMethod(httpClient, initmethod); + + // default destination is provided url + String destination = url; + if (!isBasicAuthentication) { LOGGER.debug("Form based authentication detected"); - if (initmethod.getPath().indexOf("exchweb/bin") == -1) { - LOGGER.error("DavMail configuration exception: authentication form not found at " + url + - " and basic authentication not requested"); - throw new IOException("DavMail configuration exception: authentication form not found at " + url + - " and basic authentication not requested"); - } else { - PostMethod logonMethod = new PostMethod( - "/exchweb/bin/auth/owaauth.dll?" + - "ForcedBasic=false&Basic=false&Private=true" + - "&Language=No_Value" - ); - logonMethod.addParameter("destination", url); - logonMethod.addParameter("flags", "4"); + // default logon method path + String logonMethodPath = "/exchweb/bin/auth/owaauth.dll"; + + // try to parse login form to determine logon url and destination + BufferedReader loginFormReader = null; + try { + loginFormReader = new BufferedReader(new InputStreamReader(initmethod.getResponseBodyAsStream())); + String line; + // skip to form action + final String FORM_ACTION = "