1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-04 14:52:24 -05:00

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

View File

@ -123,7 +123,15 @@ 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);
httpClient.getState().setCredentials(authScope, new NTCredentials(userName, password, "UNKNOWN", ""));
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", ""));
}
}
/**
@ -190,7 +198,7 @@ public final class DavGatewayHttpClientFacade {
try {
java.net.URI uri = new java.net.URI(url);
if (isNoProxyFor(uri)) {
LOGGER.debug("no proxy for "+uri.getHost());
LOGGER.debug("no proxy for " + uri.getHost());
} else if (useSystemProxies) {
// get proxy for url from system settings
System.setProperty("java.net.useSystemProxies", "true");
@ -205,10 +213,10 @@ public final class DavGatewayHttpClientFacade {
proxyPassword = Settings.getProperty("davmail.proxyPassword");
}
} else if (enableProxy) {
proxyHost = Settings.getProperty("davmail.proxyHost");
proxyPort = Settings.getIntProperty("davmail.proxyPort");
proxyUser = Settings.getProperty("davmail.proxyUser");
proxyPassword = Settings.getProperty("davmail.proxyPassword");
proxyHost = Settings.getProperty("davmail.proxyHost");
proxyPort = Settings.getIntProperty("davmail.proxyPort");
proxyUser = Settings.getProperty("davmail.proxyUser");
proxyPassword = Settings.getProperty("davmail.proxyPassword");
}
} catch (URISyntaxException e) {
throw new DavMailException("LOG_INVALID_URL", url);
@ -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());
}
/**