Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2013-03-09 07:10:03 +0000
committerslewis2013-03-09 07:10:03 +0000
commit57ea952bc814858f856b2a7cd024def292b318fe (patch)
tree5f081c224ea894d2d47cac4c96de33dbcacb1524
parent2bd60e610efc9c61460efd60bb8cfc502c6aabc5 (diff)
downloadorg.eclipse.ecf-57ea952bc814858f856b2a7cd024def292b318fe.tar.gz
org.eclipse.ecf-57ea952bc814858f856b2a7cd024def292b318fe.tar.xz
org.eclipse.ecf-57ea952bc814858f856b2a7cd024def292b318fe.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=402740R-Release_HEAD-sdk_feature-93_2013-03-09_07-11-52
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/META-INF/MANIFEST.MF2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/src/org/eclipse/ecf/internal/provider/filetransfer/httpclient4/HttpClientProxyCredentialProvider.java58
2 files changed, 49 insertions, 11 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/META-INF/MANIFEST.MF
index 1d64634cf..5c54c11d6 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf.provider.filetransfer.httpclient4;singleton:=true
-Bundle-Version: 1.0.200.qualifier
+Bundle-Version: 1.0.300.qualifier
Bundle-Localization: plugin
Bundle-Activator: org.eclipse.ecf.internal.provider.filetransfer.httpclient4.Activator
Require-Bundle: org.eclipse.equinox.common,
diff --git a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/src/org/eclipse/ecf/internal/provider/filetransfer/httpclient4/HttpClientProxyCredentialProvider.java b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/src/org/eclipse/ecf/internal/provider/filetransfer/httpclient4/HttpClientProxyCredentialProvider.java
index e8407f82e..56868d098 100644
--- a/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/src/org/eclipse/ecf/internal/provider/filetransfer/httpclient4/HttpClientProxyCredentialProvider.java
+++ b/providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclient4/src/org/eclipse/ecf/internal/provider/filetransfer/httpclient4/HttpClientProxyCredentialProvider.java
@@ -11,13 +11,14 @@
*******************************************************************************/
package org.eclipse.ecf.internal.provider.filetransfer.httpclient4;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.eclipse.ecf.core.util.Proxy;
+import org.eclipse.ecf.core.util.ProxyAddress;
import org.eclipse.ecf.core.util.Trace;
public abstract class HttpClientProxyCredentialProvider implements CredentialsProvider {
@@ -29,25 +30,34 @@ public abstract class HttpClientProxyCredentialProvider implements CredentialsPr
private Map cachedCredentials;
public HttpClientProxyCredentialProvider() {
- cachedCredentials = new HashMap();
+ cachedCredentials = new ConcurrentHashMap<AuthScope, Credentials>();
}
public void setCredentials(AuthScope authscope, Credentials credentials) {
+ if (authscope == null)
+ throw new IllegalArgumentException("Authentication scope may not be null"); //$NON-NLS-1$
this.cachedCredentials.put(authscope, credentials);
}
public Credentials getCredentials(AuthScope authscope) {
Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, HttpClientProxyCredentialProvider.class, "getCredentials " + authscope); //$NON-NLS-1$
- if (this.cachedCredentials.containsKey(authscope)) {
- return (Credentials) this.cachedCredentials.get(authscope);
- }
-
+ // First check to see whether given authscope matches any authscope
+ // already cached.
+ Credentials result = matchCredentials(this.cachedCredentials, authscope);
+ // If we have a match, return credentials
+ if (result != null)
+ return result;
+ // If we don't have a match, first get ECF proxy, if any
Proxy proxy = getECFProxy();
- if (proxy == null) {
+ if (proxy == null)
return null;
- }
+ // Make sure that authscope and proxy host and port match
+ if (!matchAuthScopeAndProxy(authscope, proxy))
+ return null;
+
+ // Then match scheme, and get credentials from proxy (if it's scheme we know about)
Credentials credentials = null;
if ("ntlm".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$
credentials = getNTLMCredentials(proxy);
@@ -55,6 +65,7 @@ public abstract class HttpClientProxyCredentialProvider implements CredentialsPr
"digest".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$
final String proxyUsername = proxy.getUsername();
final String proxyPassword = proxy.getPassword();
+ // If credentials present for proxy then we're done
if (proxyUsername != null) {
credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
}
@@ -64,13 +75,40 @@ public abstract class HttpClientProxyCredentialProvider implements CredentialsPr
Trace.trace(Activator.PLUGIN_ID, "Unrecognized authentication scheme."); //$NON-NLS-1$
}
- if (credentials != null) {
+ // Put found credentials in cache for next time
+ if (credentials != null)
cachedCredentials.put(authscope, credentials);
- }
return credentials;
}
+ private boolean matchAuthScopeAndProxy(AuthScope authscope, Proxy proxy) {
+ ProxyAddress proxyAddress = proxy.getAddress();
+ return (authscope.getHost().equals(proxyAddress.getHostName()) && (authscope.getPort() == proxyAddress.getPort()));
+ }
+
+ private static Credentials matchCredentials(final Map<AuthScope, Credentials> map, final AuthScope authscope) {
+ // see if we get a direct hit
+ Credentials creds = map.get(authscope);
+ if (creds == null) {
+ // Nope.
+ // Do a full scan
+ int bestMatchFactor = -1;
+ AuthScope bestMatch = null;
+ for (AuthScope current : map.keySet()) {
+ int factor = authscope.match(current);
+ if (factor > bestMatchFactor) {
+ bestMatchFactor = factor;
+ bestMatch = current;
+ }
+ }
+ if (bestMatch != null) {
+ creds = map.get(bestMatch);
+ }
+ }
+ return creds;
+ }
+
public void clear() {
this.cachedCredentials.clear();
}

Back to the top