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 / +20 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 org.eclipse.core.net.proxy.IProxyData;
17
import org.eclipse.core.net.proxy.IProxyService;
16
import org.eclipse.ui.plugin.AbstractUIPlugin;
18
import org.eclipse.ui.plugin.AbstractUIPlugin;
17
import org.osgi.framework.BundleContext;
19
import org.osgi.framework.BundleContext;
20
import org.osgi.framework.ServiceReference;
18
21
19
/**
22
/**
20
 * The activator class controls the plug-in life cycle
23
 * The activator class controls the plug-in life cycle
Lines 27-32 Link Here
27
	// The shared instance
30
	// The shared instance
28
	private static Activator plugin;
31
	private static Activator plugin;
29
32
33
	// The bundle context
34
	private BundleContext context;
35
30
	/**
36
	/**
31
	 * The constructor
37
	 * The constructor
32
	 */
38
	 */
Lines 44-55 Link Here
44
	}
50
	}
45
51
46
	public void start(BundleContext context) throws Exception {
52
	public void start(BundleContext context) throws Exception {
47
		super.start(context);
53
	  super.start(context);
54
	  this.context = context;
48
	}
55
	}
49
56
50
	public void stop(BundleContext context) throws Exception {
57
	public void stop(BundleContext context) throws Exception {
51
		plugin = null;
58
		plugin = null;
52
		super.stop(context);
59
		super.stop(context);
60
		context = null;
61
	}
62
	
63
	public IProxyData[] getProxyData() {
64
		  if (context == null) {
65
		    return null;
66
		  }
67
		  ServiceReference proxyServiceReference = context.getServiceReference(IProxyService.class.getName());
68
		  IProxyService proxyService = (IProxyService) context.getService(proxyServiceReference);
69
		  context.ungetService(proxyServiceReference);
70
		  return proxyService.getProxyData();
53
	}
71
	}
54
55
}
72
}
(-)src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java (-3 / +42 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.util.HashSet;
17
import java.util.Set;
18
19
import org.eclipse.core.net.proxy.IProxyData;
20
import org.eclipse.ui.internal.net.Activator;
14
21
15
public class NetAuthenticator extends Authenticator {
22
public class NetAuthenticator extends Authenticator {
23
24
	/*
25
	 * This set stores all used proxy hosts. Hosts are stored to avoid
26
	 * repeatable attempts to server if proxy credentials for the server are
27
	 * invalid.
28
	 * The access to the this set must be synchronized.
29
	 */
30
	private Set usedProxyHosts = new HashSet();
16
	
31
	
17
	/*
32
	/*
18
	 * @see Authenticator#getPasswordAuthentication()
33
	 * @see Authenticator#getPasswordAuthentication()
19
	 */
34
	 */
20
	protected PasswordAuthentication getPasswordAuthentication() {
35
	protected PasswordAuthentication getPasswordAuthentication() {
21
		// String protocol = getRequestingProtocol();
36
		IProxyData[] proxyDatas = Activator.getDefault().getProxyData();
37
		if (proxyDatas != null && proxyDatas.length > 0) {
38
			for (int i = 0; i < proxyDatas.length; i++) {
39
				final IProxyData iProxyData = proxyDatas[i];
40
				final String proxyHost = iProxyData.getHost();
41
				int proxyPort = iProxyData.getPort();
42
				
43
				// Assuming that if proxy host and port from proxy data is the
44
				// same as requesting host/port it is request for proxy
45
				// authentication.
46
				if (proxyHost != null && proxyHost.equals(getRequestingHost())
47
						&& proxyPort == getRequestingPort()) {
48
					synchronized (usedProxyHosts) {
49
						if (!usedProxyHosts.contains(proxyHost)) {
50
							usedProxyHosts.add(proxyHost);
51
							return new PasswordAuthentication(
52
									iProxyData.getUserId(), 
53
									iProxyData.getPassword().toCharArray());
54
						}
55
					}
56
				}
57
			}
58
		}
59
60
        // String protocol = getRequestingProtocol();
22
		InetAddress address = getRequestingSite(); // can be null;
61
		InetAddress address = getRequestingSite(); // can be null;
23
		// int port = getRequestingPort();
62
		// int port = getRequestingPort();
24
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null
63
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null

Return to bug 312228