mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
[225320] Rearranging elements prior to adding code for secure storage - no code changes.
This commit is contained in:
parent
2712a2eff0
commit
93fde9f633
1 changed files with 269 additions and 269 deletions
|
@ -49,6 +49,34 @@ import org.eclipse.rse.internal.core.RSECoreMessages;
|
||||||
*/
|
*/
|
||||||
public class PasswordPersistenceManager {
|
public class PasswordPersistenceManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default System Type
|
||||||
|
*/
|
||||||
|
private static class DefaultSystemType extends AbstractRSESystemType implements IRSESystemType {
|
||||||
|
private static final String DEFAULT_ID = "DEFAULT"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
private DefaultSystemType() {
|
||||||
|
super(DEFAULT_ID, DEFAULT_ID, RSECoreMessages.DefaultSystemType_Label, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
//TODO consider a space character at the beginning to ensure uniqueness
|
||||||
|
return DEFAULT_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getSubsystemConfigurationIds() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getAdapter(Class adapter) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Keys used for using the Platform authorization methods
|
// Keys used for using the Platform authorization methods
|
||||||
// The server url is generic so we can lookup all registered user IDs / passwords
|
// The server url is generic so we can lookup all registered user IDs / passwords
|
||||||
// to display to the user in the password information preference page
|
// to display to the user in the password information preference page
|
||||||
|
@ -70,45 +98,20 @@ public class PasswordPersistenceManager {
|
||||||
// Default user name
|
// Default user name
|
||||||
public static final String DEFAULT_USER_NAME = "DEFAULT_USER"; //$NON-NLS-1$
|
public static final String DEFAULT_USER_NAME = "DEFAULT_USER"; //$NON-NLS-1$
|
||||||
|
|
||||||
// New URL to store password map
|
|
||||||
private String newURL = null;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Singleton instance
|
* Singleton instance
|
||||||
*/
|
*/
|
||||||
private static PasswordPersistenceManager _instance;
|
private static PasswordPersistenceManager _instance;
|
||||||
|
|
||||||
/*
|
|
||||||
* Instance variables
|
|
||||||
*/
|
|
||||||
private RegisteredSystemType[] systemTypes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default System Type
|
* Retrieve the singleton instance of the PasswordPersistenceManger
|
||||||
*/
|
*/
|
||||||
private static class DefaultSystemType extends AbstractRSESystemType implements IRSESystemType {
|
public static final synchronized PasswordPersistenceManager getInstance() {
|
||||||
private static final String DEFAULT_ID = "DEFAULT"; //$NON-NLS-1$
|
if (_instance == null) {
|
||||||
|
_instance = new PasswordPersistenceManager();
|
||||||
private DefaultSystemType() {
|
_instance.initExtensions();
|
||||||
super(DEFAULT_ID, DEFAULT_ID, RSECoreMessages.DefaultSystemType_Label, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
//TODO consider a space character at the beginning to ensure uniqueness
|
|
||||||
return DEFAULT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getSubsystemConfigurationIds() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getAdapter(Class adapter) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,12 +120,12 @@ public class PasswordPersistenceManager {
|
||||||
private class RegisteredSystemType {
|
private class RegisteredSystemType {
|
||||||
private IRSESystemType _systemType;
|
private IRSESystemType _systemType;
|
||||||
private boolean _userIDCaseSensitive;
|
private boolean _userIDCaseSensitive;
|
||||||
|
|
||||||
protected RegisteredSystemType(IRSESystemType systemType, boolean caseSensitive) {
|
protected RegisteredSystemType(IRSESystemType systemType, boolean caseSensitive) {
|
||||||
_systemType = systemType;
|
_systemType = systemType;
|
||||||
_userIDCaseSensitive = caseSensitive;
|
_userIDCaseSensitive = caseSensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the system type.
|
* Returns the system type.
|
||||||
* @return the system type.
|
* @return the system type.
|
||||||
|
@ -130,7 +133,7 @@ public class PasswordPersistenceManager {
|
||||||
public IRSESystemType getSystemType() {
|
public IRSESystemType getSystemType() {
|
||||||
return _systemType;
|
return _systemType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the user ID is case sensitive.
|
* Returns whether the user ID is case sensitive.
|
||||||
* @return <code>true</code> if the user ID is case sensitive, <code>false</code> otherwise.
|
* @return <code>true</code> if the user ID is case sensitive, <code>false</code> otherwise.
|
||||||
|
@ -140,6 +143,14 @@ public class PasswordPersistenceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New URL to store password map
|
||||||
|
private String newURL = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Instance variables
|
||||||
|
*/
|
||||||
|
private RegisteredSystemType[] systemTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton so private constructor
|
* Singleton so private constructor
|
||||||
*/
|
*/
|
||||||
|
@ -153,17 +164,6 @@ public class PasswordPersistenceManager {
|
||||||
newURL = SERVER_URL + userName;
|
newURL = SERVER_URL + userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the singleton instance of the PasswordPersistenceManger
|
|
||||||
*/
|
|
||||||
public static final synchronized PasswordPersistenceManager getInstance() {
|
|
||||||
if (_instance == null) {
|
|
||||||
_instance = new PasswordPersistenceManager();
|
|
||||||
_instance.initExtensions();
|
|
||||||
}
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* initialization - register system types
|
* initialization - register system types
|
||||||
*/
|
*/
|
||||||
|
@ -177,84 +177,157 @@ public class PasswordPersistenceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the entry from the keyring that matches the systemtype, hostname and
|
* Helper class for building the key to lookup the password for a specific
|
||||||
* user ID from the SystemSignonInfo parameter.
|
* userid and hostname in the Map
|
||||||
*/
|
*/
|
||||||
public void remove(SystemSignonInformation info) {
|
private String getPasswordKey(String hname, String userid) {
|
||||||
remove(info.getSystemType(), info.getHostname(), info.getUserId());
|
String hostname = hname;//RSEUIPlugin.getQualifiedHostName(hname);
|
||||||
|
StringBuffer buffer = new StringBuffer(hostname);
|
||||||
|
buffer.append("//"); //$NON-NLS-1$
|
||||||
|
buffer.append(userid);
|
||||||
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String getHostnameFromPasswordKey(String passwordKey) {
|
||||||
* Removes all passwords for a host name for a given system type. Use the
|
int sepIndex = passwordKey.indexOf("//"); //$NON-NLS-1$
|
||||||
* default system type explicitly to remove those entries.
|
return passwordKey.substring(0, sepIndex);
|
||||||
*
|
}
|
||||||
* @param systemType The system type of the host
|
|
||||||
* @param hostName The IP address of the host in canonical format
|
private String getUserIdFromPasswordKey(String passwordKey) {
|
||||||
* @return the number of passwords removed from the keyring
|
int sepIndex = passwordKey.indexOf("//"); //$NON-NLS-1$
|
||||||
* @since org.eclipse.rse.core 3.0
|
return passwordKey.substring(sepIndex + 2, passwordKey.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve the password map from the keyring for the specified system type
|
||||||
*/
|
*/
|
||||||
public int remove(IRSESystemType systemType, String hostName) {
|
private Map getPasswordMap(IRSESystemType systemType) {
|
||||||
Map passwords = getPasswordMap(systemType);
|
Map passwords = null;
|
||||||
int numberRemoved = 0;
|
String systemTypeId = systemType.getId();
|
||||||
if (passwords != null) {
|
|
||||||
String hostPrefix = hostName + "//"; //$NON-NLS-1$
|
try {
|
||||||
Set keys = passwords.keySet();
|
URL serverURL = new URL(newURL);
|
||||||
for (Iterator z = keys.iterator(); z.hasNext();) {
|
passwords = Platform.getAuthorizationInfo(serverURL, systemTypeId, AUTH_SCHEME);
|
||||||
String key = (String) z.next();
|
|
||||||
if (key.startsWith(hostPrefix)) {
|
// if no passwords found with new URL, check old URL
|
||||||
z.remove(); // safely removes the key and the entry from the map
|
if (passwords == null) {
|
||||||
numberRemoved++;
|
|
||||||
|
URL oldServerURL1 = new URL(SERVER_URL + ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
|
||||||
|
passwords = Platform.getAuthorizationInfo(oldServerURL1, systemTypeId, AUTH_SCHEME);
|
||||||
|
|
||||||
|
// passwords found, so migrate to using new URL
|
||||||
|
if (passwords != null) {
|
||||||
|
savePasswordMap(systemTypeId, passwords);
|
||||||
|
}
|
||||||
|
// if still no passwords found, check with even older URL
|
||||||
|
else {
|
||||||
|
URL oldServerURL2 = new URL(SERVER_URL);
|
||||||
|
passwords = Platform.getAuthorizationInfo(oldServerURL2, systemTypeId, AUTH_SCHEME);
|
||||||
|
|
||||||
|
// passwords found, so migrate to using new URL
|
||||||
|
if (passwords != null) {
|
||||||
|
savePasswordMap(systemTypeId, passwords);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numberRemoved > 0) {
|
} catch (MalformedURLException e) {
|
||||||
savePasswordMap(systemType.getId(), passwords);
|
RSECorePlugin.getDefault().getLogger().logError("PasswordPersistenceManager.getPasswordMap", e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
return passwords;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve the password map from the keyring for the specified system type
|
||||||
|
*/
|
||||||
|
private void savePasswordMap(String systemTypeId, Map passwords) {
|
||||||
|
try {
|
||||||
|
URL serverURL = new URL(newURL);
|
||||||
|
Platform.flushAuthorizationInfo(serverURL, systemTypeId, AUTH_SCHEME);
|
||||||
|
Platform.addAuthorizationInfo(serverURL, systemTypeId, AUTH_SCHEME, passwords);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
RSECorePlugin.getDefault().getLogger().logError("PasswordPersistenceManager.savePasswordMap", e); //$NON-NLS-1$
|
||||||
|
} catch (CoreException e) {
|
||||||
|
RSECorePlugin.getDefault().getLogger().logError("PasswordPersistenceManager.savePasswordMap", e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removePassword(Map passwords, String hostname, String userid) {
|
||||||
|
boolean removed = false;
|
||||||
|
String password = null;
|
||||||
|
|
||||||
|
String passwordKey = getPasswordKey(hostname, userid);
|
||||||
|
password = (String) passwords.get(passwordKey);
|
||||||
|
if (password != null) {
|
||||||
|
passwords.remove(passwordKey);
|
||||||
|
removed = true;
|
||||||
|
} else {
|
||||||
|
String phostname = hostname.toUpperCase();
|
||||||
|
|
||||||
|
// DKM - fallback for different case uids, hostnames or qualified/unqualified hostnames
|
||||||
|
Iterator keys = passwords.keySet().iterator();
|
||||||
|
while (keys.hasNext() && password == null) {
|
||||||
|
String key = (String) keys.next();
|
||||||
|
if (key.equalsIgnoreCase(passwordKey)) {
|
||||||
|
password = (String) passwords.get(key);
|
||||||
|
} else {
|
||||||
|
String khostname = getHostnameFromPasswordKey(key).toUpperCase();
|
||||||
|
String kuid = getUserIdFromPasswordKey(key);
|
||||||
|
if (kuid.equalsIgnoreCase(userid)) {
|
||||||
|
// uid matches, check if hosts are the same
|
||||||
|
if (khostname.startsWith(phostname) || phostname.startsWith(khostname)) {
|
||||||
|
String qkhost = RSECorePlugin.getQualifiedHostName(khostname);
|
||||||
|
String qphost = RSECorePlugin.getQualifiedHostName(phostname);
|
||||||
|
if (qkhost.equals(qphost)) {
|
||||||
|
password = (String) passwords.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (password != null) {
|
||||||
|
passwords.remove(key);
|
||||||
|
removed = true;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return numberRemoved;
|
return removed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String getPassword(Map passwords, String hostname, String userid) {
|
||||||
* Removes all entries from the keyring that match the hostname, userid, and system type.
|
String password = null;
|
||||||
* Use the default system type explicitly to remove those entries.
|
|
||||||
* @param systemType the systemType
|
String passwordKey = getPasswordKey(hostname, userid);
|
||||||
* @param hostName the connection name
|
password = (String) passwords.get(passwordKey);
|
||||||
* @param userid the user id
|
if (password != null) return password;
|
||||||
*/
|
|
||||||
public void remove(IRSESystemType systemType, String hostName, String userid) {
|
String phostname = hostname.toUpperCase();
|
||||||
String hostname = hostName;//RSEUIPlugin.getQualifiedHostName(hname);
|
|
||||||
// Convert userid to upper case if required
|
// DKM - fallback for different case uids, hostnames or qualified/unqualified hostnames
|
||||||
if (!isUserIDCaseSensitive(systemType)) {
|
Iterator keys = passwords.keySet().iterator();
|
||||||
userid = userid.toUpperCase();
|
while (keys.hasNext() && password == null) {
|
||||||
}
|
String key = (String) keys.next();
|
||||||
Map passwords = getPasswordMap(systemType);
|
if (key.equalsIgnoreCase(passwordKey)) {
|
||||||
if (passwords != null) {
|
password = (String) passwords.get(key);
|
||||||
if (removePassword(passwords, hostname, userid)) {
|
} else {
|
||||||
savePasswordMap(systemType.getId(), passwords);
|
String khostname = getHostnameFromPasswordKey(key).toUpperCase();
|
||||||
|
String kuid = getUserIdFromPasswordKey(key);
|
||||||
|
if (kuid.equalsIgnoreCase(userid)) {
|
||||||
|
// uid matches, check if hosts are the same
|
||||||
|
if (khostname.startsWith(phostname) || phostname.startsWith(khostname)) {
|
||||||
|
String qkhost = RSECorePlugin.getQualifiedHostName(khostname);
|
||||||
|
String qphost = RSECorePlugin.getQualifiedHostName(phostname);
|
||||||
|
if (qkhost.equals(qphost)) {
|
||||||
|
password = (String) passwords.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return password;
|
||||||
/**
|
|
||||||
* Check if a password entry exists for the specified system type, hostname
|
|
||||||
* and userid.
|
|
||||||
*/
|
|
||||||
public boolean passwordExists(IRSESystemType systemtype, String hostname, String userid) {
|
|
||||||
|
|
||||||
return passwordExists(systemtype, hostname, userid, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a password entry exists for the specified system type, hostname
|
|
||||||
* and userid.
|
|
||||||
*
|
|
||||||
* @param systemtype The system type to check for.
|
|
||||||
* @param hname The hostname to check for.
|
|
||||||
* @param userid The user ID to check for.
|
|
||||||
* @param checkDefault Whether or not to check for a default system type if the specified system type is not found.
|
|
||||||
*/
|
|
||||||
public boolean passwordExists(IRSESystemType systemtype, String hname, String userid, boolean checkDefault) {
|
|
||||||
String hostname = hname;//RSEUIPlugin.getQualifiedHostName(hname);
|
|
||||||
return (find(systemtype, hostname, userid) != null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,58 +394,27 @@ public class PasswordPersistenceManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Retrieve the password map from the keyring for the specified system type
|
* Check if a password entry exists for the specified system type, hostname
|
||||||
|
* and userid.
|
||||||
*/
|
*/
|
||||||
private Map getPasswordMap(IRSESystemType systemType) {
|
public boolean passwordExists(IRSESystemType systemtype, String hostname, String userid) {
|
||||||
Map passwords = null;
|
|
||||||
String systemTypeId = systemType.getId();
|
return passwordExists(systemtype, hostname, userid, true);
|
||||||
|
|
||||||
try {
|
|
||||||
URL serverURL = new URL(newURL);
|
|
||||||
passwords = Platform.getAuthorizationInfo(serverURL, systemTypeId, AUTH_SCHEME);
|
|
||||||
|
|
||||||
// if no passwords found with new URL, check old URL
|
|
||||||
if (passwords == null) {
|
|
||||||
|
|
||||||
URL oldServerURL1 = new URL(SERVER_URL + ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
|
|
||||||
passwords = Platform.getAuthorizationInfo(oldServerURL1, systemTypeId, AUTH_SCHEME);
|
|
||||||
|
|
||||||
// passwords found, so migrate to using new URL
|
|
||||||
if (passwords != null) {
|
|
||||||
savePasswordMap(systemTypeId, passwords);
|
|
||||||
}
|
|
||||||
// if still no passwords found, check with even older URL
|
|
||||||
else {
|
|
||||||
URL oldServerURL2 = new URL(SERVER_URL);
|
|
||||||
passwords = Platform.getAuthorizationInfo(oldServerURL2, systemTypeId, AUTH_SCHEME);
|
|
||||||
|
|
||||||
// passwords found, so migrate to using new URL
|
|
||||||
if (passwords != null) {
|
|
||||||
savePasswordMap(systemTypeId, passwords);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
RSECorePlugin.getDefault().getLogger().logError("PasswordPersistenceManager.getPasswordMap", e); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
return passwords;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Retrieve the password map from the keyring for the specified system type
|
* Check if a password entry exists for the specified system type, hostname
|
||||||
|
* and userid.
|
||||||
|
*
|
||||||
|
* @param systemtype The system type to check for.
|
||||||
|
* @param hname The hostname to check for.
|
||||||
|
* @param userid The user ID to check for.
|
||||||
|
* @param checkDefault Whether or not to check for a default system type if the specified system type is not found.
|
||||||
*/
|
*/
|
||||||
private void savePasswordMap(String systemTypeId, Map passwords) {
|
public boolean passwordExists(IRSESystemType systemtype, String hname, String userid, boolean checkDefault) {
|
||||||
try {
|
String hostname = hname;//RSEUIPlugin.getQualifiedHostName(hname);
|
||||||
URL serverURL = new URL(newURL);
|
return (find(systemtype, hostname, userid) != null);
|
||||||
Platform.flushAuthorizationInfo(serverURL, systemTypeId, AUTH_SCHEME);
|
|
||||||
Platform.addAuthorizationInfo(serverURL, systemTypeId, AUTH_SCHEME, passwords);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
RSECorePlugin.getDefault().getLogger().logError("PasswordPersistenceManager.savePasswordMap", e); //$NON-NLS-1$
|
|
||||||
} catch (CoreException e) {
|
|
||||||
RSECorePlugin.getDefault().getLogger().logError("PasswordPersistenceManager.savePasswordMap", e); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,84 +427,6 @@ public class PasswordPersistenceManager {
|
||||||
return find(systemtype, hostname, userid, true);
|
return find(systemtype, hostname, userid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removePassword(Map passwords, String hostname, String userid) {
|
|
||||||
boolean removed = false;
|
|
||||||
String password = null;
|
|
||||||
|
|
||||||
String passwordKey = getPasswordKey(hostname, userid);
|
|
||||||
password = (String) passwords.get(passwordKey);
|
|
||||||
if (password != null) {
|
|
||||||
passwords.remove(passwordKey);
|
|
||||||
removed = true;
|
|
||||||
} else {
|
|
||||||
String phostname = hostname.toUpperCase();
|
|
||||||
|
|
||||||
// DKM - fallback for different case uids, hostnames or qualified/unqualified hostnames
|
|
||||||
Iterator keys = passwords.keySet().iterator();
|
|
||||||
while (keys.hasNext() && password == null) {
|
|
||||||
String key = (String) keys.next();
|
|
||||||
if (key.equalsIgnoreCase(passwordKey)) {
|
|
||||||
password = (String) passwords.get(key);
|
|
||||||
} else {
|
|
||||||
String khostname = getHostnameFromPasswordKey(key).toUpperCase();
|
|
||||||
String kuid = getUserIdFromPasswordKey(key);
|
|
||||||
if (kuid.equalsIgnoreCase(userid)) {
|
|
||||||
// uid matches, check if hosts are the same
|
|
||||||
if (khostname.startsWith(phostname) || phostname.startsWith(khostname)) {
|
|
||||||
String qkhost = RSECorePlugin.getQualifiedHostName(khostname);
|
|
||||||
String qphost = RSECorePlugin.getQualifiedHostName(phostname);
|
|
||||||
if (qkhost.equals(qphost)) {
|
|
||||||
password = (String) passwords.get(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (password != null) {
|
|
||||||
passwords.remove(key);
|
|
||||||
removed = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return removed;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPassword(Map passwords, String hostname, String userid) {
|
|
||||||
String password = null;
|
|
||||||
|
|
||||||
String passwordKey = getPasswordKey(hostname, userid);
|
|
||||||
password = (String) passwords.get(passwordKey);
|
|
||||||
if (password != null) return password;
|
|
||||||
|
|
||||||
String phostname = hostname.toUpperCase();
|
|
||||||
|
|
||||||
// DKM - fallback for different case uids, hostnames or qualified/unqualified hostnames
|
|
||||||
Iterator keys = passwords.keySet().iterator();
|
|
||||||
while (keys.hasNext() && password == null) {
|
|
||||||
String key = (String) keys.next();
|
|
||||||
if (key.equalsIgnoreCase(passwordKey)) {
|
|
||||||
password = (String) passwords.get(key);
|
|
||||||
} else {
|
|
||||||
String khostname = getHostnameFromPasswordKey(key).toUpperCase();
|
|
||||||
String kuid = getUserIdFromPasswordKey(key);
|
|
||||||
if (kuid.equalsIgnoreCase(userid)) {
|
|
||||||
// uid matches, check if hosts are the same
|
|
||||||
if (khostname.startsWith(phostname) || phostname.startsWith(khostname)) {
|
|
||||||
String qkhost = RSECorePlugin.getQualifiedHostName(khostname);
|
|
||||||
String qphost = RSECorePlugin.getQualifiedHostName(phostname);
|
|
||||||
if (qkhost.equals(qphost)) {
|
|
||||||
password = (String) passwords.get(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return password;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the persisted password for the specified systemtype, hostname and userid.
|
* Find the persisted password for the specified systemtype, hostname and userid.
|
||||||
*
|
*
|
||||||
|
@ -477,61 +441,81 @@ public class PasswordPersistenceManager {
|
||||||
if (!isUserIDCaseSensitive(systemtype) && userid != null) {
|
if (!isUserIDCaseSensitive(systemtype) && userid != null) {
|
||||||
userid = userid.toUpperCase();
|
userid = userid.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map passwords = getPasswordMap(systemtype);
|
Map passwords = getPasswordMap(systemtype);
|
||||||
|
|
||||||
if (passwords != null) {
|
if (passwords != null) {
|
||||||
String password = getPassword(passwords, hostname, userid);
|
String password = getPassword(passwords, hostname, userid);
|
||||||
|
|
||||||
if (password != null) {
|
if (password != null) {
|
||||||
return new SystemSignonInformation(hostname, userid, password, systemtype);
|
return new SystemSignonInformation(hostname, userid, password, systemtype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// yantzi: RSE6.2 check for default system type entry with this hostname and user ID
|
// yantzi: RSE6.2 check for default system type entry with this hostname and user ID
|
||||||
if (checkDefault && !DEFAULT_SYSTEM_TYPE.equals(systemtype)) {
|
if (checkDefault && !DEFAULT_SYSTEM_TYPE.equals(systemtype)) {
|
||||||
return find(DEFAULT_SYSTEM_TYPE, hostname, userid, false);
|
return find(DEFAULT_SYSTEM_TYPE, hostname, userid, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for building the key to lookup the password for a specific
|
* Remove the entry from the keyring that matches the systemtype, hostname and
|
||||||
* userid and hostname in the Map
|
* user ID from the SystemSignonInfo parameter.
|
||||||
*/
|
*/
|
||||||
private String getPasswordKey(String hname, String userid) {
|
public void remove(SystemSignonInformation info) {
|
||||||
String hostname = hname;//RSEUIPlugin.getQualifiedHostName(hname);
|
remove(info.getSystemType(), info.getHostname(), info.getUserId());
|
||||||
StringBuffer buffer = new StringBuffer(hostname);
|
|
||||||
buffer.append("//"); //$NON-NLS-1$
|
|
||||||
buffer.append(userid);
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getHostnameFromPasswordKey(String passwordKey) {
|
|
||||||
int sepIndex = passwordKey.indexOf("//"); //$NON-NLS-1$
|
|
||||||
return passwordKey.substring(0, sepIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUserIdFromPasswordKey(String passwordKey) {
|
|
||||||
int sepIndex = passwordKey.indexOf("//"); //$NON-NLS-1$
|
|
||||||
return passwordKey.substring(sepIndex + 2, passwordKey.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for determining if system type uses case sensitive user IDs
|
* Removes all passwords for a host name for a given system type. Use the
|
||||||
|
* default system type explicitly to remove those entries.
|
||||||
|
*
|
||||||
|
* @param systemType The system type of the host
|
||||||
|
* @param hostName The IP address of the host in canonical format
|
||||||
|
* @return the number of passwords removed from the keyring
|
||||||
|
* @since org.eclipse.rse.core 3.0
|
||||||
*/
|
*/
|
||||||
public boolean isUserIDCaseSensitive(IRSESystemType systemType) {
|
public int remove(IRSESystemType systemType, String hostName) {
|
||||||
// First find the correct provider
|
Map passwords = getPasswordMap(systemType);
|
||||||
for (int i = 0; i < systemTypes.length; i++) {
|
int numberRemoved = 0;
|
||||||
|
if (passwords != null) {
|
||||||
if (systemTypes[i].getSystemType().equals(systemType)) {
|
String hostPrefix = hostName + "//"; //$NON-NLS-1$
|
||||||
return systemTypes[i].isUserIDCaseSensitive();
|
Set keys = passwords.keySet();
|
||||||
|
for (Iterator z = keys.iterator(); z.hasNext();) {
|
||||||
|
String key = (String) z.next();
|
||||||
|
if (key.startsWith(hostPrefix)) {
|
||||||
|
z.remove(); // safely removes the key and the entry from the map
|
||||||
|
numberRemoved++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (numberRemoved > 0) {
|
||||||
|
savePasswordMap(systemType.getId(), passwords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return numberRemoved;
|
||||||
|
}
|
||||||
|
|
||||||
//Not found: Default system type is case sensitive
|
/**
|
||||||
return true;
|
* Removes all entries from the keyring that match the hostname, userid, and system type.
|
||||||
|
* Use the default system type explicitly to remove those entries.
|
||||||
|
* @param systemType the systemType
|
||||||
|
* @param hostName the connection name
|
||||||
|
* @param userid the user id
|
||||||
|
*/
|
||||||
|
public void remove(IRSESystemType systemType, String hostName, String userid) {
|
||||||
|
String hostname = hostName;//RSEUIPlugin.getQualifiedHostName(hname);
|
||||||
|
// Convert userid to upper case if required
|
||||||
|
if (!isUserIDCaseSensitive(systemType)) {
|
||||||
|
userid = userid.toUpperCase();
|
||||||
|
}
|
||||||
|
Map passwords = getPasswordMap(systemType);
|
||||||
|
if (passwords != null) {
|
||||||
|
if (removePassword(passwords, hostname, userid)) {
|
||||||
|
savePasswordMap(systemType.getId(), passwords);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -592,4 +576,20 @@ public class PasswordPersistenceManager {
|
||||||
return savedUserIDs;
|
return savedUserIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method for determining if system type uses case sensitive user IDs
|
||||||
|
*/
|
||||||
|
public boolean isUserIDCaseSensitive(IRSESystemType systemType) {
|
||||||
|
// First find the correct provider
|
||||||
|
for (int i = 0; i < systemTypes.length; i++) {
|
||||||
|
|
||||||
|
if (systemTypes[i].getSystemType().equals(systemType)) {
|
||||||
|
return systemTypes[i].isUserIDCaseSensitive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Not found: Default system type is case sensitive
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue