Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2006-12-06 00:29:40 +0000
committerrelves2006-12-06 00:29:40 +0000
commit5302192dec8e513db96147a9bf5763bbd8e296f0 (patch)
tree14b8ae6326c97b907b99a57a4d96228b750316ec /org.eclipse.mylyn.tasks.core/src
parent2ddbffea2d5e4fa3ae743dd2849fecbe2d97ce3d (diff)
downloadorg.eclipse.mylyn.tasks-5302192dec8e513db96147a9bf5763bbd8e296f0.tar.gz
org.eclipse.mylyn.tasks-5302192dec8e513db96147a9bf5763bbd8e296f0.tar.xz
org.eclipse.mylyn.tasks-5302192dec8e513db96147a9bf5763bbd8e296f0.zip
NEW - bug 166540: Task repositories cannot be used through an auth proxy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=166540
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SslProtocolSocketFactory.java43
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java14
2 files changed, 42 insertions, 15 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SslProtocolSocketFactory.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SslProtocolSocketFactory.java
index 0e95a6970..b9bfb8536 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SslProtocolSocketFactory.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/SslProtocolSocketFactory.java
@@ -14,6 +14,7 @@ package org.eclipse.mylar.internal.tasks.core;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.Proxy;
import java.net.Socket;
import java.net.UnknownHostException;
@@ -21,17 +22,28 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.ProxyClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.eclipse.mylar.context.core.MylarStatusHandler;
-/**
+/**
* @author Nathan Hapke
+ * @author Rob Elves
*/
public class SslProtocolSocketFactory implements ProtocolSocketFactory {
private SSLContext sslContext;
+ private Proxy proxy;
+
+ public SslProtocolSocketFactory(Proxy proxy) {
+ this.proxy = proxy;
+ }
+
private SSLContext getSslContext() {
if (sslContext == null) {
try {
@@ -39,7 +51,7 @@ public class SslProtocolSocketFactory implements ProtocolSocketFactory {
sslContext.init(null, new TrustManager[] { new RepositoryTrustManager() }, null);
} catch (Exception e) {
MylarStatusHandler.log(e, "could not get SSL context");
- }
+ }
}
return sslContext;
}
@@ -58,6 +70,33 @@ public class SslProtocolSocketFactory implements ProtocolSocketFactory {
if (params == null || params.getConnectionTimeout() == 0)
return getSslContext().getSocketFactory().createSocket(remoteHost, remotePort, clientHost, clientPort);
+ if (proxy != null && !Proxy.NO_PROXY.equals(proxy) && proxy.address() instanceof InetSocketAddress) {
+ ProxyClient proxyClient = new ProxyClient();
+
+ InetSocketAddress address = (InetSocketAddress) proxy.address();
+ proxyClient.getHostConfiguration().setProxy(WebClientUtil.getDomain(address.getHostName()),
+ address.getPort());
+ proxyClient.getHostConfiguration().setHost(remoteHost, remotePort);
+ if (proxy instanceof AuthenticatedProxy) {
+ AuthenticatedProxy authProxy = (AuthenticatedProxy) proxy;
+ Credentials credentials = new UsernamePasswordCredentials(authProxy.getUserName(), authProxy
+ .getPassword());
+ AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM);
+ proxyClient.getState().setProxyCredentials(proxyAuthScope, credentials);
+ }
+
+ ProxyClient.ConnectResponse response = proxyClient.connect();
+ if (response.getSocket() != null) {
+ // tunnel SSL via the resultant socket
+ Socket sslsocket = getSslContext().getSocketFactory().createSocket(response.getSocket(), remoteHost,
+ remotePort, true);
+ return sslsocket;
+ } else {
+ MylarStatusHandler.log("Could not make proxy connection. Trying direct...", this);
+ }
+
+ }
+
Socket socket = getSslContext().getSocketFactory().createSocket();
socket.bind(new InetSocketAddress(clientHost, clientPort));
socket.connect(new InetSocketAddress(remoteHost, remotePort), params.getConnectionTimeout());
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
index 44a4c671e..8b869d3a0 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
@@ -15,7 +15,6 @@ import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
-import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
@@ -115,17 +114,6 @@ public class WebClientUtil {
//System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
- if (proxySettings != null && proxySettings.address() instanceof InetSocketAddress) {
- InetSocketAddress address = (InetSocketAddress) proxySettings.address();
- client.getHostConfiguration().setProxy(WebClientUtil.getDomain(address.getHostName()), address.getPort());
- if (proxySettings instanceof AuthenticatedProxy) {
- AuthenticatedProxy authProxy = (AuthenticatedProxy) proxySettings;
- Credentials credentials = new UsernamePasswordCredentials(authProxy.getUserName(), authProxy
- .getPassword());
- AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM);
- client.getState().setProxyCredentials(proxyAuthScope, credentials);
- }
- }
if (user != null && password != null) {
AuthScope authScope = new AuthScope(WebClientUtil.getDomain(repositoryUrl), WebClientUtil
@@ -134,7 +122,7 @@ public class WebClientUtil {
}
if (WebClientUtil.repositoryUsesHttps(repositoryUrl)) {
- Protocol acceptAllSsl = new Protocol("https", new SslProtocolSocketFactory(), WebClientUtil
+ Protocol acceptAllSsl = new Protocol("https", new SslProtocolSocketFactory(proxySettings), WebClientUtil
.getPort(repositoryUrl));
client.getHostConfiguration().setHost(WebClientUtil.getDomain(repositoryUrl),
WebClientUtil.getPort(repositoryUrl), acceptAllSsl);

Back to the top