View | Details | Raw Unified | Return to bug 312228 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/net/Activator.java (-3 / +32 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-20 Link Here
13
 *******************************************************************************/
13
 *******************************************************************************/
14
package org.eclipse.ui.internal.net;
14
package org.eclipse.ui.internal.net;
15
15
16
import java.net.URI;
17
import java.net.URISyntaxException;
18
import java.net.URL;
19
20
import org.eclipse.core.net.proxy.IProxyData;
21
import org.eclipse.core.net.proxy.IProxyService;
16
import org.eclipse.ui.plugin.AbstractUIPlugin;
22
import org.eclipse.ui.plugin.AbstractUIPlugin;
17
import org.osgi.framework.BundleContext;
23
import org.osgi.framework.BundleContext;
24
import org.osgi.framework.ServiceReference;
18
25
19
/**
26
/**
20
 * The activator class controls the plug-in life cycle
27
 * The activator class controls the plug-in life cycle
Lines 27-32 Link Here
27
	// The shared instance
34
	// The shared instance
28
	private static Activator plugin;
35
	private static Activator plugin;
29
36
37
	// The bundle context
38
	private BundleContext context;
39
30
	/**
40
	/**
31
	 * The constructor
41
	 * The constructor
32
	 */
42
	 */
Lines 44-55 Link Here
44
	}
54
	}
45
55
46
	public void start(BundleContext context) throws Exception {
56
	public void start(BundleContext context) throws Exception {
47
		super.start(context);
57
	  super.start(context);
58
	  this.context = context;
48
	}
59
	}
49
60
50
	public void stop(BundleContext context) throws Exception {
61
	public void stop(BundleContext context) throws Exception {
51
		plugin = null;
62
		plugin = null;
52
		super.stop(context);
63
		super.stop(context);
64
		context = null;
65
	}
66
	
67
	public IProxyData[] getProxyData(URL url) {
68
		  if (context == null || url == null) {
69
		    return null;
70
		  }
71
		  ServiceReference proxyServiceReference = context.getServiceReference(IProxyService.class.getName());
72
		  IProxyService proxyService = (IProxyService) context.getService(proxyServiceReference);
73
		  try {
74
		    URI uri = url.toURI();
75
		    return proxyService.select(uri);
76
		  }
77
		  catch (URISyntaxException e) {
78
		    // Nothing to do.
79
		  } finally {
80
			  context.ungetService(proxyServiceReference);
81
		  }
82
		  return null;
53
	}
83
	}
54
55
}
84
}
(-)src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java (-3 / +89 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-24 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net.auth;
11
package org.eclipse.ui.internal.net.auth;
12
12
13
import java.net.*;
13
import java.net.Authenticator;
14
import java.net.InetAddress;
15
import java.net.PasswordAuthentication;
16
import java.net.URL;
17
import java.util.HashSet;
18
import java.util.Set;
19
20
import org.eclipse.core.net.proxy.IProxyData;
21
import org.eclipse.ui.internal.net.Activator;
14
22
15
public class NetAuthenticator extends Authenticator {
23
public class NetAuthenticator extends Authenticator {
16
	
24
	
17
	/*
25
	/*
26
	 * This is class storing PasswordAuthentication credentials to enable comparing this data. 
27
	 */
28
	private class ComparablePasswordAuthentication {
29
		private final String userName;
30
		private final String password;
31
		public ComparablePasswordAuthentication(String userName, String password) {
32
			this.userName = userName;
33
			this.password = password;
34
		}
35
		public int hashCode() {
36
			final int prime = 31;
37
			int result = 1;
38
			result = prime * result + getOuterType().hashCode();
39
			result = prime * result
40
					+ ((password == null) ? 0 : password.hashCode());
41
			result = prime * result
42
					+ ((userName == null) ? 0 : userName.hashCode());
43
			return result;
44
		}
45
		public boolean equals(Object obj) {
46
			if (this == obj)
47
				return true;
48
			if (obj == null)
49
				return false;
50
			if (getClass() != obj.getClass())
51
				return false;
52
			ComparablePasswordAuthentication other = (ComparablePasswordAuthentication) obj;
53
			if (!getOuterType().equals(other.getOuterType()))
54
				return false;
55
			if (password == null) {
56
				if (other.password != null)
57
					return false;
58
			} else if (!password.equals(other.password))
59
				return false;
60
			if (userName == null) {
61
				if (other.userName != null)
62
					return false;
63
			} else if (!userName.equals(other.userName))
64
				return false;
65
			return true;
66
		}
67
		private NetAuthenticator getOuterType() {
68
			return NetAuthenticator.this;
69
		}
70
		
71
	}
72
73
	/*
74
	 * This set stores all used password credentials to avoid blocking by proxy
75
	 * server as a consequence of to many failed requests to proxy server. 
76
	 * The access to the this set must be synchronized.
77
	 */
78
	private Set usedPasswordCredentials = new HashSet();
79
	
80
	/*
18
	 * @see Authenticator#getPasswordAuthentication()
81
	 * @see Authenticator#getPasswordAuthentication()
19
	 */
82
	 */
20
	protected PasswordAuthentication getPasswordAuthentication() {
83
	protected PasswordAuthentication getPasswordAuthentication() {
21
		// String protocol = getRequestingProtocol();
84
		RequestorType requestorType = getRequestorType();
85
		if (requestorType == RequestorType.PROXY) {
86
			URL url = getRequestingURL();
87
			IProxyData[] proxyDatas = Activator.getDefault().getProxyData(url);
88
			if (proxyDatas != null && proxyDatas.length > 0) {
89
				for (int i = 0; i < proxyDatas.length; i++) {
90
					IProxyData iProxyData = proxyDatas[i];
91
					final String userName = iProxyData.getUserId();
92
					final String password = iProxyData.getPassword();
93
					ComparablePasswordAuthentication passwordAuthentication = 
94
						new ComparablePasswordAuthentication(userName, password);
95
					synchronized (usedPasswordCredentials) {
96
						if (!usedPasswordCredentials
97
								.contains(passwordAuthentication)) {
98
							usedPasswordCredentials.add(passwordAuthentication);
99
							return new PasswordAuthentication(userName,
100
									password.toCharArray());
101
						}
102
					}
103
				}
104
			}
105
		}
106
107
        // String protocol = getRequestingProtocol();
22
		InetAddress address = getRequestingSite(); // can be null;
108
		InetAddress address = getRequestingSite(); // can be null;
23
		// int port = getRequestingPort();
109
		// int port = getRequestingPort();
24
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null
110
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null

Return to bug 312228