mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
Simplify HttpClient creation to avoid password decoding bug in commons httpclient ('+' in password decoded as ' ')
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@678 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
3b7a369e33
commit
dfe241dc2b
@ -151,22 +151,7 @@ public class ExchangeSession {
|
|||||||
try {
|
try {
|
||||||
boolean isBasicAuthentication = isBasicAuthentication(poolKey.url);
|
boolean isBasicAuthentication = isBasicAuthentication(poolKey.url);
|
||||||
|
|
||||||
// get proxy configuration from setttings properties
|
httpClient = DavGatewayHttpClientFacade.getInstance(poolKey.url, poolKey.userName, poolKey.password);
|
||||||
URL urlObject = new URL(poolKey.url);
|
|
||||||
// webdavresource is unable to create the correct url type
|
|
||||||
HttpURL httpURL;
|
|
||||||
if (poolKey.url.startsWith("http://")) {
|
|
||||||
httpURL = new HttpURL(poolKey.userName, poolKey.password,
|
|
||||||
urlObject.getHost(), urlObject.getPort());
|
|
||||||
} else if (poolKey.url.startsWith("https://")) {
|
|
||||||
httpURL = new HttpsURL(poolKey.userName, poolKey.password,
|
|
||||||
urlObject.getHost(), urlObject.getPort());
|
|
||||||
} else {
|
|
||||||
throw new DavMailException("LOG_INVALID_URL", poolKey.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
httpClient = DavGatewayHttpClientFacade.getInstance(httpURL);
|
|
||||||
// avoid 401 roundtrips
|
// avoid 401 roundtrips
|
||||||
httpClient.getParams().setParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
|
httpClient.getParams().setParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ package davmail.http;
|
|||||||
|
|
||||||
import davmail.Settings;
|
import davmail.Settings;
|
||||||
import davmail.BundleMessage;
|
import davmail.BundleMessage;
|
||||||
|
import davmail.exception.DavMailException;
|
||||||
import davmail.ui.tray.DavGatewayTray;
|
import davmail.ui.tray.DavGatewayTray;
|
||||||
import org.apache.commons.httpclient.*;
|
import org.apache.commons.httpclient.*;
|
||||||
import org.apache.commons.httpclient.auth.AuthPolicy;
|
import org.apache.commons.httpclient.auth.AuthPolicy;
|
||||||
@ -37,6 +38,7 @@ import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create HttpClient instance according to DavGateway Settings
|
* Create HttpClient instance according to DavGateway Settings
|
||||||
@ -73,16 +75,19 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpClient getInstance(HttpURL httpURL) throws URIException {
|
public static HttpClient getInstance(String url, String userName, String password) throws DavMailException {
|
||||||
HttpClient httpClient = new HttpClient();
|
HttpClient httpClient = new HttpClient();
|
||||||
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, IE_USER_AGENT);
|
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, IE_USER_AGENT);
|
||||||
httpClient.getParams().setParameter(HttpClientParams.MAX_REDIRECTS, MAX_REDIRECTS);
|
httpClient.getParams().setParameter(HttpClientParams.MAX_REDIRECTS, MAX_REDIRECTS);
|
||||||
HostConfiguration hostConfig = httpClient.getHostConfiguration();
|
HostConfiguration hostConfig = httpClient.getHostConfiguration();
|
||||||
hostConfig.setHost(httpURL);
|
try {
|
||||||
String userName = httpURL.getUser();
|
URI httpURI = new URI(url, true);
|
||||||
String password = httpURL.getPassword();
|
hostConfig.setHost(httpURI);
|
||||||
AuthScope authScope = new AuthScope(httpURL.getHost(), httpURL.getPort(), AuthScope.ANY_REALM);
|
AuthScope authScope = new AuthScope(httpURI.getHost(), httpURI.getPort(), AuthScope.ANY_REALM);
|
||||||
httpClient.getState().setCredentials(authScope, new UsernamePasswordCredentials(userName, password));
|
httpClient.getState().setCredentials(authScope, new UsernamePasswordCredentials(userName, password));
|
||||||
|
} catch (URIException e) {
|
||||||
|
throw new DavMailException("LOG_INVALID_URL", url);
|
||||||
|
}
|
||||||
configureClient(httpClient);
|
configureClient(httpClient);
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user