Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 313916 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 13-18 Link Here
13
 org.eclipse.equinox.registry;bundle-version="3.4.0"
13
 org.eclipse.equinox.registry;bundle-version="3.4.0"
14
Bundle-ActivationPolicy: lazy
14
Bundle-ActivationPolicy: lazy
15
Export-Package: org.eclipse.core.internal.net;x-friends:="org.eclipse.ui.net",
15
Export-Package: org.eclipse.core.internal.net;x-friends:="org.eclipse.ui.net",
16
 org.eclipse.core.internal.net.auth;x-friends:="org.eclipse.ui.net",
16
 org.eclipse.core.net.proxy
17
 org.eclipse.core.net.proxy
17
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
18
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
18
 CDC-1.1/Foundation-1.1
19
 CDC-1.1/Foundation-1.1
(-)schema/authenticator.exsd (-1 / +1 lines)
Lines 50-56 Link Here
50
                  
50
                  
51
               </documentation>
51
               </documentation>
52
               <appInfo>
52
               <appInfo>
53
                  <meta.attribute kind="java" basedOn="java.net.Authenticator"/>
53
                  <meta.attribute kind="java" basedOn=":org.eclipse.core.internal.net.auth.IAuthenticator"/>
54
               </appInfo>
54
               </appInfo>
55
            </annotation>
55
            </annotation>
56
         </attribute>
56
         </attribute>
(-)src/org/eclipse/core/internal/net/ProxyManager.java (-34 / +3 lines)
Lines 17-41 Link Here
17
import java.util.List;
17
import java.util.List;
18
import java.util.Properties;
18
import java.util.Properties;
19
19
20
import org.eclipse.core.internal.net.auth.ProxyAuthenticator;
20
import org.eclipse.core.net.proxy.IProxyChangeEvent;
21
import org.eclipse.core.net.proxy.IProxyChangeEvent;
21
import org.eclipse.core.net.proxy.IProxyChangeListener;
22
import org.eclipse.core.net.proxy.IProxyChangeListener;
22
import org.eclipse.core.net.proxy.IProxyData;
23
import org.eclipse.core.net.proxy.IProxyData;
23
import org.eclipse.core.net.proxy.IProxyService;
24
import org.eclipse.core.net.proxy.IProxyService;
24
import org.eclipse.core.runtime.Assert;
25
import org.eclipse.core.runtime.Assert;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IConfigurationElement;
27
import org.eclipse.core.runtime.IExtension;
28
import org.eclipse.core.runtime.ISafeRunnable;
26
import org.eclipse.core.runtime.ISafeRunnable;
29
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.ListenerList;
27
import org.eclipse.core.runtime.ListenerList;
31
import org.eclipse.core.runtime.RegistryFactory;
32
import org.eclipse.core.runtime.SafeRunner;
28
import org.eclipse.core.runtime.SafeRunner;
33
import org.eclipse.core.runtime.preferences.ConfigurationScope;
29
import org.eclipse.core.runtime.preferences.ConfigurationScope;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
30
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
35
import org.eclipse.core.runtime.preferences.InstanceScope;
31
import org.eclipse.core.runtime.preferences.InstanceScope;
36
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
32
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
37
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
33
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
38
import org.eclipse.osgi.util.NLS;
39
import org.osgi.service.prefs.BackingStoreException;
34
import org.osgi.service.prefs.BackingStoreException;
40
import org.osgi.service.prefs.Preferences;
35
import org.osgi.service.prefs.Preferences;
41
36
Lines 281-287 Link Here
281
			ProxyType type = proxies[i];
276
			ProxyType type = proxies[i];
282
			type.initialize();
277
			type.initialize();
283
		}
278
		}
284
		registerAuthenticator();
279
		ProxyAuthenticator a = new ProxyAuthenticator();
280
		Authenticator.setDefault(a);
285
	}
281
	}
286
282
287
	public IProxyData getProxyData(String type) {
283
	public IProxyData getProxyData(String type) {
Lines 378-411 Link Here
378
		}
374
		}
379
		return null;
375
		return null;
380
	}
376
	}
381
	
382
	private void registerAuthenticator() {
383
		Authenticator a = getPluggedInAuthenticator();
384
		if (a != null) {
385
			Authenticator.setDefault(a);
386
		}
387
	}
388
	
389
	private Authenticator getPluggedInAuthenticator() {
390
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
391
		if (extensions.length == 0)
392
			return null;
393
		IExtension extension = extensions[0];
394
		IConfigurationElement[] configs = extension.getConfigurationElements();
395
		if (configs.length == 0) {
396
			Activator.log(IStatus.ERROR, NLS.bind("Authenticator {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$ 
397
			return null;
398
		}
399
		try {
400
			IConfigurationElement config = configs[0];
401
			return (Authenticator) config.createExecutableExtension("class");//$NON-NLS-1$ 
402
		} catch (CoreException ex) {
403
			Activator.log(IStatus.ERROR, NLS.bind("Unable to instantiate authenticator {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ 
404
			return null;
405
		}
406
	}
407
377
408
	
409
	private synchronized void checkMigrated() {
378
	private synchronized void checkMigrated() {
410
		if (migrated || !Activator.getInstance().instanceLocationAvailable())
379
		if (migrated || !Activator.getInstance().instanceLocationAvailable())
411
			return;
380
			return;
(-)src/org/eclipse/core/internal/net/auth/Authentication.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net.auth;
12
13
/**
14
 * Keeps user and password strings.
15
 */
16
public class Authentication {
17
	protected String user;
18
	protected String password;
19
	public Authentication(String user, String password){
20
		this.user = user;
21
		this.password = password;
22
	}
23
24
	/**
25
	 * @return Returns the password.
26
	 */
27
	public String getPassword() {
28
		return password;
29
	}
30
	/**
31
	 * @return Returns the user.
32
	 */
33
	public String getUser() {
34
		return user;
35
	}
36
}
(-)src/org/eclipse/core/internal/net/auth/IAuthenticator.java (+15 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net.auth;
12
13
public interface IAuthenticator {
14
	Authentication getAuthentication(String host, String prompt);
15
}
(-)src/org/eclipse/core/internal/net/auth/ProxyAuthenticator.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net.auth;
12
13
import java.net.*;
14
15
import org.eclipse.core.internal.net.Activator;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IExtension;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.RegistryFactory;
21
import org.eclipse.osgi.util.NLS;
22
23
public class ProxyAuthenticator extends Authenticator {
24
	
25
	private IAuthenticator authenticator;
26
27
	/*
28
	 * @see Authenticator#getPasswordAuthentication()
29
	 */
30
	protected PasswordAuthentication getPasswordAuthentication() {
31
		InetAddress address = getRequestingSite(); // can be null;
32
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null
33
34
		// get the host name from the address since #getRequestingHost
35
		// is not available in the foundation 1.0 class libraries
36
		String hostString = null;
37
		if (address != null) {
38
			hostString = address.getHostName();
39
		}
40
		if (hostString == null) {
41
			hostString = ""; //$NON-NLS-1$
42
		}
43
		String promptString = prompt;
44
		if (prompt == null) {
45
			promptString = ""; //$NON-NLS-1$
46
		}
47
		if (hasAuthenticator()) {
48
			Authentication auth = authenticator.getAuthentication(hostString, promptString);
49
			if (auth != null) {
50
				return new PasswordAuthentication(auth.getUser(), auth.getPassword().toCharArray());
51
			}
52
		}
53
		return null;
54
	}
55
	
56
	private boolean hasAuthenticator() {
57
		if (authenticator != null) {
58
			return true;
59
		}
60
		IExtension[] extensions = RegistryFactory.getRegistry().
61
				getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
62
		if (extensions.length == 0) {
63
			return false;
64
		}
65
		IExtension extension = extensions[0];
66
		IConfigurationElement[] configs = extension.getConfigurationElements();
67
		if (configs.length == 0) {
68
			Activator.log(IStatus.ERROR, NLS.bind("Authenticator {0} is missing required fields", //$NON-NLS-1$ 
69
					(new Object[] {extension.getUniqueIdentifier()})), null);
70
			return false;
71
		}
72
		try {
73
			IConfigurationElement config = configs[0];
74
			authenticator = (IAuthenticator) config.createExecutableExtension("class");//$NON-NLS-1$ 
75
			return true;
76
		} catch (CoreException ex) {
77
			Activator.log(IStatus.ERROR, NLS.bind("Unable to instantiate authenticator {0}", //$NON-NLS-1$ 
78
					(new Object[] {extension.getUniqueIdentifier()})), ex);
79
			return false;
80
		}
81
	}
82
}
(-)plugin.xml (-1 / +1 lines)
Lines 22-28 Link Here
22
  <extension
22
  <extension
23
        point="org.eclipse.core.net.authenticator">
23
        point="org.eclipse.core.net.authenticator">
24
     <authenticator
24
     <authenticator
25
           class="org.eclipse.ui.internal.net.auth.NetAuthenticator">
25
           class="org.eclipse.ui.internal.net.auth.UIAuthenticator">
26
     </authenticator>
26
     </authenticator>
27
  </extension>
27
  </extension>
28
28
(-)src/org/eclipse/ui/internal/net/auth/Authentication.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net.auth;
12
13
/**
14
 * Keeps user and password strings.
15
 */
16
public class Authentication {
17
	protected String user;
18
	protected String password;
19
	public Authentication(String user, String password){
20
		this.user = user;
21
		this.password = password;
22
	}
23
24
	/**
25
	 * @return Returns the password.
26
	 */
27
	public String getPassword() {
28
		return password;
29
	}
30
	/**
31
	 * @return Returns the user.
32
	 */
33
	public String getUser() {
34
		return user;
35
	}
36
}
(-)src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java (-49 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net.auth;
12
13
import java.net.*;
14
15
public class NetAuthenticator extends Authenticator {
16
	
17
	/*
18
	 * @see Authenticator#getPasswordAuthentication()
19
	 */
20
	protected PasswordAuthentication getPasswordAuthentication() {
21
		// String protocol = getRequestingProtocol();
22
		InetAddress address = getRequestingSite(); // can be null;
23
		// int port = getRequestingPort();
24
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null
25
		// String scheme = getRequestingScheme(); // not documented that can be null
26
27
		 // get the host name from the address since #getRequestingHost
28
		 // is not available in the foundation 1.0 class libraries
29
		String hostString = null;
30
		if (address != null) {
31
			hostString = address.getHostName();
32
		}
33
		if (hostString == null) {
34
			hostString = ""; //$NON-NLS-1$
35
		}
36
		String promptString = prompt;
37
		if (prompt == null) {
38
			promptString = ""; //$NON-NLS-1$
39
		}
40
41
		Authentication auth = UserValidationDialog.getAuthentication(
42
				hostString, promptString);
43
		if (auth != null)
44
			return new PasswordAuthentication(auth.getUser(), auth
45
					.getPassword().toCharArray());
46
		else
47
			return null;
48
	}
49
}
(-)src/org/eclipse/ui/internal/net/auth/UIAuthenticator.java (+22 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net.auth;
12
13
import org.eclipse.core.internal.net.auth.Authentication;
14
import org.eclipse.core.internal.net.auth.IAuthenticator;
15
16
public class UIAuthenticator implements IAuthenticator {
17
18
	public Authentication getAuthentication(String host, String prompt) {
19
		return UserValidationDialog.getAuthentication(host, prompt);
20
	}
21
22
}
(-)src/org/eclipse/ui/internal/net/auth/UserValidationDialog.java (-1 / +2 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-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net.auth;
11
package org.eclipse.ui.internal.net.auth;
12
12
13
import org.eclipse.core.internal.net.auth.Authentication;
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jface.dialogs.IDialogConstants;
15
import org.eclipse.jface.dialogs.IDialogConstants;
15
import org.eclipse.osgi.util.NLS;
16
import org.eclipse.osgi.util.NLS;

Return to bug 313916