mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 03:32:22 -05:00
EWS: implement failover on OWA authentication failure (e.g. with outlook.com)
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1521 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
18584e259d
commit
c0abc93ac5
@ -119,7 +119,7 @@ public abstract class ExchangeSession {
|
|||||||
protected String currentMailboxPath;
|
protected String currentMailboxPath;
|
||||||
protected final HttpClient httpClient;
|
protected final HttpClient httpClient;
|
||||||
|
|
||||||
private final String userName;
|
protected final String userName;
|
||||||
|
|
||||||
protected String serverVersion;
|
protected String serverVersion;
|
||||||
|
|
||||||
@ -429,15 +429,7 @@ public abstract class ExchangeSession {
|
|||||||
return logonMethod;
|
return logonMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException {
|
protected HttpMethod postLogonMethod(HttpClient httpClient, HttpMethod logonMethod, String userName, String password) throws IOException {
|
||||||
LOGGER.debug("Form based authentication detected");
|
|
||||||
|
|
||||||
HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod);
|
|
||||||
if (logonMethod == null) {
|
|
||||||
LOGGER.debug("Authentication form not found at " + initmethod.getURI() + ", trying default url");
|
|
||||||
logonMethod = new PostMethod("/owa/auth/owaauth.dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure username and password fields are empty
|
// make sure username and password fields are empty
|
||||||
((PostMethod) logonMethod).removeParameter(userNameInput);
|
((PostMethod) logonMethod).removeParameter(userNameInput);
|
||||||
((PostMethod) logonMethod).removeParameter(passwordInput);
|
((PostMethod) logonMethod).removeParameter(passwordInput);
|
||||||
@ -480,6 +472,18 @@ public abstract class ExchangeSession {
|
|||||||
// need to submit form
|
// need to submit form
|
||||||
logonMethod = submitLanguageSelectionForm(logonMethod);
|
logonMethod = submitLanguageSelectionForm(logonMethod);
|
||||||
}
|
}
|
||||||
|
return logonMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException {
|
||||||
|
LOGGER.debug("Form based authentication detected");
|
||||||
|
|
||||||
|
HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod);
|
||||||
|
if (logonMethod == null) {
|
||||||
|
LOGGER.debug("Authentication form not found at " + initmethod.getURI() + ", trying default url");
|
||||||
|
logonMethod = new PostMethod("/owa/auth/owaauth.dll");
|
||||||
|
}
|
||||||
|
logonMethod = postLogonMethod(httpClient, logonMethod, userName, password);
|
||||||
|
|
||||||
return logonMethod;
|
return logonMethod;
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,21 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
super(url, userName, password);
|
super(url, userName, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException {
|
||||||
|
LOGGER.debug("Form based authentication detected");
|
||||||
|
|
||||||
|
HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod);
|
||||||
|
if (logonMethod == null) {
|
||||||
|
LOGGER.debug("Authentication form not found at " + initmethod.getURI() + ", will try direct EWS access");
|
||||||
|
} else {
|
||||||
|
logonMethod = postLogonMethod(httpClient, logonMethod, userName, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
return logonMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check endpoint url.
|
* Check endpoint url.
|
||||||
*
|
*
|
||||||
@ -90,7 +105,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
getMethod.setFollowRedirects(false);
|
getMethod.setFollowRedirects(false);
|
||||||
try {
|
try {
|
||||||
int status = DavGatewayHttpClientFacade.executeNoRedirect(httpClient, getMethod);
|
int status = DavGatewayHttpClientFacade.executeNoRedirect(httpClient, getMethod);
|
||||||
if (status != HttpStatus.SC_MOVED_TEMPORARILY) {
|
if (status == HttpStatus.SC_UNAUTHORIZED) {
|
||||||
|
throw new DavMailAuthenticationException("EXCEPTION_AUTHENTICATION_FAILED");
|
||||||
|
} else if (status != HttpStatus.SC_MOVED_TEMPORARILY) {
|
||||||
throw DavGatewayHttpClientFacade.buildHttpException(getMethod);
|
throw DavGatewayHttpClientFacade.buildHttpException(getMethod);
|
||||||
}
|
}
|
||||||
// check Location
|
// check Location
|
||||||
@ -109,10 +126,19 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
@Override
|
@Override
|
||||||
protected void buildSessionInfo(HttpMethod method) throws DavMailException {
|
protected void buildSessionInfo(HttpMethod method) throws DavMailException {
|
||||||
// no need to check logon method body
|
// no need to check logon method body
|
||||||
|
if (method != null) {
|
||||||
method.releaseConnection();
|
method.releaseConnection();
|
||||||
|
// need to retrieve email and alias
|
||||||
// also need to retrieve email and alias
|
|
||||||
getEmailAndAliasFromOptions();
|
getEmailAndAliasFromOptions();
|
||||||
|
} else {
|
||||||
|
// OWA authentication failed, get email address from login
|
||||||
|
if (userName.indexOf('@') >= 0) {
|
||||||
|
// userName is email address
|
||||||
|
email = userName;
|
||||||
|
alias = userName.substring(0, userName.indexOf('@'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (email == null || alias == null) {
|
if (email == null || alias == null) {
|
||||||
throw new DavMailAuthenticationException("EXCEPTION_EWS_NOT_AVAILABLE");
|
throw new DavMailAuthenticationException("EXCEPTION_EWS_NOT_AVAILABLE");
|
||||||
}
|
}
|
||||||
@ -122,6 +148,8 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
// check EWS access
|
// check EWS access
|
||||||
try {
|
try {
|
||||||
checkEndPointUrl("/ews/exchange.asmx");
|
checkEndPointUrl("/ews/exchange.asmx");
|
||||||
|
} catch (DavMailAuthenticationException e) {
|
||||||
|
throw e;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
try {
|
try {
|
||||||
// failover, try to retrieve EWS url from autodiscover
|
// failover, try to retrieve EWS url from autodiscover
|
||||||
@ -1273,7 +1301,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
event.getEventContent();
|
event.getEventContent();
|
||||||
events.add(event);
|
events.add(event);
|
||||||
} catch (HttpException e) {
|
} catch (HttpException e) {
|
||||||
LOGGER.warn("Ignore invalid event "+event.getHref());
|
LOGGER.warn("Ignore invalid event " + event.getHref());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
events.add(event);
|
events.add(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user