mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 17:31:52 -05:00
Workaround for post logon script redirect
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@541 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
e4de45f3f0
commit
12246cbdf9
@ -156,26 +156,18 @@ public class ExchangeSession {
|
|||||||
// manually follow redirect
|
// manually follow redirect
|
||||||
HttpMethod method = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, poolKey.url);
|
HttpMethod method = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, poolKey.url);
|
||||||
|
|
||||||
if (!isBasicAuthentication) {
|
if (isBasicAuthentication) {
|
||||||
method = formLogin(httpClient, method, poolKey.userName, poolKey.password);
|
|
||||||
}
|
|
||||||
int status = method.getStatusCode();
|
int status = method.getStatusCode();
|
||||||
|
|
||||||
if (status == HttpStatus.SC_UNAUTHORIZED) {
|
if (status == HttpStatus.SC_UNAUTHORIZED) {
|
||||||
|
method.releaseConnection();
|
||||||
throw new AuthenticationException("Authentication failed: invalid user or password");
|
throw new AuthenticationException("Authentication failed: invalid user or password");
|
||||||
} else if (status != HttpStatus.SC_OK) {
|
} else if (status != HttpStatus.SC_OK) {
|
||||||
|
method.releaseConnection();
|
||||||
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
||||||
}
|
}
|
||||||
// test form based authentication
|
|
||||||
String queryString = method.getQueryString();
|
|
||||||
if (queryString != null && queryString.contains("reason=2")) {
|
|
||||||
method.releaseConnection();
|
|
||||||
if (poolKey.userName != null && poolKey.userName.contains("\\")) {
|
|
||||||
throw new AuthenticationException("Authentication failed: invalid user or password");
|
|
||||||
} else {
|
} else {
|
||||||
throw new AuthenticationException("Authentication failed: invalid user or password, " +
|
method = formLogin(httpClient, method, poolKey.userName, poolKey.password);
|
||||||
"retry with domain\\user");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildMailPath(method);
|
buildMailPath(method);
|
||||||
@ -374,9 +366,33 @@ public class ExchangeSession {
|
|||||||
((PostMethod) logonMethod).addParameter("username", userName);
|
((PostMethod) logonMethod).addParameter("username", userName);
|
||||||
((PostMethod) logonMethod).addParameter("password", password);
|
((PostMethod) logonMethod).addParameter("password", password);
|
||||||
logonMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, logonMethod);
|
logonMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, logonMethod);
|
||||||
|
|
||||||
|
// test form based authentication
|
||||||
|
checkFormLoginQueryString(logonMethod);
|
||||||
|
|
||||||
|
// workaround for post logon script redirect
|
||||||
|
if (httpClient.getState().getCookies().length == 0) {
|
||||||
|
logonMethod = buildLogonMethod(httpClient, logonMethod);
|
||||||
|
logonMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, logonMethod);
|
||||||
|
checkFormLoginQueryString(logonMethod);
|
||||||
|
}
|
||||||
|
|
||||||
return logonMethod;
|
return logonMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void checkFormLoginQueryString(HttpMethod logonMethod) throws AuthenticationException {
|
||||||
|
String queryString = logonMethod.getQueryString();
|
||||||
|
if (queryString != null && queryString.contains("reason=2")) {
|
||||||
|
logonMethod.releaseConnection();
|
||||||
|
if (poolKey.userName != null && poolKey.userName.contains("\\")) {
|
||||||
|
throw new AuthenticationException("Authentication failed: invalid user or password");
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationException("Authentication failed: invalid user or password, " +
|
||||||
|
"retry with domain\\user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void buildMailPath(HttpMethod method) throws HttpException {
|
protected void buildMailPath(HttpMethod method) throws HttpException {
|
||||||
// get user mail URL from html body (multi frame)
|
// get user mail URL from html body (multi frame)
|
||||||
BufferedReader mainPageReader = null;
|
BufferedReader mainPageReader = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user