Improve NTLM mode detection

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1011 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-04-22 10:32:44 +00:00
parent 9e478908e7
commit 9e7813132e
1 changed files with 19 additions and 4 deletions

View File

@ -251,12 +251,20 @@ public final class DavGatewayHttpClientFacade {
HttpMethod currentMethod = method;
try {
DavGatewayTray.debug(new BundleMessage("LOG_EXECUTE_FOLLOW_REDIRECTS", currentMethod.getURI()));
httpClient.executeMethod(currentMethod);
int status = httpClient.executeMethod(currentMethod);
// check NTLM
if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED)
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
LOGGER.debug("Received " + status + " unauthorized at " + currentMethod.getURI() + ", retrying with NTLM");
resetMethod(currentMethod);
addNTLM(httpClient);
status = httpClient.executeMethod(currentMethod);
}
Header location = currentMethod.getResponseHeader("Location");
int redirectCount = 0;
while (redirectCount++ < 10
&& location != null
&& isRedirect(currentMethod.getStatusCode())) {
&& isRedirect(status)) {
currentMethod.releaseConnection();
currentMethod = new GetMethod(location.getValue());
currentMethod.setFollowRedirects(false);
@ -469,7 +477,7 @@ public final class DavGatewayHttpClientFacade {
int status = httpClient.executeMethod(method);
if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
method.releaseConnection();
resetMethod(method);
LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM");
addNTLM(httpClient);
status = httpClient.executeMethod(method);
@ -493,7 +501,7 @@ public final class DavGatewayHttpClientFacade {
int status = httpClient.executeMethod(method);
if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED)
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
method.releaseConnection();
resetMethod(method);
LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM");
addNTLM(httpClient);
status = httpClient.executeMethod(method);
@ -514,6 +522,13 @@ public final class DavGatewayHttpClientFacade {
return status;
}
private static void resetMethod(HttpMethod method) {
// reset method state
method.releaseConnection();
method.getHostAuthState().invalidate();
method.getProxyAuthState().invalidate();
}
private static void checkExpiredSession(String queryString) throws DavMailAuthenticationException {
if (queryString != null && queryString.contains("reason=2")) {
LOGGER.warn("Request failed, session expired (reason=2) ");