mirror of
https://github.com/moparisthebest/davmail
synced 2024-08-13 16:53:51 -04:00
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:
parent
9e478908e7
commit
9e7813132e
@ -251,12 +251,20 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
HttpMethod currentMethod = method;
|
HttpMethod currentMethod = method;
|
||||||
try {
|
try {
|
||||||
DavGatewayTray.debug(new BundleMessage("LOG_EXECUTE_FOLLOW_REDIRECTS", currentMethod.getURI()));
|
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");
|
Header location = currentMethod.getResponseHeader("Location");
|
||||||
int redirectCount = 0;
|
int redirectCount = 0;
|
||||||
while (redirectCount++ < 10
|
while (redirectCount++ < 10
|
||||||
&& location != null
|
&& location != null
|
||||||
&& isRedirect(currentMethod.getStatusCode())) {
|
&& isRedirect(status)) {
|
||||||
currentMethod.releaseConnection();
|
currentMethod.releaseConnection();
|
||||||
currentMethod = new GetMethod(location.getValue());
|
currentMethod = new GetMethod(location.getValue());
|
||||||
currentMethod.setFollowRedirects(false);
|
currentMethod.setFollowRedirects(false);
|
||||||
@ -469,7 +477,7 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
int status = httpClient.executeMethod(method);
|
int status = httpClient.executeMethod(method);
|
||||||
if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED
|
if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED
|
||||||
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
|
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
|
||||||
method.releaseConnection();
|
resetMethod(method);
|
||||||
LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM");
|
LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM");
|
||||||
addNTLM(httpClient);
|
addNTLM(httpClient);
|
||||||
status = httpClient.executeMethod(method);
|
status = httpClient.executeMethod(method);
|
||||||
@ -493,7 +501,7 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
int status = httpClient.executeMethod(method);
|
int status = httpClient.executeMethod(method);
|
||||||
if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED)
|
if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED)
|
||||||
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
|
&& acceptsNTLMOnly(method) && !hasNTLM(httpClient)) {
|
||||||
method.releaseConnection();
|
resetMethod(method);
|
||||||
LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM");
|
LOGGER.debug("Received " + status + " unauthorized at " + method.getURI() + ", retrying with NTLM");
|
||||||
addNTLM(httpClient);
|
addNTLM(httpClient);
|
||||||
status = httpClient.executeMethod(method);
|
status = httpClient.executeMethod(method);
|
||||||
@ -514,6 +522,13 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
return status;
|
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 {
|
private static void checkExpiredSession(String queryString) throws DavMailAuthenticationException {
|
||||||
if (queryString != null && queryString.contains("reason=2")) {
|
if (queryString != null && queryString.contains("reason=2")) {
|
||||||
LOGGER.warn("Request failed, session expired (reason=2) ");
|
LOGGER.warn("Request failed, session expired (reason=2) ");
|
||||||
|
Loading…
Reference in New Issue
Block a user