Fix reauthentication issue: separate domain from username in credentials

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2210 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-01-15 22:10:43 +00:00
parent e2e6d12542
commit 38fbc96da3
1 changed files with 18 additions and 17 deletions

View File

@ -123,8 +123,16 @@ public final class DavGatewayHttpClientFacade {
public static void setCredentials(HttpClient httpClient, String userName, String password) {
// some Exchange servers redirect to a different host for freebusy, use wide auth scope
AuthScope authScope = new AuthScope(null, -1);
int backSlashIndex = userName.indexOf('\\');
if (needNTLM && backSlashIndex >= 0) {
// separate domain from username in credentials
String domain = userName.substring(0, backSlashIndex);
userName = userName.substring(backSlashIndex + 1);
httpClient.getState().setCredentials(authScope, new NTCredentials(userName, password, "UNKNOWN", domain));
} else {
httpClient.getState().setCredentials(authScope, new NTCredentials(userName, password, "UNKNOWN", ""));
}
}
/**
* Set http client current host configuration.
@ -598,20 +606,13 @@ public final class DavGatewayHttpClientFacade {
authPrefs.add(AuthPolicy.BASIC);
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
// make sure NTLM is always active
needNTLM = true;
// separate domain from username in credentials
AuthScope authScope = new AuthScope(null, -1);
NTCredentials credentials = (NTCredentials) httpClient.getState().getCredentials(authScope);
String userName = credentials.getUserName();
int backSlashIndex = userName.indexOf('\\');
if (backSlashIndex >= 0) {
String domain = userName.substring(0, backSlashIndex);
userName = userName.substring(backSlashIndex + 1);
credentials = new NTCredentials(userName, credentials.getPassword(), "UNKNOWN", domain);
httpClient.getState().setCredentials(authScope, credentials);
}
// make sure NTLM is always active
needNTLM = true;
setCredentials(httpClient, credentials.getUserName(), credentials.getPassword());
}
/**