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 214796 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/net/ProxyType.java (-61 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 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-23 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net;
11
package org.eclipse.core.internal.net;
12
12
13
import java.net.MalformedURLException;
13
import java.util.Properties;
14
import java.net.URL;
15
import java.util.*;
16
14
17
import org.eclipse.core.net.proxy.IProxyData;
15
import org.eclipse.core.net.proxy.IProxyData;
18
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences.*;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
21
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
21
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.osgi.util.NLS;
22
import org.osgi.service.prefs.BackingStoreException;
23
import org.osgi.service.prefs.BackingStoreException;
23
import org.osgi.service.prefs.Preferences;
24
import org.osgi.service.prefs.Preferences;
Lines 48-67 Link Here
48
	public static final int NEVER_SET = 2;
49
	public static final int NEVER_SET = 2;
49
	public static int socksSystemPropertySetting;
50
	public static int socksSystemPropertySetting;
50
	
51
	
51
	/*
52
	 * Fields used to cache authentication information in the keyring
53
	 */
54
    private static final String INFO_PROXY_USER = "user"; //$NON-NLS-1$ 
55
    private static final String INFO_PROXY_PASS = "pass"; //$NON-NLS-1$ 
56
    private static final URL FAKE_URL;
57
    static {
52
    static {
58
        URL temp = null;
59
        try {
60
            temp = new URL("http://org.eclipse.core.net.proxy.auth");//$NON-NLS-1$ 
61
        } catch (MalformedURLException e) {
62
            // Should never fail
63
        }
64
        FAKE_URL = temp;
65
        String value = System.getProperty(PROP_SOCKS_SYSTEM_PROPERTY_HANDLING);
53
        String value = System.getProperty(PROP_SOCKS_SYSTEM_PROPERTY_HANDLING);
66
        if (value == null) {
54
        if (value == null) {
67
        	socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER;
55
        	socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER;
Lines 135-141 Link Here
135
		int port = node.getInt(PREF_PROXY_PORT, -1);
123
		int port = node.getInt(PREF_PROXY_PORT, -1);
136
		boolean requiresAuth = node.getBoolean(PREF_PROXY_HAS_AUTH, false);
124
		boolean requiresAuth = node.getBoolean(PREF_PROXY_HAS_AUTH, false);
137
		ProxyData proxyData = new ProxyData(type, host, port, requiresAuth);
125
		ProxyData proxyData = new ProxyData(type, host, port, requiresAuth);
138
		loadProxyAuth(proxyData);
139
		if (verifyFlag == VERIFY_EMPTY) {
126
		if (verifyFlag == VERIFY_EMPTY) {
140
			// We are initializing so verify that the system properties are empty
127
			// We are initializing so verify that the system properties are empty
141
			verifySystemPropertiesEmpty(type);
128
			verifySystemPropertiesEmpty(type);
Lines 151-157 Link Here
151
		IProxyData oldData = getProxyData(VERIFY_EQUAL);
138
		IProxyData oldData = getProxyData(VERIFY_EQUAL);
152
		if (oldData.equals(proxyData))
139
		if (oldData.equals(proxyData))
153
			return false;
140
			return false;
154
		saveProxyAuth(proxyData);
155
		try {
141
		try {
156
			updatingPreferences = true;
142
			updatingPreferences = true;
157
			updatePreferences(proxyData);
143
			updatePreferences(proxyData);
Lines 476-521 Link Here
476
		((IEclipsePreferences)getPreferenceNode()).addPreferenceChangeListener(this);
462
		((IEclipsePreferences)getPreferenceNode()).addPreferenceChangeListener(this);
477
	}
463
	}
478
	
464
	
479
    private Map getAuthInfo() {
480
		// Retrieve username and password from keyring.
481
		Map authInfo = Platform.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
482
		return authInfo != null ? authInfo : Collections.EMPTY_MAP;
483
	}
484
485
    private void loadProxyAuth(IProxyData data) {
486
		Map authInfo = getAuthInfo();
487
		data.setUserid((String)authInfo.get(INFO_PROXY_USER));
488
		data.setPassword((String)authInfo.get(INFO_PROXY_PASS));
489
	}
490
    
491
	private void saveProxyAuth(IProxyData data) {
492
		Map authInfo = getAuthInfo();
493
		if (authInfo.size() == 0) {
494
			authInfo = new java.util.HashMap(4);
495
		}
496
		String proxyUser = data.getUserId();
497
		if (proxyUser != null && data.getHost() != null) {
498
			authInfo.put(INFO_PROXY_USER, proxyUser);
499
		} else {
500
			authInfo.remove(INFO_PROXY_USER);
501
		}
502
		String proxyPass = data.getPassword();
503
		if (proxyPass != null && data.getHost() != null) {
504
			authInfo.put(INFO_PROXY_PASS, proxyPass);
505
		} else {
506
			authInfo.remove(INFO_PROXY_PASS);
507
		}
508
		try {
509
			if (authInfo.isEmpty()) {
510
				Platform.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
511
			} else {
512
				Platform.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$
513
			}
514
		} catch (CoreException e) {
515
			Activator.logError(e.getMessage(), e);
516
		}
517
	}
518
	
519
	private synchronized boolean hasJavaNetProxyClass() {
465
	private synchronized boolean hasJavaNetProxyClass() {
520
		try {
466
		try {
521
			Class proxyClass = Class.forName("java.net.Proxy"); //$NON-NLS-1$
467
			Class proxyClass = Class.forName("java.net.Proxy"); //$NON-NLS-1$
(-)src/org/eclipse/core/internal/net/ProxyData.java (+63 lines)
Lines 11-18 Link Here
11
package org.eclipse.core.internal.net;
11
package org.eclipse.core.internal.net;
12
12
13
import org.eclipse.core.net.proxy.IProxyData;
13
import org.eclipse.core.net.proxy.IProxyData;
14
import org.eclipse.equinox.security.storage.ISecurePreferences;
15
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
16
import org.eclipse.equinox.security.storage.StorageException;
14
17
15
public class ProxyData implements IProxyData {
18
public class ProxyData implements IProxyData {
19
	
20
    /**
21
     * Absolute path to the node for the cached proxy information
22
     */
23
    private static final String PREFERENCES_CONTEXT = "/org.eclipse.core.net.proxy.auth"; //$NON-NLS-1$
24
	/*
25
	 * Fields used to cache authentication information in the keyring
26
	 */
27
    private static final String INFO_PROXY_USER = "user"; //$NON-NLS-1$ 
28
    private static final String INFO_PROXY_PASS = "pass"; //$NON-NLS-1$ 
16
29
17
	private String type;
30
	private String type;
18
	private String host;
31
	private String host;
Lines 20-25 Link Here
20
	private String user;
33
	private String user;
21
	private String password;
34
	private String password;
22
	private boolean requiresAuthentication;
35
	private boolean requiresAuthentication;
36
	
37
	private boolean authenticationLoaded = false;
23
38
24
	public ProxyData(String type, String host, int port, boolean requiresAuthentication) {
39
	public ProxyData(String type, String host, int port, boolean requiresAuthentication) {
25
		this.type = type;
40
		this.type = type;
Lines 37-42 Link Here
37
	}
52
	}
38
53
39
	public String getPassword() {
54
	public String getPassword() {
55
		if (!authenticationLoaded)
56
			load();
40
		return password;
57
		return password;
41
	}
58
	}
42
59
Lines 49-54 Link Here
49
	}
66
	}
50
67
51
	public String getUserId() {
68
	public String getUserId() {
69
		if (!authenticationLoaded)
70
			load();
52
		return user;
71
		return user;
53
	}
72
	}
54
73
Lines 60-65 Link Here
60
79
61
	public void setPassword(String password) {
80
	public void setPassword(String password) {
62
		this.password = password;
81
		this.password = password;
82
		
83
		ISecurePreferences node = getNode();
84
		if (node == null)
85
			return;
86
		try {
87
			node.put(INFO_PROXY_PASS, this.password, true /* store encrypted */);
88
		} catch (StorageException e) {
89
			Activator.logError(e.getMessage(), e);
90
			return;
91
		}
63
	}
92
	}
64
93
65
	public void setPort(int port) {
94
	public void setPort(int port) {
Lines 69-74 Link Here
69
	public void setUserid(String userid) {
98
	public void setUserid(String userid) {
70
		this.user = userid;
99
		this.user = userid;
71
		requiresAuthentication = userid != null;
100
		requiresAuthentication = userid != null;
101
		
102
		ISecurePreferences node = getNode();
103
		if (node == null)
104
			return;
105
		try {
106
			node.put(INFO_PROXY_USER, this.user, true /* store encrypted */);
107
		} catch (StorageException e) {
108
			Activator.logError(e.getMessage(), e);
109
			return;
110
		}
72
	}
111
	}
73
112
74
	public boolean isRequiresAuthentication() {
113
	public boolean isRequiresAuthentication() {
Lines 83-86 Link Here
83
		requiresAuthentication = false;
122
		requiresAuthentication = false;
84
	}
123
	}
85
124
125
	private ISecurePreferences getNode() {
126
		ISecurePreferences root = SecurePreferencesFactory.getDefault();
127
		if (root == null)
128
			return null;
129
		ISecurePreferences node = root.node(PREFERENCES_CONTEXT);
130
		if (type != null && type.length() != 0)
131
			return node.node(type);
132
		return node;
133
	}
134
135
    private void load() {
136
    	authenticationLoaded = true;
137
		ISecurePreferences node = getNode();
138
		if (node == null)
139
			return;
140
		try {
141
			user = node.get(INFO_PROXY_USER, null);
142
			password = node.get(INFO_PROXY_PASS, null);
143
		} catch (StorageException e) {
144
			Activator.logError(e.getMessage(), e);
145
		}
146
	}
147
148
86
}
149
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 6-12 Link Here
6
Bundle-Activator: org.eclipse.core.internal.net.Activator
6
Bundle-Activator: org.eclipse.core.internal.net.Activator
7
Bundle-Vendor: %PLUGIN_PROVIDER
7
Bundle-Vendor: %PLUGIN_PROVIDER
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)"
9
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
10
 org.eclipse.equinox.security;bundle-version="[1.0.0,2.0.0)"
10
Eclipse-LazyStart: true
11
Eclipse-LazyStart: true
11
Export-Package: org.eclipse.core.internal.net;x-internal:=true,
12
Export-Package: org.eclipse.core.internal.net;x-internal:=true,
12
 org.eclipse.core.net.proxy
13
 org.eclipse.core.net.proxy

Return to bug 214796