mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-08 09:35:23 +02:00
bug 141835 - user id information wasn't being persisted.
Found a password persistence bug during testing and fixed that at the same time.
This commit is contained in:
parent
5e8dfb9cf8
commit
e32b3be6e7
3 changed files with 136 additions and 86 deletions
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.eclipse.rse.ui.propertypages;
|
package org.eclipse.rse.ui.propertypages;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ public class RemoteSystemsPreferencePage
|
||||||
private boolean lastShowFilterPoolsValue = false;
|
private boolean lastShowFilterPoolsValue = false;
|
||||||
private boolean lastQualifyConnectionNamesValue = false;
|
private boolean lastQualifyConnectionNamesValue = false;
|
||||||
private boolean lastRememberStateValue = true; // changed in R2 by Phil. Not sure about migration!
|
private boolean lastRememberStateValue = true; // changed in R2 by Phil. Not sure about migration!
|
||||||
private boolean lastRestoreFromCacheValue = true; // yantzi: new in artemis 6.0
|
// private boolean lastRestoreFromCacheValue = true; // yantzi: new in artemis 6.0
|
||||||
private boolean lastShowNewConnectionPromptValue = true;
|
private boolean lastShowNewConnectionPromptValue = true;
|
||||||
private boolean lastUseDeferredQueryValue = false;
|
private boolean lastUseDeferredQueryValue = false;
|
||||||
|
|
||||||
|
@ -163,7 +162,7 @@ public class RemoteSystemsPreferencePage
|
||||||
restoreFromCache.setEnabled(lastRememberStateValue, innerComposite);
|
restoreFromCache.setEnabled(lastRememberStateValue, innerComposite);
|
||||||
addField(restoreFromCache);
|
addField(restoreFromCache);
|
||||||
restoreFromCache.setToolTipText(SystemResources.RESID_PREF_RESTOREFROMCACHE_PREFIX_TOOLTIP);
|
restoreFromCache.setToolTipText(SystemResources.RESID_PREF_RESTOREFROMCACHE_PREFIX_TOOLTIP);
|
||||||
lastRestoreFromCacheValue = getPreferenceStore().getBoolean(ISystemPreferencesConstants.RESTORE_STATE_FROM_CACHE);
|
// lastRestoreFromCacheValue = getPreferenceStore().getBoolean(ISystemPreferencesConstants.RESTORE_STATE_FROM_CACHE);
|
||||||
|
|
||||||
// USE DEFERRED QUERY
|
// USE DEFERRED QUERY
|
||||||
useDeferredQueryEditor = new SystemBooleanFieldEditor(
|
useDeferredQueryEditor = new SystemBooleanFieldEditor(
|
||||||
|
@ -404,32 +403,32 @@ public class RemoteSystemsPreferencePage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Return the hashtable where the key is a string identifying a particular object, and
|
// * Return the hashtable where the key is a string identifying a particular object, and
|
||||||
* the value is the user Id for that object.
|
// * the value is the user Id for that object.
|
||||||
*/
|
// */
|
||||||
public static Hashtable getUserIdsPerKey()
|
// public static Hashtable getUserIdsPerKey() // DWD remove this later
|
||||||
{
|
// {
|
||||||
IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
|
// IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
|
||||||
Hashtable keyValues = null;
|
// Hashtable keyValues = null;
|
||||||
String value = store.getString(ISystemPreferencesConstants.USERIDPERKEY);
|
// String value = store.getString(ISystemPreferencesConstants.USERIDPERKEY);
|
||||||
if (value != null)
|
// if (value != null)
|
||||||
keyValues = parseString(value);
|
// keyValues = parseString(value);
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
keyValues = new Hashtable();
|
// keyValues = new Hashtable();
|
||||||
}
|
// }
|
||||||
return keyValues;
|
// return keyValues;
|
||||||
}
|
// }
|
||||||
/**
|
// /**
|
||||||
* Set/store the user ids that are saved keyed by some key.
|
// * Set/store the user ids that are saved keyed by some key.
|
||||||
*/
|
// */
|
||||||
public static void setUserIdsPerKey(Hashtable uidsPerKey)
|
// public static void setUserIdsPerKey(Hashtable uidsPerKey) // DWD remove this later
|
||||||
{
|
// {
|
||||||
IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
|
// IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
|
||||||
store.setValue(ISystemPreferencesConstants.USERIDPERKEY, makeString(uidsPerKey));
|
// store.setValue(ISystemPreferencesConstants.USERIDPERKEY, makeString(uidsPerKey));
|
||||||
savePreferenceStore();
|
// savePreferenceStore();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the System type to default to on the Create Connection wizard.
|
* Return the System type to default to on the Create Connection wizard.
|
||||||
|
@ -505,24 +504,24 @@ public class RemoteSystemsPreferencePage
|
||||||
/**
|
/**
|
||||||
* Convert hashtable of key-value pairs into a single string
|
* Convert hashtable of key-value pairs into a single string
|
||||||
*/
|
*/
|
||||||
protected static String makeString(Hashtable keyValues)
|
// protected static String makeString(Hashtable keyValues) DWD remove this later
|
||||||
{
|
// {
|
||||||
Enumeration keys = keyValues.keys();
|
// Enumeration keys = keyValues.keys();
|
||||||
StringBuffer sb = new StringBuffer();
|
// StringBuffer sb = new StringBuffer();
|
||||||
while (keys.hasMoreElements())
|
// while (keys.hasMoreElements())
|
||||||
{
|
// {
|
||||||
String key = (String)keys.nextElement();
|
// String key = (String)keys.nextElement();
|
||||||
String value = (String)keyValues.get(key);
|
// String value = (String)keyValues.get(key);
|
||||||
if ((value != null) && (value.length()>0))
|
// if ((value != null) && (value.length()>0))
|
||||||
{
|
// {
|
||||||
sb.append(key);
|
// sb.append(key);
|
||||||
sb.append('=');
|
// sb.append('=');
|
||||||
sb.append(value);
|
// sb.append(value);
|
||||||
sb.append(';');
|
// sb.append(';');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return sb.toString();
|
// return sb.toString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse out list of multiple values into a string array per value
|
* Parse out list of multiple values into a string array per value
|
||||||
|
|
|
@ -244,10 +244,9 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
|
||||||
* cached userId.
|
* cached userId.
|
||||||
*/
|
*/
|
||||||
final public String getUserId() {
|
final public String getUserId() {
|
||||||
String result = getSubsystemUserId();
|
String result = getLocalUserId();
|
||||||
ISubSystem ss = getPrimarySubSystem();
|
if (result == null) {
|
||||||
if (ss.isConnected()) {
|
result = getSubsystemUserId();
|
||||||
result = getLocalUserId();
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -258,9 +257,6 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
|
||||||
* set for this service then it is retrieved from the primary subsystem.
|
* set for this service then it is retrieved from the primary subsystem.
|
||||||
*/
|
*/
|
||||||
final protected String getLocalUserId() {
|
final protected String getLocalUserId() {
|
||||||
if (_userId == null) {
|
|
||||||
_userId = getSubsystemUserId();
|
|
||||||
}
|
|
||||||
return _userId;
|
return _userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,13 +418,13 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
|
||||||
IHost host = subsystem.getHost();
|
IHost host = subsystem.getHost();
|
||||||
String hostName = host.getHostName();
|
String hostName = host.getHostName();
|
||||||
String hostType = host.getSystemType();
|
String hostType = host.getSystemType();
|
||||||
String oldUserId = getLocalUserId();
|
String userId = getUserId();
|
||||||
PasswordPersistenceManager ppm = PasswordPersistenceManager.getInstance();
|
PasswordPersistenceManager ppm = PasswordPersistenceManager.getInstance();
|
||||||
|
|
||||||
// Check the transient in memory password ...
|
// Check the transient in memory password ...
|
||||||
// Test if userId has been changed... d43274
|
// Test if userId has been changed... d43274
|
||||||
if (passwordInformation != null && !forcePrompt) {
|
if (passwordInformation != null && !forcePrompt) {
|
||||||
boolean same = host.compareUserIds(oldUserId, passwordInformation.getUserid());
|
boolean same = host.compareUserIds(userId, passwordInformation.getUserid());
|
||||||
same = same && hostName.equalsIgnoreCase(passwordInformation.getHostname());
|
same = same && hostName.equalsIgnoreCase(passwordInformation.getHostname());
|
||||||
if (!same) {
|
if (!same) {
|
||||||
clearPasswordCache();
|
clearPasswordCache();
|
||||||
|
@ -445,8 +441,8 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the saved passwords if we still haven't found a good password.
|
// Check the saved passwords if we still haven't found a good password.
|
||||||
if (passwordInformation == null && oldUserId != null && !forcePrompt) {
|
if (passwordInformation == null && userId != null && !forcePrompt) {
|
||||||
SystemSignonInformation savedPasswordInformation = ppm.find(hostType, hostName, oldUserId);
|
SystemSignonInformation savedPasswordInformation = ppm.find(hostType, hostName, userId);
|
||||||
if (savedPasswordInformation != null) {
|
if (savedPasswordInformation != null) {
|
||||||
if (validator == null || validator.isValid(shell, savedPasswordInformation)) {
|
if (validator == null || validator.isValid(shell, savedPasswordInformation)) {
|
||||||
setPasswordInformation(savedPasswordInformation);
|
setPasswordInformation(savedPasswordInformation);
|
||||||
|
@ -472,7 +468,7 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
|
||||||
if ((forcePrompt || (passwordInformation == null)) && (shell != null)) {
|
if ((forcePrompt || (passwordInformation == null)) && (shell != null)) {
|
||||||
ISystemPasswordPromptDialog dlg = getPasswordPromptDialog(shell);
|
ISystemPasswordPromptDialog dlg = getPasswordPromptDialog(shell);
|
||||||
dlg.setSystemInput(this);
|
dlg.setSystemInput(this);
|
||||||
passwordInformation = ppm.find(hostType, hostName, oldUserId);
|
passwordInformation = ppm.find(hostType, hostName, userId);
|
||||||
if (passwordInformation != null) {
|
if (passwordInformation != null) {
|
||||||
String password = passwordInformation.getPassword();
|
String password = passwordInformation.getPassword();
|
||||||
dlg.setPassword(password);
|
dlg.setPassword(password);
|
||||||
|
@ -828,6 +824,7 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
|
||||||
{
|
{
|
||||||
internalDisconnect(monitor);
|
internalDisconnect(monitor);
|
||||||
unintializeSubSystems(monitor);
|
unintializeSubSystems(monitor);
|
||||||
|
clearPasswordCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void internalDisconnect(IProgressMonitor monitor) throws Exception
|
public void internalDisconnect(IProgressMonitor monitor) throws Exception
|
||||||
|
|
|
@ -16,10 +16,14 @@
|
||||||
|
|
||||||
package org.eclipse.rse.core;
|
package org.eclipse.rse.core;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Preferences;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.rse.model.IHost;
|
import org.eclipse.rse.model.IHost;
|
||||||
import org.eclipse.rse.model.ISystemRegistry;
|
import org.eclipse.rse.model.ISystemRegistry;
|
||||||
|
@ -45,7 +49,7 @@ public class SystemPreferencesManager
|
||||||
{
|
{
|
||||||
|
|
||||||
private static SystemPreferencesManager inst;
|
private static SystemPreferencesManager inst;
|
||||||
private Hashtable userIdsPerKey = null;
|
// private Hashtable userIdsPerKey = null;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -274,22 +278,24 @@ public class SystemPreferencesManager
|
||||||
public String getUserId(String key)
|
public String getUserId(String key)
|
||||||
{
|
{
|
||||||
String uid = null;
|
String uid = null;
|
||||||
userIdsPerKey = getUserIdsPerKey();
|
Hashtable userIds = getUserIds();
|
||||||
uid = (String)userIdsPerKey.get(key);
|
uid = (String) userIds.get(key);
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the user Id for this key. The key typically designates a scope for this userid so that a hierarchy
|
* Set the user Id for this key. The key typically designates a scope for this userid so that a hierarchy
|
||||||
* of user ids can be maintained for inheritance. For example, hosts have greater scope than subsystems.
|
* of user ids can be maintained for inheritance. For example, hosts have greater scope than subsystems.
|
||||||
|
* A key would typically be <profile-name>.<host-name>, or <profile-name>.<host-type>, or
|
||||||
|
* <profile-name>.<host-name>.<subsystem-name>.
|
||||||
*/
|
*/
|
||||||
public void setUserId(String key, String userId) {
|
public void setUserId(String key, String userId) {
|
||||||
if ((key != null) && (userId != null)) {
|
if ((key != null) && (userId != null)) {
|
||||||
userIdsPerKey = getUserIdsPerKey();
|
Hashtable userIds = getUserIds();
|
||||||
String storedUserId = (String) userIdsPerKey.get(key);
|
String storedUserId = (String) userIds.get(key);
|
||||||
if (!storedUserId.equals(userId)) { // don't bother updating if its already there
|
if (storedUserId == null || !storedUserId.equals(userId)) { // don't bother updating if its already there
|
||||||
userIdsPerKey.put(key, userId);
|
userIds.put(key, userId);
|
||||||
setUserIdsPerKey();
|
setUserIds(userIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,31 +305,79 @@ public class SystemPreferencesManager
|
||||||
*/
|
*/
|
||||||
public void clearUserId(String key)
|
public void clearUserId(String key)
|
||||||
{
|
{
|
||||||
userIdsPerKey = getUserIdsPerKey();
|
Hashtable userIds = getUserIds();
|
||||||
if (userIdsPerKey.containsKey(key))
|
if (userIds.containsKey(key))
|
||||||
{
|
{
|
||||||
userIdsPerKey.remove(key);
|
userIds.remove(key);
|
||||||
setUserIdsPerKey();
|
setUserIds(userIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to get the hashtable of userIds per key. Comes from preference store.
|
* Return the hashtable where the key is a string identifying a particular object, and
|
||||||
|
* the value is the user Id for that object.
|
||||||
*/
|
*/
|
||||||
private Hashtable getUserIdsPerKey()
|
public static Hashtable getUserIds() {
|
||||||
{
|
Preferences store = RSECorePlugin.getDefault().getPluginPreferences();
|
||||||
if (userIdsPerKey == null)
|
Hashtable userIds = null;
|
||||||
userIdsPerKey = RemoteSystemsPreferencePage.getUserIdsPerKey();
|
String value = store.getString(ISystemPreferencesConstants.USERIDPERKEY);
|
||||||
return userIdsPerKey;
|
if (value != null) {
|
||||||
|
userIds = parseString(value);
|
||||||
|
} else {
|
||||||
|
userIds = new Hashtable();
|
||||||
}
|
}
|
||||||
/**
|
return userIds;
|
||||||
* Helper method to set the hashtable of userIds per subsystem. Sets it in the preference store.
|
|
||||||
*/
|
|
||||||
private void setUserIdsPerKey()
|
|
||||||
{
|
|
||||||
RemoteSystemsPreferencePage.setUserIdsPerKey(userIdsPerKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set/store the user ids that are saved keyed by some key.
|
||||||
|
*/
|
||||||
|
public static void setUserIds(Hashtable userIds) {
|
||||||
|
Preferences store = RSECorePlugin.getDefault().getPluginPreferences();
|
||||||
|
String userIdsString = makeString(userIds);
|
||||||
|
store.setValue(ISystemPreferencesConstants.USERIDPERKEY, userIdsString);
|
||||||
|
RSECorePlugin.getDefault().savePluginPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert hashtable of key-value pairs into a single string
|
||||||
|
*/
|
||||||
|
protected static String makeString(Hashtable table) {
|
||||||
|
Enumeration keys = table.keys();
|
||||||
|
StringBuffer sb = new StringBuffer(20 * table.size());
|
||||||
|
while (keys.hasMoreElements()) {
|
||||||
|
String key = (String) keys.nextElement();
|
||||||
|
String value = (String) table.get(key);
|
||||||
|
if ((value != null) && (value.length() > 0)) {
|
||||||
|
sb.append(key);
|
||||||
|
sb.append('=');
|
||||||
|
sb.append(value);
|
||||||
|
sb.append(';');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse out list of key-value pairs into a hashtable
|
||||||
|
*/
|
||||||
|
protected static Hashtable parseString(String allvalues) {
|
||||||
|
StringTokenizer tokens = new StringTokenizer(allvalues, "=;");
|
||||||
|
Hashtable keyValues = new Hashtable(10);
|
||||||
|
int count = 0;
|
||||||
|
String token1 = null;
|
||||||
|
String token2 = null;
|
||||||
|
while (tokens.hasMoreTokens()) {
|
||||||
|
count++;
|
||||||
|
if ((count % 2) == 0) // even number
|
||||||
|
{
|
||||||
|
token2 = tokens.nextToken();
|
||||||
|
keyValues.put(token1, token2);
|
||||||
|
} else
|
||||||
|
token1 = tokens.nextToken();
|
||||||
|
}
|
||||||
|
return keyValues;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
// GETTER METHODS...
|
// GETTER METHODS...
|
||||||
|
|
Loading…
Add table
Reference in a new issue