Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2010-04-23 19:22:55 -0400
committerslewis2010-04-23 19:22:55 -0400
commit6b8c19c82d509ef6ecd9f46e8c35f293f886f1a0 (patch)
tree0f39a52759ffed83337549164044a186c54aa7c7 /providers/bundles/org.eclipse.ecf.provider.filetransfer
parenta6759754bb3ab92c5b2f8ba99006dd298264937a (diff)
downloadorg.eclipse.ecf-6b8c19c82d509ef6ecd9f46e8c35f293f886f1a0.tar.gz
org.eclipse.ecf-6b8c19c82d509ef6ecd9f46e8c35f293f886f1a0.tar.xz
org.eclipse.ecf-6b8c19c82d509ef6ecd9f46e8c35f293f886f1a0.zip
Fix for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=295030. Applied from patch https://bugs.eclipse.org/bugs/attachment.cgi?id=165981 from Henrich Kraemer.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.filetransfer')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java49
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/outgoing/AbstractOutgoingFileTransfer.java34
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java29
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/JREProxyHelper.java15
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/ProxySetupHelper.java97
5 files changed, 126 insertions, 98 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java
index 331bedcdc..b75fa3835 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/browse/AbstractFileSystemBrowser.java
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2007, 2009 Composent, Inc., IBM and others.
+ * Copyright (c) 2007, 2010 Composent, Inc., IBM and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,12 +12,12 @@
package org.eclipse.ecf.provider.filetransfer.browse;
-import java.net.URI;
+import org.eclipse.ecf.provider.filetransfer.util.ProxySetupHelper;
+
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -25,7 +25,6 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.Proxy;
-import org.eclipse.ecf.core.util.ProxyAddress;
import org.eclipse.ecf.filetransfer.IRemoteFile;
import org.eclipse.ecf.filetransfer.IRemoteFileSystemListener;
import org.eclipse.ecf.filetransfer.IRemoteFileSystemRequest;
@@ -33,7 +32,6 @@ import org.eclipse.ecf.filetransfer.UserCancelledException;
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemBrowseEvent;
import org.eclipse.ecf.filetransfer.events.IRemoteFileSystemEvent;
import org.eclipse.ecf.filetransfer.identity.IFileID;
-import org.eclipse.ecf.internal.provider.filetransfer.Activator;
import org.eclipse.ecf.internal.provider.filetransfer.Messages;
/**
@@ -211,50 +209,13 @@ public abstract class AbstractFileSystemBrowser {
* @return proxy data selected from the proxies provided.
*/
protected IProxyData selectProxyFromProxies(String protocol, IProxyData[] proxies) {
- if (proxies == null || proxies.length == 0)
- return null;
- // If only one proxy is available, then use that
- if (proxies.length == 1)
- return proxies[0];
- // If more than one proxy is available, then if http/https protocol then look for that
- // one...if not found then use first
- if (protocol.equalsIgnoreCase("http")) { //$NON-NLS-1$
- for (int i = 0; i < proxies.length; i++) {
- if (proxies[i].getType().equals(IProxyData.HTTP_PROXY_TYPE))
- return proxies[i];
- }
- } else if (protocol.equalsIgnoreCase("https")) { //$NON-NLS-1$
- for (int i = 0; i < proxies.length; i++) {
- if (proxies[i].getType().equals(IProxyData.HTTPS_PROXY_TYPE))
- return proxies[i];
- }
- }
- // If we haven't found it yet, then return the first one.
- return proxies[0];
+ return ProxySetupHelper.selectProxyFromProxies(protocol, proxies);
}
protected void setupProxies() {
// If it's been set directly (via ECF API) then this overrides platform settings
if (proxy == null) {
- try {
- IProxyService proxyService = Activator.getDefault().getProxyService();
- // Only do this if platform service exists
- if (proxyService != null && proxyService.isProxiesEnabled()) {
- // Setup via proxyService entry
- URI target = new URI(directoryOrFile.toExternalForm());
- final IProxyData[] proxies = proxyService.select(target);
- IProxyData selectedProxy = selectProxyFromProxies(target.getScheme(), proxies);
- if (selectedProxy != null) {
- proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
- }
- }
- } catch (Exception e) {
- // If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available)
- // then we simply log and ignore
- Activator.logNoProxyWarning(e);
- } catch (NoClassDefFoundError e) {
- Activator.logNoProxyWarning(e);
- }
+ proxy = ProxySetupHelper.getProxy(directoryOrFile.toExternalForm());
}
if (proxy != null)
setupProxy(proxy);
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/outgoing/AbstractOutgoingFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/outgoing/AbstractOutgoingFileTransfer.java
index 95ecf8c4d..6d93be26d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/outgoing/AbstractOutgoingFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/outgoing/AbstractOutgoingFileTransfer.java
@@ -1,24 +1,25 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 Composent, Inc. All rights reserved. This
+ * Copyright (c) 2004, 2010 Composent, Inc. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Composent, Inc. - initial API and implementation
* Cloudsmith, Inc. - additional API and implementation
+ * Henrich Kraemer - bug 295030, Update Manager doesn't work with SOCKS proxy
******************************************************************************/
package org.eclipse.ecf.provider.filetransfer.outgoing;
+import org.eclipse.ecf.provider.filetransfer.util.ProxySetupHelper;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
-import java.net.URI;
import java.net.URL;
import java.util.Map;
import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -30,7 +31,6 @@ import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.Proxy;
-import org.eclipse.ecf.core.util.ProxyAddress;
import org.eclipse.ecf.filetransfer.FileTransferInfo;
import org.eclipse.ecf.filetransfer.FileTransferJob;
import org.eclipse.ecf.filetransfer.IFileTransferInfo;
@@ -357,31 +357,7 @@ public abstract class AbstractOutgoingFileTransfer implements IOutgoingFileTrans
protected void setupProxies() {
// If it's been set directly (via ECF API) then this overrides platform settings
if (proxy == null) {
- try {
- IProxyService proxyService = Activator.getDefault().getProxyService();
- // Only do this if platform service exists
- if (proxyService != null && proxyService.isProxiesEnabled()) {
- // Setup via proxyService entry
- URI target = new URI(getRemoteFileURL().toExternalForm());
- String type = IProxyData.SOCKS_PROXY_TYPE;
- if (target.getScheme().equalsIgnoreCase(IProxyData.HTTP_PROXY_TYPE)) {
- type = IProxyData.HTTP_PROXY_TYPE;
- } else if (target.getScheme().equalsIgnoreCase(IProxyData.HTTPS_PROXY_TYPE)) {
- type = IProxyData.HTTPS_PROXY_TYPE;
- }
- final IProxyData[] proxyDatas = proxyService.select(target);
- final IProxyData proxyData = selectProxyFromProxies(target.getScheme(), proxyDatas);
- if (proxyData != null) {
- proxy = new Proxy(((type.equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(proxyData.getHost(), proxyData.getPort()), proxyData.getUserId(), proxyData.getPassword());
- }
- }
- } catch (Exception e) {
- // If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available)
- // then we simply log and ignore
- Activator.logNoProxyWarning(e);
- } catch (NoClassDefFoundError e) {
- Activator.logNoProxyWarning(e);
- }
+ proxy = ProxySetupHelper.getProxy(getRemoteFileURL().toExternalForm());
}
if (proxy != null)
setupProxy(proxy);
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
index c4a251e24..41f90661e 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/retrieve/AbstractRetrieveFileTransfer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 Composent, Inc. and others.
+ * Copyright (c) 2004, 2010 Composent, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,9 +8,12 @@
* Contributors:
* Composent, Inc. - initial API and implementation
* Benjamin Cabe <benjamin.cabe@anyware-tech.com> - bug 220258
+ * Henrich Kraemer - bug 295030, Update Manager doesn't work with SOCKS proxy
******************************************************************************/
package org.eclipse.ecf.provider.filetransfer.retrieve;
+import org.eclipse.ecf.provider.filetransfer.util.ProxySetupHelper;
+
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -18,13 +21,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
-import java.net.URI;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Map;
import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IPath;
@@ -39,7 +40,6 @@ import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
import org.eclipse.ecf.core.util.Proxy;
-import org.eclipse.ecf.core.util.ProxyAddress;
import org.eclipse.ecf.filetransfer.FileTransferJob;
import org.eclipse.ecf.filetransfer.IFileRangeSpecification;
import org.eclipse.ecf.filetransfer.IFileTransferListener;
@@ -941,26 +941,7 @@ public abstract class AbstractRetrieveFileTransfer implements IIncomingFileTrans
// If it's been set directly (via ECF API) then this overrides platform
// settings
if (proxy == null) {
- try {
- IProxyService proxyService = Activator.getDefault().getProxyService();
- // Only do this if platform service exists
- if (proxyService != null && proxyService.isProxiesEnabled()) {
- // Setup via proxyService entry
- URI target = new URI(getRemoteFileURL().toExternalForm());
- final IProxyData[] proxies = proxyService.select(target);
- IProxyData selectedProxy = selectProxyFromProxies(target.getScheme(), proxies);
- if (selectedProxy != null) {
- proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
- }
- }
- } catch (Exception e) {
- // If we don't even have the classes for this (i.e. the
- // org.eclipse.core.net plugin not available)
- // then we simply log and ignore
- Activator.logNoProxyWarning(e);
- } catch (NoClassDefFoundError e) {
- Activator.logNoProxyWarning(e);
- }
+ proxy = ProxySetupHelper.getProxy(getRemoteFileURL().toExternalForm());
}
if (proxy != null)
setupProxy(proxy);
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/JREProxyHelper.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/JREProxyHelper.java
index 611a32e2b..3d7414ee1 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/JREProxyHelper.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/JREProxyHelper.java
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2007 Composent, Inc. and others.
+ * Copyright (c) 2007, 2010 Composent, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Composent, Inc. - initial API and implementation
+ * Henrich Kraemer - bug 295030, Update Manager doesn't work with SOCKS proxy
*****************************************************************************/
package org.eclipse.ecf.provider.filetransfer.util;
@@ -48,6 +49,7 @@ public class JREProxyHelper {
if (proxyPort != -1)
systemProperties.setProperty(proxyPortProperty, proxyPort + ""); //$NON-NLS-1$
final String username = proxy2.getUsername();
+ boolean setAuthenticator = false;
if (username != null && !username.equals("")) { //$NON-NLS-1$
final String password = (proxy2.getPassword() == null) ? "" : proxy2.getPassword(); //$NON-NLS-1$
if (proxy2.hasCredentials()) {
@@ -59,8 +61,19 @@ public class JREProxyHelper {
return new PasswordAuthentication(username, password.toCharArray());
}
});
+ setAuthenticator = true;
}
}
+ if (!setAuthenticator) {
+ Authenticator.setDefault(new Authenticator() {
+ /* (non-Javadoc)
+ * @see java.net.Authenticator#getPasswordAuthentication()
+ */
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return null;
+ }
+ });
+ }
}
public void dispose() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/ProxySetupHelper.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/ProxySetupHelper.java
new file mode 100644
index 000000000..8e1b9e5a2
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer/src/org/eclipse/ecf/provider/filetransfer/util/ProxySetupHelper.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+* Copyright (c) 2010 IBM, and others.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* IBM Corporation - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.provider.filetransfer.util;
+
+import java.net.URI;
+import java.net.URL;
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.net.proxy.IProxyService;
+import org.eclipse.ecf.core.util.Proxy;
+import org.eclipse.ecf.core.util.ProxyAddress;
+import org.eclipse.ecf.internal.provider.filetransfer.Activator;
+
+/**
+ * Proxy setup utilities.
+ *
+ * @noextend This class is not intended to be extended by clients.
+ * @since 3.1
+ */
+public class ProxySetupHelper {
+ public static Proxy getProxy(String url) {
+ Proxy proxy = null;
+ try {
+ IProxyService proxyService = Activator.getDefault().getProxyService();
+ // Only do this if platform service exists
+ if (proxyService != null && proxyService.isProxiesEnabled()) {
+ // Setup via proxyService entry
+ URI uri = new URI(url);
+ final IProxyData[] proxies = proxyService.select(uri);
+ IProxyData selectedProxy = selectProxyFromProxies(uri.getScheme(), proxies);
+ if (selectedProxy != null) {
+ proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
+ }
+ }
+ } catch (Exception e) {
+ // If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available)
+ // then we simply log and ignore
+ Activator.logNoProxyWarning(e);
+ } catch (NoClassDefFoundError e) {
+ Activator.logNoProxyWarning(e);
+ }
+ return proxy;
+ }
+
+ public static Proxy getSocksProxy(URL url) {
+ String host = url.getHost();
+ int port = url.getPort();
+ String strURL = IProxyData.SOCKS_PROXY_TYPE + "://" + host; //$NON-NLS-1$
+ if (port != -1) {
+ strURL += ":" + port; //$NON-NLS-1$
+ }
+ return ProxySetupHelper.getProxy(strURL);
+ }
+
+ /**
+ * Select a single proxy from a set of proxies available for the given host. This implementation
+ * selects in the following manner: 1) If proxies provided is null or array of 0 length, null
+ * is returned. If only one proxy is available (array of length 1) then the entry is returned.
+ * If proxies provided is length > 1, then if the type of a proxy in the array matches the given
+ * protocol (e.g. http, https), then the first matching proxy is returned. If the protocol does
+ * not match any of the proxies, then the *first* proxy (i.e. proxies[0]) is returned.
+ *
+ * @param protocol the target protocol (e.g. http, https, scp, etc). Will not be <code>null</code>.
+ * @param proxies the proxies to select from. May be <code>null</code> or array of length 0.
+ * @return proxy data selected from the proxies provided.
+ */
+ public static IProxyData selectProxyFromProxies(String protocol, IProxyData[] proxies) {
+ if (proxies == null || proxies.length == 0)
+ return null;
+ // If only one proxy is available, then use that
+ if (proxies.length == 1)
+ return proxies[0];
+ // If more than one proxy is available, then if http/https protocol then look for that
+ // one...if not found then use first
+ if (protocol.equalsIgnoreCase("http")) { //$NON-NLS-1$
+ for (int i = 0; i < proxies.length; i++) {
+ if (proxies[i].getType().equals(IProxyData.HTTP_PROXY_TYPE))
+ return proxies[i];
+ }
+ } else if (protocol.equalsIgnoreCase("https")) { //$NON-NLS-1$
+ for (int i = 0; i < proxies.length; i++) {
+ if (proxies[i].getType().equals(IProxyData.HTTPS_PROXY_TYPE))
+ return proxies[i];
+ }
+ }
+ // If we haven't found it yet, then return the first one.
+ return proxies[0];
+ }
+
+}

Back to the top