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 (-33 / +2 lines)
Lines 18-39 Link Here
18
import java.util.List;
18
import java.util.List;
19
import java.util.Properties;
19
import java.util.Properties;
20
20
21
import org.eclipse.core.internal.net.auth.ProxyAuthenticator;
21
import org.eclipse.core.net.proxy.IProxyChangeEvent;
22
import org.eclipse.core.net.proxy.IProxyChangeEvent;
22
import org.eclipse.core.net.proxy.IProxyChangeListener;
23
import org.eclipse.core.net.proxy.IProxyChangeListener;
23
import org.eclipse.core.net.proxy.IProxyData;
24
import org.eclipse.core.net.proxy.IProxyData;
24
import org.eclipse.core.net.proxy.IProxyService;
25
import org.eclipse.core.net.proxy.IProxyService;
25
import org.eclipse.core.runtime.Assert;
26
import org.eclipse.core.runtime.Assert;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IConfigurationElement;
28
import org.eclipse.core.runtime.IExtension;
29
import org.eclipse.core.runtime.ISafeRunnable;
27
import org.eclipse.core.runtime.ISafeRunnable;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.ListenerList;
28
import org.eclipse.core.runtime.ListenerList;
32
import org.eclipse.core.runtime.RegistryFactory;
33
import org.eclipse.core.runtime.SafeRunner;
29
import org.eclipse.core.runtime.SafeRunner;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
30
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
35
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
31
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
36
import org.eclipse.osgi.util.NLS;
37
import org.osgi.service.prefs.BackingStoreException;
32
import org.osgi.service.prefs.BackingStoreException;
38
33
39
public class ProxyManager implements IProxyService, IPreferenceChangeListener {
34
public class ProxyManager implements IProxyService, IPreferenceChangeListener {
Lines 272-278 Link Here
272
			ProxyType type = proxies[i];
267
			ProxyType type = proxies[i];
273
			type.initialize();
268
			type.initialize();
274
		}
269
		}
275
		registerAuthenticator();
270
		Authenticator.setDefault(new ProxyAuthenticator());
276
	}
271
	}
277
272
278
	public IProxyData getProxyData(String type) {
273
	public IProxyData getProxyData(String type) {
Lines 370-401 Link Here
370
		return null;
365
		return null;
371
	}
366
	}
372
	
367
	
373
	private void registerAuthenticator() {
374
		Authenticator a = getPluggedInAuthenticator();
375
		if (a != null) {
376
			Authenticator.setDefault(a);
377
		}
378
	}
379
	
380
	private Authenticator getPluggedInAuthenticator() {
381
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
382
		if (extensions.length == 0)
383
			return null;
384
		IExtension extension = extensions[0];
385
		IConfigurationElement[] configs = extension.getConfigurationElements();
386
		if (configs.length == 0) {
387
			Activator.log(IStatus.ERROR, NLS.bind("Authenticator {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$ 
388
			return null;
389
		}
390
		try {
391
			IConfigurationElement config = configs[0];
392
			return (Authenticator) config.createExecutableExtension("class");//$NON-NLS-1$ 
393
		} catch (CoreException ex) {
394
			Activator.log(IStatus.ERROR, NLS.bind("Unable to instantiate authenticator {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ 
395
			return null;
396
		}
397
	}
398
	
399
	private synchronized void checkMigrated() {
368
	private synchronized void checkMigrated() {
400
		if (preferenceManager.isMigrated() || !Activator.getInstance().instanceLocationAvailable()) {
369
		if (preferenceManager.isMigrated() || !Activator.getInstance().instanceLocationAvailable()) {
401
			return;
370
			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