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:
parent
e2e6d12542
commit
38fbc96da3
|
@ -123,7 +123,15 @@ public final class DavGatewayHttpClientFacade {
|
||||||
public static void setCredentials(HttpClient httpClient, String userName, String password) {
|
public static void setCredentials(HttpClient httpClient, String userName, String password) {
|
||||||
// some Exchange servers redirect to a different host for freebusy, use wide auth scope
|
// some Exchange servers redirect to a different host for freebusy, use wide auth scope
|
||||||
AuthScope authScope = new AuthScope(null, -1);
|
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 {
|
try {
|
||||||
java.net.URI uri = new java.net.URI(url);
|
java.net.URI uri = new java.net.URI(url);
|
||||||
if (isNoProxyFor(uri)) {
|
if (isNoProxyFor(uri)) {
|
||||||
LOGGER.debug("no proxy for "+uri.getHost());
|
LOGGER.debug("no proxy for " + uri.getHost());
|
||||||
} else if (useSystemProxies) {
|
} else if (useSystemProxies) {
|
||||||
// get proxy for url from system settings
|
// get proxy for url from system settings
|
||||||
System.setProperty("java.net.useSystemProxies", "true");
|
System.setProperty("java.net.useSystemProxies", "true");
|
||||||
|
@ -205,10 +213,10 @@ public final class DavGatewayHttpClientFacade {
|
||||||
proxyPassword = Settings.getProperty("davmail.proxyPassword");
|
proxyPassword = Settings.getProperty("davmail.proxyPassword");
|
||||||
}
|
}
|
||||||
} else if (enableProxy) {
|
} else if (enableProxy) {
|
||||||
proxyHost = Settings.getProperty("davmail.proxyHost");
|
proxyHost = Settings.getProperty("davmail.proxyHost");
|
||||||
proxyPort = Settings.getIntProperty("davmail.proxyPort");
|
proxyPort = Settings.getIntProperty("davmail.proxyPort");
|
||||||
proxyUser = Settings.getProperty("davmail.proxyUser");
|
proxyUser = Settings.getProperty("davmail.proxyUser");
|
||||||
proxyPassword = Settings.getProperty("davmail.proxyPassword");
|
proxyPassword = Settings.getProperty("davmail.proxyPassword");
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new DavMailException("LOG_INVALID_URL", url);
|
throw new DavMailException("LOG_INVALID_URL", url);
|
||||||
|
@ -598,20 +606,13 @@ public final class DavGatewayHttpClientFacade {
|
||||||
authPrefs.add(AuthPolicy.BASIC);
|
authPrefs.add(AuthPolicy.BASIC);
|
||||||
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
||||||
|
|
||||||
|
// make sure NTLM is always active
|
||||||
|
needNTLM = true;
|
||||||
|
|
||||||
// separate domain from username in credentials
|
// separate domain from username in credentials
|
||||||
AuthScope authScope = new AuthScope(null, -1);
|
AuthScope authScope = new AuthScope(null, -1);
|
||||||
NTCredentials credentials = (NTCredentials) httpClient.getState().getCredentials(authScope);
|
NTCredentials credentials = (NTCredentials) httpClient.getState().getCredentials(authScope);
|
||||||
String userName = credentials.getUserName();
|
setCredentials(httpClient, credentials.getUserName(), credentials.getPassword());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue