1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +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:
David Dykstal 2006-06-28 21:26:22 +00:00
parent 5e8dfb9cf8
commit e32b3be6e7
3 changed files with 136 additions and 86 deletions

View file

@ -16,7 +16,6 @@
package org.eclipse.rse.ui.propertypages;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
@ -63,7 +62,7 @@ public class RemoteSystemsPreferencePage
private boolean lastShowFilterPoolsValue = false;
private boolean lastQualifyConnectionNamesValue = false;
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 lastUseDeferredQueryValue = false;
@ -163,7 +162,7 @@ public class RemoteSystemsPreferencePage
restoreFromCache.setEnabled(lastRememberStateValue, innerComposite);
addField(restoreFromCache);
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
useDeferredQueryEditor = new SystemBooleanFieldEditor(
@ -404,32 +403,32 @@ public class RemoteSystemsPreferencePage
}
/**
* Return the hashtable where the key is a string identifying a particular object, and
* the value is the user Id for that object.
*/
public static Hashtable getUserIdsPerKey()
{
IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
Hashtable keyValues = null;
String value = store.getString(ISystemPreferencesConstants.USERIDPERKEY);
if (value != null)
keyValues = parseString(value);
else
{
keyValues = new Hashtable();
}
return keyValues;
}
/**
* Set/store the user ids that are saved keyed by some key.
*/
public static void setUserIdsPerKey(Hashtable uidsPerKey)
{
IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
store.setValue(ISystemPreferencesConstants.USERIDPERKEY, makeString(uidsPerKey));
savePreferenceStore();
}
// /**
// * Return the hashtable where the key is a string identifying a particular object, and
// * the value is the user Id for that object.
// */
// public static Hashtable getUserIdsPerKey() // DWD remove this later
// {
// IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
// Hashtable keyValues = null;
// String value = store.getString(ISystemPreferencesConstants.USERIDPERKEY);
// if (value != null)
// keyValues = parseString(value);
// else
// {
// keyValues = new Hashtable();
// }
// return keyValues;
// }
// /**
// * Set/store the user ids that are saved keyed by some key.
// */
// public static void setUserIdsPerKey(Hashtable uidsPerKey) // DWD remove this later
// {
// IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore();
// store.setValue(ISystemPreferencesConstants.USERIDPERKEY, makeString(uidsPerKey));
// savePreferenceStore();
// }
/**
* 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
*/
protected static String makeString(Hashtable keyValues)
{
Enumeration keys = keyValues.keys();
StringBuffer sb = new StringBuffer();
while (keys.hasMoreElements())
{
String key = (String)keys.nextElement();
String value = (String)keyValues.get(key);
if ((value != null) && (value.length()>0))
{
sb.append(key);
sb.append('=');
sb.append(value);
sb.append(';');
}
}
return sb.toString();
}
// protected static String makeString(Hashtable keyValues) DWD remove this later
// {
// Enumeration keys = keyValues.keys();
// StringBuffer sb = new StringBuffer();
// while (keys.hasMoreElements())
// {
// String key = (String)keys.nextElement();
// String value = (String)keyValues.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 multiple values into a string array per value

View file

@ -244,10 +244,9 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
* cached userId.
*/
final public String getUserId() {
String result = getSubsystemUserId();
ISubSystem ss = getPrimarySubSystem();
if (ss.isConnected()) {
result = getLocalUserId();
String result = getLocalUserId();
if (result == null) {
result = getSubsystemUserId();
}
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.
*/
final protected String getLocalUserId() {
if (_userId == null) {
_userId = getSubsystemUserId();
}
return _userId;
}
@ -422,13 +418,13 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
IHost host = subsystem.getHost();
String hostName = host.getHostName();
String hostType = host.getSystemType();
String oldUserId = getLocalUserId();
String userId = getUserId();
PasswordPersistenceManager ppm = PasswordPersistenceManager.getInstance();
// Check the transient in memory password ...
// Test if userId has been changed... d43274
if (passwordInformation != null && !forcePrompt) {
boolean same = host.compareUserIds(oldUserId, passwordInformation.getUserid());
boolean same = host.compareUserIds(userId, passwordInformation.getUserid());
same = same && hostName.equalsIgnoreCase(passwordInformation.getHostname());
if (!same) {
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.
if (passwordInformation == null && oldUserId != null && !forcePrompt) {
SystemSignonInformation savedPasswordInformation = ppm.find(hostType, hostName, oldUserId);
if (passwordInformation == null && userId != null && !forcePrompt) {
SystemSignonInformation savedPasswordInformation = ppm.find(hostType, hostName, userId);
if (savedPasswordInformation != null) {
if (validator == null || validator.isValid(shell, savedPasswordInformation)) {
setPasswordInformation(savedPasswordInformation);
@ -472,7 +468,7 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
if ((forcePrompt || (passwordInformation == null)) && (shell != null)) {
ISystemPasswordPromptDialog dlg = getPasswordPromptDialog(shell);
dlg.setSystemInput(this);
passwordInformation = ppm.find(hostType, hostName, oldUserId);
passwordInformation = ppm.find(hostType, hostName, userId);
if (passwordInformation != null) {
String password = passwordInformation.getPassword();
dlg.setPassword(password);
@ -828,6 +824,7 @@ public abstract class AbstractConnectorService extends RSEModelObject implements
{
internalDisconnect(monitor);
unintializeSubSystems(monitor);
clearPasswordCache();
}
public void internalDisconnect(IProgressMonitor monitor) throws Exception

View file

@ -16,10 +16,14 @@
package org.eclipse.rse.core;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.rse.model.IHost;
import org.eclipse.rse.model.ISystemRegistry;
@ -45,7 +49,7 @@ public class SystemPreferencesManager
{
private static SystemPreferencesManager inst;
private Hashtable userIdsPerKey = null;
// private Hashtable userIdsPerKey = null;
/**
*
*/
@ -274,22 +278,24 @@ public class SystemPreferencesManager
public String getUserId(String key)
{
String uid = null;
userIdsPerKey = getUserIdsPerKey();
uid = (String)userIdsPerKey.get(key);
Hashtable userIds = getUserIds();
uid = (String) userIds.get(key);
return uid;
}
/**
* 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.
* 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) {
if ((key != null) && (userId != null)) {
userIdsPerKey = getUserIdsPerKey();
String storedUserId = (String) userIdsPerKey.get(key);
if (!storedUserId.equals(userId)) { // don't bother updating if its already there
userIdsPerKey.put(key, userId);
setUserIdsPerKey();
Hashtable userIds = getUserIds();
String storedUserId = (String) userIds.get(key);
if (storedUserId == null || !storedUserId.equals(userId)) { // don't bother updating if its already there
userIds.put(key, userId);
setUserIds(userIds);
}
}
}
@ -299,31 +305,79 @@ public class SystemPreferencesManager
*/
public void clearUserId(String key)
{
userIdsPerKey = getUserIdsPerKey();
if (userIdsPerKey.containsKey(key))
Hashtable userIds = getUserIds();
if (userIds.containsKey(key))
{
userIdsPerKey.remove(key);
setUserIdsPerKey();
userIds.remove(key);
setUserIds(userIds);
}
}
/**
* Helper method to get the hashtable of userIds per key. Comes from preference store.
*/
private Hashtable getUserIdsPerKey()
{
if (userIdsPerKey == null)
userIdsPerKey = RemoteSystemsPreferencePage.getUserIdsPerKey();
return userIdsPerKey;
}
/**
* Helper method to set the hashtable of userIds per subsystem. Sets it in the preference store.
*/
private void setUserIdsPerKey()
{
RemoteSystemsPreferencePage.setUserIdsPerKey(userIdsPerKey);
}
* Return the hashtable where the key is a string identifying a particular object, and
* the value is the user Id for that object.
*/
public static Hashtable getUserIds() {
Preferences store = RSECorePlugin.getDefault().getPluginPreferences();
Hashtable userIds = null;
String value = store.getString(ISystemPreferencesConstants.USERIDPERKEY);
if (value != null) {
userIds = parseString(value);
} else {
userIds = new Hashtable();
}
return userIds;
}
/**
* 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...