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 (-44 / +55 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.io.IOException;
14
import java.net.URL;
14
import java.util.Properties;
15
import java.util.*;
16
15
17
import org.eclipse.core.net.proxy.IProxyData;
16
import org.eclipse.core.net.proxy.IProxyData;
18
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences.*;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener;
20
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
21
import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
22
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
23
import org.eclipse.equinox.security.storage.ISecurePreferences;
24
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
25
import org.eclipse.equinox.security.storage.StorageException;
21
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.osgi.util.NLS;
22
import org.osgi.service.prefs.BackingStoreException;
27
import org.osgi.service.prefs.BackingStoreException;
23
import org.osgi.service.prefs.Preferences;
28
import org.osgi.service.prefs.Preferences;
Lines 48-67 Link Here
48
	public static final int NEVER_SET = 2;
53
	public static final int NEVER_SET = 2;
49
	public static int socksSystemPropertySetting;
54
	public static int socksSystemPropertySetting;
50
	
55
	
56
    /**
57
     * Absolute path to the node for the cached proxy information
58
     */
59
    private static final String PREFERENCES_CONTEXT = "/org.eclipse.core.net.proxy.auth"; //$NON-NLS-1$
51
	/*
60
	/*
52
	 * Fields used to cache authentication information in the keyring
61
	 * Fields used to cache authentication information in the keyring
53
	 */
62
	 */
54
    private static final String INFO_PROXY_USER = "user"; //$NON-NLS-1$ 
63
    private static final String INFO_PROXY_USER = "user"; //$NON-NLS-1$ 
55
    private static final String INFO_PROXY_PASS = "pass"; //$NON-NLS-1$ 
64
    private static final String INFO_PROXY_PASS = "pass"; //$NON-NLS-1$ 
56
    private static final URL FAKE_URL;
57
    static {
65
    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);
66
        String value = System.getProperty(PROP_SOCKS_SYSTEM_PROPERTY_HANDLING);
66
        if (value == null) {
67
        if (value == null) {
67
        	socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER;
68
        	socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER;
Lines 476-521 Link Here
476
		((IEclipsePreferences)getPreferenceNode()).addPreferenceChangeListener(this);
477
		((IEclipsePreferences)getPreferenceNode()).addPreferenceChangeListener(this);
477
	}
478
	}
478
	
479
	
479
    private Map getAuthInfo() {
480
	private ISecurePreferences getNode() {
480
		// Retrieve username and password from keyring.
481
		ISecurePreferences root = SecurePreferencesFactory.getDefault();
481
		Map authInfo = Platform.getAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
482
		if (root == null)
482
		return authInfo != null ? authInfo : Collections.EMPTY_MAP;
483
			return null;
484
		ISecurePreferences node = root.node(PREFERENCES_CONTEXT);
485
		if (getName() != null)
486
			return node.node(getName());
487
		return node;
483
	}
488
	}
484
489
485
    private void loadProxyAuth(IProxyData data) {
490
    private void loadProxyAuth(IProxyData data) {
486
		Map authInfo = getAuthInfo();
491
		ISecurePreferences node = getNode();
487
		data.setUserid((String)authInfo.get(INFO_PROXY_USER));
492
		if (node == null)
488
		data.setPassword((String)authInfo.get(INFO_PROXY_PASS));
493
			return;
494
		try {
495
			data.setUserid(node.get(INFO_PROXY_USER, null));
496
			data.setPassword(node.get(INFO_PROXY_PASS, null));
497
		} catch (StorageException e) {
498
			Activator.logError(e.getMessage(), e);
499
		}
489
	}
500
	}
490
    
501
491
	private void saveProxyAuth(IProxyData data) {
502
	private void saveProxyAuth(IProxyData data) {
492
		Map authInfo = getAuthInfo();
503
		ISecurePreferences node= getNode();
493
		if (authInfo.size() == 0) {
504
		if (node == null)
494
			authInfo = new java.util.HashMap(4);
505
			return;
495
		}
506
		try {
496
		String proxyUser = data.getUserId();
507
			if (data.getUserId() != null)
497
		if (proxyUser != null && data.getHost() != null) {
508
				node.put(INFO_PROXY_USER, data.getUserId(), true /* store encrypted */);
498
			authInfo.put(INFO_PROXY_USER, proxyUser);
509
			else
499
		} else {
510
				node.remove(INFO_PROXY_USER);
500
			authInfo.remove(INFO_PROXY_USER);
511
501
		}
512
			if (data.getPassword() != null)
502
		String proxyPass = data.getPassword();
513
				node.put(INFO_PROXY_PASS, data.getPassword(), true /* store encrypted */);
503
		if (proxyPass != null && data.getHost() != null) {
514
			else
504
			authInfo.put(INFO_PROXY_PASS, proxyPass);
515
				node.remove(INFO_PROXY_PASS);
505
		} else {
516
		} catch (StorageException e) {
506
			authInfo.remove(INFO_PROXY_PASS);
517
			Activator.logError(e.getMessage(), e);
518
			return;
507
		}
519
		}
520
521
		// optional: save it right away in case something crashes later
508
		try {
522
		try {
509
			if (authInfo.isEmpty()) {
523
			node.flush();
510
				Platform.flushAuthorizationInfo(FAKE_URL, getName(), ""); //$NON-NLS-1$
524
		} catch (IOException e) {
511
			} else {
512
				Platform.addAuthorizationInfo(FAKE_URL, getName(), "", authInfo); //$NON-NLS-1$
513
			}
514
		} catch (CoreException e) {
515
			Activator.logError(e.getMessage(), e);
525
			Activator.logError(e.getMessage(), e);
526
			return;
516
		}
527
		}
517
	}
528
	}
518
	
529
519
	private synchronized boolean hasJavaNetProxyClass() {
530
	private synchronized boolean hasJavaNetProxyClass() {
520
		try {
531
		try {
521
			Class proxyClass = Class.forName("java.net.Proxy"); //$NON-NLS-1$
532
			Class proxyClass = Class.forName("java.net.Proxy"); //$NON-NLS-1$
(-)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
Bundle-ActivationPolicy: lazy
11
Bundle-ActivationPolicy: lazy
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