|
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$ |