diff --git a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreConnectorService.java index b0b2f8b2c77..9c1db915f08 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreConnectorService.java @@ -332,7 +332,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements notifyDisconnection(); clientConnection = null; // DKM - no need to clear uid cache - clearPassword(false); // clear in-memory password + clearPassword(false, true); // clear in-memory password //clearUserIdCache(); // Clear any cached local user IDs sysInfo = null; installInfo = null; @@ -528,7 +528,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements monitor.subTask(cmsg.getLevelOneText()); } - SystemSignonInformation info = getPasswordInformation(); + SystemSignonInformation info = getSignonInformation(); // GC: - if failed to get a connection in another way, try // starting the datastore server with rexec @@ -597,7 +597,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements // should be the same as the one stored in the password info (and for Windows // this will be the temp remoteuser userid. //launchStatus = clientConnection.launchServer(getLocalUserId(), getPassword(getPasswordInformation())); - SystemSignonInformation info = getPasswordInformation(); + SystemSignonInformation info = getSignonInformation(); if (info == null) { System.out.println("password info = null!"); @@ -632,17 +632,20 @@ public class DStoreConnectorService extends AbstractConnectorService implements // If password has expired and must be changed if (launchMsg != null && (isPasswordExpired(launchMsg) || isNewPasswordInvalid(launchMsg))) { - NewPasswordInfo newPasswordInfo = null; + SystemSignonInformation oldCredentials = (SystemSignonInformation) getCredentialsProvider().getCredentials(); + SystemSignonInformation newCredentials = null; while (launchMsg != null && (isPasswordExpired(launchMsg) || isNewPasswordInvalid(launchMsg))) { - newPasswordInfo = promptForNewPassword(isPasswordExpired(launchMsg) ? RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PASSWORD_EXPIRED) : RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PASSWORD_INVALID)); - launchStatus = changePassword(clientConnection, getPasswordInformation(), serverLauncher, monitor, newPasswordInfo.newPassword); + String messageId = isPasswordExpired(launchMsg) ? ISystemMessages.MSG_VALIDATE_PASSWORD_EXPIRED : ISystemMessages.MSG_VALIDATE_PASSWORD_INVALID; + SystemMessage message = RSEUIPlugin.getPluginMessage(messageId); + getCredentialsProvider().repairCredentials(message); + newCredentials = (SystemSignonInformation) getCredentialsProvider().getCredentials(); + launchStatus = changePassword(clientConnection, oldCredentials, serverLauncher, monitor, newCredentials.getPassword()); launchMsg = launchStatus.getMessage(); } - if (newPasswordInfo != null) + if (newCredentials != null) { - setPassword(info.getUserid(), newPasswordInfo.newPassword, newPasswordInfo.savePassword); - info = getPasswordInformation(); + info = newCredentials; } if (launchMsg != null && launchMsg.equals(IDataStoreConstants.ATTEMPT_RECONNECT)) { @@ -757,7 +760,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements // server launcher type is unknown else { - SystemSignonInformation info = getPasswordInformation(); + SystemSignonInformation info = getSignonInformation(); connectStatus = launchServer(clientConnection, info, serverLauncher, monitor); if (!connectStatus.isConnected() && !clientConnection.isKnownStatus(connectStatus.getMessage())) { @@ -935,7 +938,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements { if (launchFailed) { - clearPassword(true); + clearPassword(true, true); } // Display error message @@ -978,22 +981,38 @@ public class DStoreConnectorService extends AbstractConnectorService implements // If password has expired and must be changed else if (launchMsg != null && (isPasswordExpired(launchMsg) || isNewPasswordInvalid(launchMsg))) { - NewPasswordInfo newPasswordInfo = null; + SystemSignonInformation oldCredentials = (SystemSignonInformation) getCredentialsProvider().getCredentials(); + SystemSignonInformation newCredentials = null; while (launchMsg != null && (isPasswordExpired(launchMsg) || isNewPasswordInvalid(launchMsg))) { - newPasswordInfo = promptForNewPassword(isPasswordExpired(launchMsg) ? RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PASSWORD_EXPIRED) : RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PASSWORD_INVALID)); - launchStatus = changePassword(clientConnection, getPasswordInformation(), serverLauncher, monitor, newPasswordInfo.newPassword); + String messageId = isPasswordExpired(launchMsg) ? ISystemMessages.MSG_VALIDATE_PASSWORD_EXPIRED : ISystemMessages.MSG_VALIDATE_PASSWORD_INVALID; + SystemMessage message = RSEUIPlugin.getPluginMessage(messageId); + getCredentialsProvider().repairCredentials(message); + newCredentials = (SystemSignonInformation) getCredentialsProvider().getCredentials(); + launchStatus = changePassword(clientConnection, oldCredentials, serverLauncher, monitor, newCredentials.getPassword()); launchMsg = launchStatus.getMessage(); } - if (newPasswordInfo != null) - { - setPassword(getPasswordInformation().getUserid(), newPasswordInfo.newPassword, newPasswordInfo.savePassword); - } if (launchMsg != null && launchMsg.equals(IDataStoreConstants.ATTEMPT_RECONNECT)) { internalConnect(monitor); return; } +// NewPasswordInfo newPasswordInfo = null; +// while (launchMsg != null && (isPasswordExpired(launchMsg) || isNewPasswordInvalid(launchMsg))) +// { +// newPasswordInfo = promptForNewPassword(isPasswordExpired(launchMsg) ? RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PASSWORD_EXPIRED) : RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_VALIDATE_PASSWORD_INVALID)); +// launchStatus = changePassword(clientConnection, getPasswordInformation(), serverLauncher, monitor, newPasswordInfo.newPassword); +// launchMsg = launchStatus.getMessage(); +// } +// if (newPasswordInfo != null) +// { +// setPassword(getPasswordInformation().getUserid(), newPasswordInfo.newPassword, newPasswordInfo.savePassword); +// } +// if (launchMsg != null && launchMsg.equals(IDataStoreConstants.ATTEMPT_RECONNECT)) +// { +// internalConnect(monitor); +// return; +// } } else if (launchMsg != null) { @@ -1050,7 +1069,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements { if (launchFailed) { - clearPassword(true); + clearPassword(true, true); } DisplaySystemMessageAction msgAction = new DisplaySystemMessageAction(msg); @@ -1188,7 +1207,7 @@ public class DStoreConnectorService extends AbstractConnectorService implements */ protected ConnectionStatus launchServer(ClientConnection clientConnection, SystemSignonInformation info, int daemonPort, IProgressMonitor monitor, int timeout) { - return clientConnection.launchServer(info.getUserid(), info.getPassword(), daemonPort, timeout); + return clientConnection.launchServer(info.getUserId(), info.getPassword(), daemonPort, timeout); } /* diff --git a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreCredentialsProvider.java b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreCredentialsProvider.java index 00c00f342d7..de9b85f801d 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreCredentialsProvider.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/DStoreCredentialsProvider.java @@ -25,7 +25,7 @@ public class DStoreCredentialsProvider extends StandardCredentialsProvider { */ public boolean supportsPassword() { boolean result = super.supportsPassword(); - IHost host = getHost(); + IHost host = getConnectorService().getHost(); String systemType = host.getSystemType(); if (systemType.equals(IRSESystemType.SYSTEMTYPE_WINDOWS)) { result = false; @@ -38,7 +38,7 @@ public class DStoreCredentialsProvider extends StandardCredentialsProvider { */ public boolean supportsUserId() { boolean result = super.supportsUserId(); - IHost host = getHost(); + IHost host = getConnectorService().getHost(); String systemType = host.getSystemType(); if (systemType.equals(IRSESystemType.SYSTEMTYPE_WINDOWS)) { result = false; diff --git a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/RexecDstoreServer.java b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/RexecDstoreServer.java index 73faa55c424..531cbf6bae4 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/RexecDstoreServer.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.dstore/src/org/eclipse/rse/connectorservice/dstore/RexecDstoreServer.java @@ -440,7 +440,7 @@ public class RexecDstoreServer implements IServerLauncher rxOut.flush(); // send userid and password on rexec socket - rxOut.writeBytes(signonInfo.getUserid()); + rxOut.writeBytes(signonInfo.getUserId()); rxOut.writeByte(0); // send null terminator rxOut.writeBytes(signonInfo.getPassword()); rxOut.writeByte(0); // send null terminator diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java index 960234a4786..f9da016d272 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java @@ -294,9 +294,9 @@ public class SshConnectorService extends AbstractConnectorService implements ISs //session.setTimeout(getSshTimeoutInMillis()); session.setTimeout(0); //never time out on the session String password=""; //$NON-NLS-1$ - SystemSignonInformation ssi = getPasswordInformation(); + SystemSignonInformation ssi = getSignonInformation(); if (ssi!=null) { - password = getPasswordInformation().getPassword(); + password = getSignonInformation().getPassword(); } session.setPassword(password); MyUserInfo userInfo = new MyUserInfo(user, password); @@ -352,7 +352,7 @@ public class SshConnectorService extends AbstractConnectorService implements ISs //TODO MOB - keep the session to avoid NPEs in services (disables gc for the session!) // session = null; // DKM - no need to clear uid cache - clearPassword(false); // clear in-memory password + clearPassword(false, true); // clear in-memory password //clearUserIdCache(); // Clear any cached local user IDs } } @@ -706,14 +706,6 @@ public class SshConnectorService extends AbstractConnectorService implements ISs return false; } - /** - * @return false - * @see org.eclipse.rse.core.subsystems.AbstractConnectorService#requiresPassword() - */ - public boolean requiresPassword() { - return false; - } - protected ICredentialsProvider getCredentialsProvider() { if (credentialsProvider == null) { credentialsProvider = new SshCredentialsProvider(this); diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/PasswordPersistenceManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/PasswordPersistenceManager.java index 4b8f38aecd6..a8bebf51032 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/PasswordPersistenceManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/PasswordPersistenceManager.java @@ -150,7 +150,7 @@ public class PasswordPersistenceManager { */ public void remove(SystemSignonInformation info) { - remove(info.getSystemType(), info.getHostname(), info.getUserid()); + remove(info.getSystemType(), info.getHostname(), info.getUserId()); } /** @@ -247,11 +247,11 @@ public class PasswordPersistenceManager { // Convert userid to upper case if required if (!isUserIDCaseSensitive(systemtype)) { - info.setUserid(info.getUserid().toUpperCase()); + info.setUserId(info.getUserId().toUpperCase()); } String hostname = info.getHostname(); - String userid = info.getUserid(); + String userid = info.getUserId(); Map passwords = getPasswordMap(systemtype); String passwordKey = getPasswordKey(hostname, userid); diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/SystemSignonInformation.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/SystemSignonInformation.java index bac55ea8849..a8a1593456d 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/SystemSignonInformation.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/SystemSignonInformation.java @@ -29,7 +29,7 @@ import org.eclipse.rse.core.subsystems.ICredentials; public final class SystemSignonInformation implements ICredentials { private String _hostname; - private String _userid; + private String _userId; private String _systemType; private String _password; @@ -44,7 +44,7 @@ public final class SystemSignonInformation implements ICredentials { */ public SystemSignonInformation(String hostname, String userid, String systemType) { _hostname = hostname;//RSEUIPlugin.getQualifiedHostName(hostname).toUpperCase(); - _userid = userid; + _userId = userid; _systemType = systemType; } @@ -53,7 +53,7 @@ public final class SystemSignonInformation implements ICredentials { */ public SystemSignonInformation(String hostname, String userid, String password, String systemType) { _hostname = hostname;//RSEUIPlugin.getQualifiedHostName(hostname).toUpperCase(); - _userid = userid; + _userId = userid; _password = password; _systemType = systemType; } @@ -78,8 +78,8 @@ public final class SystemSignonInformation implements ICredentials { * Returns the userid for the remote system * @return String */ - public String getUserid() { - return _userid; + public String getUserId() { + return _userId; } /** @@ -114,10 +114,10 @@ public final class SystemSignonInformation implements ICredentials { /** * Sets the userid. - * @param userid The userid to set + * @param userId The userid to set */ - public void setUserid(String userid) { - _userid = userid; + public void setUserId(String userId) { + _userId = userId; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/BasicCredentialsProvider.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/BasicCredentialsProvider.java index 7c2d5990aa9..91ab17869ab 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/BasicCredentialsProvider.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/BasicCredentialsProvider.java @@ -7,9 +7,9 @@ * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService ********************************************************************************/ - package org.eclipse.rse.core.subsystems; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; /** * The {@link BasicCredentialsProvider} provides a simple implementation of the {@link ICredentialsProvider} @@ -19,27 +19,65 @@ package org.eclipse.rse.core.subsystems; * This class is not meant to be subclassed. */ public class BasicCredentialsProvider implements ICredentialsProvider { - - public boolean requiresPassword() { - return false; - } - - public boolean requiresUserId() { - return false; - } - - public boolean supportsPassword() { - return false; - } - - public boolean supportsUserId() { - return false; - } - public void acquireCredentials(boolean reacquire) { } - + public void clearCredentials() { } + public void clearPassword() { + // TODO Auto-generated method stub + } + + public ICredentials getCredentials() { + // TODO Auto-generated method stub + return null; + } + + public String getUserId() { + // TODO Auto-generated method stub + return null; + } + + public boolean isSuppressed() { + // TODO Auto-generated method stub + return false; + } + + public void repairCredentials(SystemMessage message) throws InterruptedException { + // TODO Auto-generated method stub + } + + public boolean requiresPassword() { + return false; + } + + public boolean requiresUserId() { + return false; + } + + public void setPassword(String password) { + // TODO Auto-generated method stub + } + + public void setSuppressed(boolean suppressed) { + // TODO Auto-generated method stub + } + + public void setUserId(String userId) { + // TODO Auto-generated method stub + } + + public boolean supportsPassword() { + return false; + } + + public boolean supportsUserId() { + return false; + } + + public IConnectorService getConnectorService() { + // TODO Auto-generated method stub + return null; + } } diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/IConnectorService.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/IConnectorService.java index 36550aa8da6..a1f77b9a524 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/IConnectorService.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/IConnectorService.java @@ -118,11 +118,6 @@ public interface IConnectorService extends IRSEModelObject { */ public String getHostType(); - /** - * @return the name of this connector service - */ - public String getName(); - /** * Sets the host used by this connector service. * @param host @@ -182,24 +177,6 @@ public interface IConnectorService extends IRSEModelObject { */ public boolean supportsPassword(); - /** - * Reports if this connector service requires a user id. - * Returns true in default implementation. - * Typically used to indicate if a login dialog can allow an empty user id. - * Must be ignored if supportsUserId() is false. - * @return true or false to indicate if the connector service requires a user id. - */ - public boolean requiresUserId(); - - /** - * Determines if a password is required for this connector service. - * Must be ignored if {@link #supportsPassword()} returns false. - * The default implementation of this interface should return true. - * @return true if the connector service requires a password, - * false if a password may be empty. - */ - public boolean requiresPassword(); - /** * @return the userId that will be used by this connector when * establishing its connection. @@ -213,6 +190,10 @@ public interface IConnectorService extends IRSEModelObject { */ public void setUserId(String userId); + public void saveUserId(); + + public void removeUserId(); + /** * Sets the password used by this connector service. * Can be used if the connector service acquires a password by some external @@ -220,17 +201,23 @@ public interface IConnectorService extends IRSEModelObject { * @param matchingUserId The user id to be associated with this password. * @param password the password * @param persist true if the password is to be persisted for later use. + * @param propagate true if this password should be propagated to related connector services. */ - public void setPassword(String matchingUserId, String password, boolean persist); - + public void setPassword(String matchingUserId, String password, boolean persist, boolean propagate); + + public void savePassword(); + + public void removePassword(); + /** * Clear password held by this service and optionally * clear its persistent form. * Called when user uses the property dialog to * change his userId. - * @param onDisk if true, clears the persistent form of the password + * @param persist if true, clears the persistent form of the password + * @param propagate true if this password should be cleared in related connector services. */ - public void clearPassword(boolean onDisk); + public void clearPassword(boolean persist, boolean propagate); /** * @param onDisk retrieve the persistent form of the password. diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentials.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentials.java index 62aed2eb8d1..7c5d5891880 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentials.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentials.java @@ -10,4 +10,9 @@ package org.eclipse.rse.core.subsystems; public interface ICredentials { + + String getPassword(); + + String getUserId(); + } diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentialsProvider.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentialsProvider.java index 0428e0f3088..3b8bb6c9468 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentialsProvider.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/ICredentialsProvider.java @@ -9,18 +9,38 @@ ********************************************************************************/ package org.eclipse.rse.core.subsystems; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; + public interface ICredentialsProvider { - boolean supportsPassword(); + void acquireCredentials(boolean reacquire) throws InterruptedException; - boolean supportsUserId(); + void clearCredentials(); + + void clearPassword(); + + ICredentials getCredentials(); + + String getUserId(); + + boolean isSuppressed(); + + void repairCredentials(SystemMessage message)throws InterruptedException; boolean requiresPassword(); boolean requiresUserId(); - void acquireCredentials(boolean reacquire); + void setPassword(String password); - void clearCredentials(); + void setSuppressed(boolean suppressed); + + void setUserId(String userId); + + boolean supportsPassword(); + + boolean supportsUserId(); + + IConnectorService getConnectorService(); } diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/connectorservice/FTPConnectorService.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/connectorservice/FTPConnectorService.java index 85060b3e1c3..80121e2ccc8 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/connectorservice/FTPConnectorService.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/internal/subsystems/files/ftp/connectorservice/FTPConnectorService.java @@ -65,9 +65,9 @@ public class FTPConnectorService extends AbstractConnectorService _propertySet.addProperty("passive","false",PropertyType.getEnumPropertyType(new String[]{"true","false"})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } - SystemSignonInformation info = getPasswordInformation(); + SystemSignonInformation info = getSignonInformation(); _ftpService.setHostName(info.getHostname()); - _ftpService.setUserId(info.getUserid()); + _ftpService.setUserId(info.getUserId()); _ftpService.setPassword(info.getPassword()); _ftpService.setPortNumber(getPort()); _ftpService.setLoggingStream(getLoggingStream(info.getHostname(),getPort())); diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearAllPasswordsAction.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearAllPasswordsAction.java index ae88ebe64ba..27a288c48f5 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearAllPasswordsAction.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearAllPasswordsAction.java @@ -98,7 +98,7 @@ public class SystemClearAllPasswordsAction extends SystemBaseAction { // clear userid/password from memory and fire event //DKM and disk now - system.clearPassword(true); + system.clearPassword(true, true); RSEUIPlugin.getTheSystemRegistry().fireEvent(new SystemResourceChangeEvent(ss, ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE, ss.getHost())); diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearPasswordAction.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearPasswordAction.java index 6198d54be8b..c60ca7601e1 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearPasswordAction.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemClearPasswordAction.java @@ -71,7 +71,7 @@ public class SystemClearPasswordAction extends SystemBaseAction ISubSystem ss = (ISubSystem)getFirstSelection(); try { IConnectorService system = ss.getConnectorService(); - system.clearPassword(true); + system.clearPassword(true, true); RSEUIPlugin.getTheSystemRegistry().fireEvent(new SystemResourceChangeEvent(ss, ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE, ss.getHost())); diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/dialogs/SystemPasswordPersistencePrompt.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/dialogs/SystemPasswordPersistencePrompt.java index 240d0a7de3d..4e3d5acfd37 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/dialogs/SystemPasswordPersistencePrompt.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/dialogs/SystemPasswordPersistencePrompt.java @@ -183,12 +183,12 @@ public final class SystemPasswordPersistencePrompt extends SystemPromptDialog im if (change) { - if (exists(signonInfo.getHostname(), signonInfo.getUserid(), signonInfo.getSystemType())) + if (exists(signonInfo.getHostname(), signonInfo.getUserId(), signonInfo.getSystemType())) { if (!signonInfo.getSystemType().equals(originalSystemType) || !signonInfo.getHostname().equalsIgnoreCase(originalHostname) || //!signonInfo.getHostname().equalsIgnoreCase(RSEUIPlugin.getQualifiedHostName(originalHostname)) || - !signonInfo.getUserid().equals(originalUserid)) + !signonInfo.getUserId().equals(originalUserid)) { // User changed hostname, systemtype or userid and the change conflicts with an existing entry SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_EXISTS); @@ -203,7 +203,7 @@ public final class SystemPasswordPersistencePrompt extends SystemPromptDialog im else { // Adding a new entry, make sure it doesn't already exist - if (exists(signonInfo.getHostname(), signonInfo.getUserid(), signonInfo.getSystemType())) + if (exists(signonInfo.getHostname(), signonInfo.getUserId(), signonInfo.getSystemType())) { SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_EXISTS); msg.makeSubstitution(sUserID, sHostName); @@ -234,11 +234,11 @@ public final class SystemPasswordPersistencePrompt extends SystemPromptDialog im { if (!manager.isUserIDCaseSensitive(info.getSystemType())) { - found = userID.equalsIgnoreCase(info.getUserid()); + found = userID.equalsIgnoreCase(info.getUserId()); } else { - found = userID.equals(info.getUserid()); + found = userID.equals(info.getUserId()); } } } diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/propertypages/SignonPreferencePage.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/propertypages/SignonPreferencePage.java index 672ecd18b08..828366d10ff 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/propertypages/SignonPreferencePage.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/propertypages/SignonPreferencePage.java @@ -134,7 +134,7 @@ public final class SignonPreferencePage extends PreferencePage implements IWorkb return ((SystemSignonInformation) element).getSystemType(); case 2: - return ((SystemSignonInformation) element).getUserid(); + return ((SystemSignonInformation) element).getUserId(); } // Should never get here @@ -281,7 +281,7 @@ public final class SignonPreferencePage extends PreferencePage implements IWorkb SystemPasswordPersistencePrompt dialog = new SystemPasswordPersistencePrompt(getShell(), SystemResources.RESID_PREF_SIGNON_CHANGE_DIALOG_TITLE, passwords, true); int index = pwdTable.getSelectionIndex(); SystemSignonInformation info = (SystemSignonInformation) passwords.get(index); - dialog.setInputData(info.getSystemType(), info.getHostname(), info.getUserid()); + dialog.setInputData(info.getSystemType(), info.getHostname(), info.getUserId()); if (dialog.open() == Window.OK) { // Remove old and add new @@ -368,7 +368,7 @@ public final class SignonPreferencePage extends PreferencePage implements IWorkb system = subsystems[k].getConnectorService(); if (system != null) { - system.clearPassword(false); + system.clearPassword(false, true); } } } diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/SystemRegistry.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/SystemRegistry.java index b7024710cc7..c983fa4be27 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/SystemRegistry.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/model/SystemRegistry.java @@ -2549,7 +2549,7 @@ public class SystemRegistry implements ISystemRegistryUI, ISystemModelChangeEven { subsystems[idx].getConnectorService().clearCredentials(); } - subsystems[idx].getConnectorService().clearPassword(false); + subsystems[idx].getConnectorService().clearPassword(false, true); } catch (Exception exc) { diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractConnectorService.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractConnectorService.java index 90b197425ad..816f83d59a6 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractConnectorService.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractConnectorService.java @@ -13,35 +13,19 @@ * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies ********************************************************************************/ - package org.eclipse.rse.core.subsystems; + import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.rse.core.IRSEUserIdConstants; import org.eclipse.rse.core.PasswordPersistenceManager; -import org.eclipse.rse.core.SystemBasePlugin; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.core.model.SystemSignonInformation; -import org.eclipse.rse.core.subsystems.util.ISubSystemConfigurationAdapter; -import org.eclipse.rse.logging.Logger; -import org.eclipse.rse.logging.LoggerFactory; import org.eclipse.rse.model.ISystemRegistryUI; -import org.eclipse.rse.services.clientserver.messages.SystemMessage; -import org.eclipse.rse.ui.ISystemMessages; import org.eclipse.rse.ui.RSEUIPlugin; -import org.eclipse.rse.ui.dialogs.ICredentialsValidator; -import org.eclipse.rse.ui.dialogs.ISystemPasswordPromptDialog; -import org.eclipse.rse.ui.dialogs.SystemChangePasswordDialog; -import org.eclipse.rse.ui.dialogs.SystemPasswordPromptDialog; -import org.eclipse.rse.ui.messages.SystemMessageDialog; -import org.eclipse.rse.ui.validators.ISystemValidator; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; - /** * This is a base class to make it easier to create connector service classes. @@ -72,83 +56,43 @@ import org.eclipse.ui.PlatformUI; * * * @see org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager - */ -public abstract class AbstractConnectorService extends SuperAbstractConnectorService implements IRSEUserIdConstants -{ - - private String _userId; - private transient SystemSignonInformation _passwordInfo; - protected Shell shell; - // dy: March 24, 2003 Added _suppressSignonPrompt flag to suppress prompting the - // user to signon if they already cancelled signon. Then intent is to allows tools - // writers to prevent multiple signon prompts during a "transaction" if the user cancel - // the first signon prompt - private boolean _suppressSignonPrompt = false; - - - public AbstractConnectorService(String name, String description, IHost host, int port) - { + */ +public abstract class AbstractConnectorService extends SuperAbstractConnectorService implements IRSEUserIdConstants { + public AbstractConnectorService(String name, String description, IHost host, int port) { super(name, description, host, port); - } + } - - /** + /** * Useful utility method. Fully implemented, do not override.
* Returns the active userId if we are connected. * If not it returns the userId for the primary subsystem ignoring the * cached userId. */ final public String getUserId() { - String result = null; - if (supportsUserId()) { - result = getLocalUserId(); - if (result == null) { - result = getSubSystemUserId(); - } - } - return result; + return getCredentialsProvider().getUserId(); } - /** - * Useful utility method. Fully implemented, do not override.
- * Return the userId for this connector service. If there is none - * set for this service then it is retrieved from the primary subsystem. - */ - final protected String getLocalUserId() { - return _userId; - } - - /** - * @return the userId from the primary subsystem. - */ - private String getSubSystemUserId() { - ISubSystem ss = getPrimarySubSystem(); - String result = ss.getUserId(); - return result; - } - - /* (non-Javadoc) + /* (non-Javadoc) * @see org.eclipse.rse.core.subsystems.IConnectorService#setUserId(java.lang.String) */ - final public void setUserId(String newId) - { - - if (_userId == null || !_userId.equals(newId)) { - _userId = newId; + final public void setUserId(String newId) { + ICredentialsProvider provider = getCredentialsProvider(); + String oldUserId = provider.getUserId(); + if (oldUserId == null || oldUserId.equals(newId)) { + updateDefaultUserId(getPrimarySubSystem(), getUserId()); + provider.setUserId(newId); setDirty(true); } } - - /** - * Useful utility method. Fully implemented, do not override.
- * Clear internal userId. Called when user uses the property dialog to - * change his userId. By default, sets internal userId value to null so that on - * the next call to getUserId() it is requeried from subsystem. - * Also clears the password. - */ - final public void clearCredentials() { - _userId = null; - clearPassword(false); + + public final void saveUserId() { + ICredentialsProvider provider = getCredentialsProvider(); + String userId = provider.getUserId(); + updateDefaultUserId(getPrimarySubSystem(), userId); + } + + public final void removeUserId() { + updateDefaultUserId(getPrimarySubSystem(), null); } /** @@ -156,22 +100,18 @@ public abstract class AbstractConnectorService extends SuperAbstractConnectorSer * Clear internal password cache. Called when user uses the property dialog to * change his userId. * - * @param onDisk if this is true, clear the password from the disk cache as well + * @param persist if this is true, clear the password from the disk cache as well * @see #clearCredentials() */ - final public void clearPassword(boolean onDisk) { - setPasswordInformation(null); - String userId = getUserId(); - if (onDisk) { - // now get rid of userid/password from disk - String systemType = getHostType(); - String hostName = getHostName(); - if (userId != null) - PasswordPersistenceManager.getInstance().remove(systemType, hostName, userId); + final public void clearPassword(boolean persist, boolean propagate) { + ICredentialsProvider provider = getCredentialsProvider(); + provider.clearPassword(); + if (persist) { + removePassword(); } - if (sharesCredentials()) { - // clear this uid/password with other ISystems in connection - clearPasswordForOtherSystemsInConnection(userId, onDisk); + if (sharesCredentials() && propagate) { + String userId = provider.getUserId(); + clearPasswordForOtherSystemsInConnection(userId, false); } } @@ -184,9 +124,9 @@ public abstract class AbstractConnectorService extends SuperAbstractConnectorSer * @return true if the password is known, false otherwise. */ final public boolean hasPassword(boolean onDisk) { - boolean cached = (getPasswordInformation() != null); + SystemSignonInformation signonInformation = getSignonInformation(); + boolean cached = (signonInformation != null && signonInformation.getPassword() != null); if (!cached && onDisk) { - // now check if cached on disk String systemType = getHostType(); String hostName = getHostName(); String userId = getUserId(); @@ -196,530 +136,191 @@ public abstract class AbstractConnectorService extends SuperAbstractConnectorSer } return cached; } - - /* (non-Javadoc) - * @see org.eclipse.rse.core.subsystems.IConnectorService#requiresPassword() - */ - public boolean requiresPassword() { - return true; - } - - - /* (non-Javadoc) - * @see org.eclipse.rse.core.subsystems.IConnectorService#requiresUserId() - */ - public boolean requiresUserId() { - return true; - } - /** - * Do not override. - * Sets the signon information for this connector service. - * The search order for the password is as follows:

- *
    - *
  1. First check if the password is already known by this connector service and that it is still valid. - *
  2. If password not known then look in the password store and verify that it is still valid. - *
  3. If a valid password is not found then prompt the user. - *
- * Must be run in the UI thread. - * Can be null if the password is known to exist in either this class or in the password store. - * @param forcePrompt if true then present the prompt even if the password was found and is valid. - * @throws InterruptedException if user is prompted and user cancels that prompt or if isSuppressSignonPrompt is true. + * Useful utility method. Fully implemented, no need to override.
+ * Set the password if you got it from somewhere + * @param userId the user for which to set the password + * @param password the password to set for this userId + * @param persist true if the password is to be persisted, + * false if its persistent form is to be removed. + * @param propagate if the password should be propagated to related connector services. */ - public void acquireCredentials(boolean forcePrompt) throws InterruptedException { - // dy: March 24, 2003: check if prompting is temporarily suppressed by a tool - // vendor, this should only be suppressed if the user cancelled a previous signon - // dialog (or some other good reason) - if (isSuppressed()) { - throw new InterruptedException(); + public final void setPassword(String userId, String password, boolean persist, boolean propagate) { + if (getPrimarySubSystem().forceUserIdToUpperCase()) { + userId = userId.toUpperCase(); } - - ISubSystem subsystem = getPrimarySubSystem(); - IHost host = subsystem.getHost(); - String hostName = host.getHostName(); - String hostType = host.getSystemType(); - boolean savePassword = false; - if (_passwordInfo == null) { - _passwordInfo = new SystemSignonInformation(hostName, null, null, hostType); + ICredentialsProvider provider = getCredentialsProvider(); + String myUserId = provider.getUserId(); + IHost host = getHost(); + if (host.compareUserIds(userId, myUserId)) { + provider.setPassword(password); } - if (supportsUserId()) { - String userId = getUserId(); - if (_passwordInfo.getUserid() == null) { - _passwordInfo.setUserid(userId); - } - boolean sameUserId = host.compareUserIds(userId, _passwordInfo.getUserid()); - boolean sameHost = hostName.equalsIgnoreCase(_passwordInfo.getHostname()); - if (!(sameHost && sameUserId)) { - _passwordInfo.setPassword(null); - _passwordInfo.setUserid(userId); - } + if (sharesCredentials() && propagate) { + updatePasswordForOtherSystemsInConnection(userId, password, persist); } - if (supportsPassword()) { - if (_passwordInfo.getPassword() == null) { - PasswordPersistenceManager ppm = PasswordPersistenceManager.getInstance(); - String userId = _passwordInfo.getUserid(); - SystemSignonInformation savedPasswordInformation = ppm.find(hostType, hostName, userId); - if (savedPasswordInformation != null) { - _passwordInfo = savedPasswordInformation; - savePassword = true; - } - } - } - ICredentialsValidator validator = getSignonValidator(); - boolean signonValid = true; - if (validator != null) { - SystemMessage m = validator.validate(_passwordInfo); - signonValid = (m == null); - } - - // If we ran into an invalid password we need to tell the user. - // DWD refactor - want to move this to a pluggable class so that this can be moved to core. - // DWD not sure this is necessary, shouldn't this message show up on the password prompt itself? - if (!signonValid) { - SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_INVALID); - msg.makeSubstitution(getLocalUserId(), getHostName()); - SystemMessageDialog dialog = new SystemMessageDialog(shell, msg); - dialog.open(); - } - if (shell == null) - { - try - { - shell = SystemBasePlugin.getActiveWorkbenchShell(); - } - catch (Exception e) - { - shell = new Shell(); - } - } - - if (supportsPassword() || supportsUserId()) - { - if (shell == null) - { - try - { - shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - } - catch (Exception e) - { - shell = new Shell(); - } - } - if (shell != null) { - boolean passwordNeeded = supportsPassword() && _passwordInfo.getPassword() == null; - boolean userIdNeeded = supportsUserId() && _passwordInfo.getUserid() == null; - if (passwordNeeded || userIdNeeded || forcePrompt) { - ISystemPasswordPromptDialog dialog = getPasswordPromptDialog(shell); - if (dialog != null) { - dialog.setSystemInput(this); - dialog.setSignonValidator(getSignonValidator()); - if (supportsUserId()) { - dialog.setUserIdValidator(getUserIdValidator()); - } - if (supportsPassword()) { - String password = _passwordInfo.getPassword(); - dialog.setSavePassword(savePassword); - dialog.setPassword(password); - dialog.setPasswordValidator(getPasswordValidator()); - } - try { - dialog.open(); - } catch (Exception e) { - logException(e); - } - if (dialog.wasCancelled()) { - _passwordInfo = null; - throw new InterruptedException(); - } - String userId = dialog.getUserId(); - boolean userIdChanged = dialog.getIsUserIdChanged(); - boolean saveUserId = dialog.getIsUserIdChangePermanent(); - String password = dialog.getPassword(); - savePassword = dialog.getIsSavePassword(); - if (supportsUserId() && userIdChanged) { - if (saveUserId) { - updateDefaultUserId(subsystem, userId); - } else { - setUserId(userId); - _passwordInfo.setUserid(userId); - } - } - if (supportsPassword()) { - setPassword(userId, password, savePassword); - if (sharesCredentials()) { - updatePasswordForOtherSystemsInConnection(userId, password, savePassword); - } - } - } - } - } + if (persist) { + savePassword(); + } else { + removePassword(); } } - - protected void clearPasswordForOtherSystemsInConnection(String uid, boolean fromDisk) - { - if (uid != null) - { - IHost connection = getHost(); - ISystemRegistry registry = RSEUIPlugin.getTheSystemRegistry(); - ISubSystem[] subsystems = registry.getSubSystems(connection); - - List uniqueSystems = new ArrayList(); - for (int i = 0; i < subsystems.length; i++) - { - IConnectorService system = subsystems[i].getConnectorService(); - if (system != this && system.inheritsCredentials()) - { - if (!uniqueSystems.contains(system)) - { - uniqueSystems.add(system); - } - } - } - - for (int s = 0; s < uniqueSystems.size(); s++) - { - IConnectorService system = (IConnectorService)uniqueSystems.get(s); - if (system.hasPassword(fromDisk)) - { - system.clearPassword(fromDisk); - } - } - } - } - - - protected void updatePasswordForOtherSystemsInConnection(String uid, String password, boolean persistPassword) - { - IHost connection = getPrimarySubSystem().getHost(); - ISystemRegistry registry = RSEUIPlugin.getTheSystemRegistry(); - ISubSystem[] subsystems = registry.getSubSystems(connection); - - List uniqueSystems = new ArrayList(); - for (int i = 0; i < subsystems.length; i++) - { - IConnectorService system = subsystems[i].getConnectorService(); - if (system != this && system.inheritsCredentials()) - { - if (!uniqueSystems.contains(system)) - { - uniqueSystems.add(system); - } - } - } - - for (int s = 0; s < uniqueSystems.size(); s++) - { - IConnectorService system = (IConnectorService)uniqueSystems.get(s); - if (!system.isConnected() && !system.hasPassword(false)) - { - if (system.getPrimarySubSystem().forceUserIdToUpperCase()) - { - system.setPassword(uid.toUpperCase(), password.toUpperCase(), persistPassword); - } - else - { - system.setPassword(uid, password, persistPassword); - } - } - } - } - - /** - * Change the default user Id value in the SubSystem if it is non-null, else - * update it in the Connection object - */ - private void updateDefaultUserId(ISubSystem subsystem, String userId) { - String ssLocalUserId = subsystem.getLocalUserId(); - if (ssLocalUserId != null) { // defect 42709 - ISubSystemConfiguration ssc = subsystem.getSubSystemConfiguration(); - ssc.updateSubSystem(subsystem, true, userId, false, 0); - } else { // it seems intuitive to update the connection object. defect 42709. Phil - int whereToUpdate = IRSEUserIdConstants.USERID_LOCATION_HOST; - IHost conn = subsystem.getHost(); - ISystemRegistryUI sr = RSEUIPlugin.getDefault().getSystemRegistry(); - sr.updateHost(null, conn, conn.getSystemType(), conn.getAliasName(), conn.getHostName(), conn.getDescription(), userId, whereToUpdate); + public final void savePassword() { + ICredentialsProvider provider = getCredentialsProvider(); + ICredentials credentials = provider.getCredentials(); + if (credentials instanceof SystemSignonInformation) { + SystemSignonInformation signonInformation = (SystemSignonInformation) credentials; + PasswordPersistenceManager.getInstance().add(signonInformation, true, true); } } - /** - * A default implementation is supplied, but can be overridden if desired.
- * Instantiates and returns the dialog to prompt for the userId and password. - *

- * By default returns an instance of SystemPasswordPromptDialog. Calls forcePasswordToUpperCase() to decide whether the user Id and password should be folded to uppercase. - *

- * Calls {@link #getUserIdValidator()} and {@link #getPasswordValidator()} to set the validators. These return null by default by you can override them. - *

- * Before calling open() on the dialog, the getPassword(Shell) method that calls this will call setSystemInput(this). - *

- * After return, it will call wasCancelled() and getUserId(), getIsUserIdChanged(), getIsUserIdChangePermanent() and getPassword(). - *

- * - * @return An instance of a dialog class that implements the ISystemPasswordPromptDialog interface - */ - protected final ISystemPasswordPromptDialog getPasswordPromptDialog(Shell shell) - { - ISystemPasswordPromptDialog dlg = new SystemPasswordPromptDialog(shell, requiresUserId(), requiresPassword()); - dlg.setForceToUpperCase(forcePasswordToUpperCase()); - dlg.setUserIdValidator(getUserIdValidator()); - dlg.setPasswordValidator(getPasswordValidator()); - dlg.setSignonValidator(getSignonValidator()); - return dlg; - } + public final void removePassword() { + ICredentialsProvider provider = getCredentialsProvider(); + String systemType = getHostType(); + String hostName = getHostName(); + String userId = provider.getUserId(); + PasswordPersistenceManager.getInstance().remove(systemType, hostName, userId); + } - /** + /** + * This connection method wrappers the others (internal connect) so that registered subsystems + * can be notified and initialized after a connect + * Previous implementations that overrode this method should now change + * their connect() method to internalConnect() + */ + public final void connect(IProgressMonitor monitor) throws Exception { + internalConnect(monitor); + intializeSubSystems(monitor); + } + + /** + * Disconnects from the remote system. + *

+ * You must override + * if subsystem.getParentSubSystemConfiguration().supportsServerLaunchProperties + * returns false. + *

+ * If the subsystem supports server launch + * the default behavior is to use the same remote server + * launcher created in connect() and call disconnect(). + *

+ * This is called, by default, from the disconnect() + * method of the subsystem. + * @see IServerLauncher#disconnect() + */ + public final void disconnect(IProgressMonitor monitor) throws Exception { + internalDisconnect(monitor); + unintializeSubSystems(monitor); + clearPassword(false, true); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.IConnectorService#isSuppressed() + */ + public final boolean isSuppressed() { + return getCredentialsProvider().isSuppressed(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.IConnectorService#setSuppressed(boolean) + */ + public final void setSuppressed(boolean suppressed) { + getCredentialsProvider().setSuppressed(suppressed); + } + + public final void acquireCredentials(boolean reacquire) throws InterruptedException { + getCredentialsProvider().acquireCredentials(reacquire); + } + + /** + * Useful utility method. Fully implemented, do not override.
+ * Clear internal userId. Called when user uses the property dialog to + * change his userId. By default, sets internal userId value to null so that on + * the next call to getUserId() it is requeried from subsystem. + * Also clears the password. + */ + final public void clearCredentials() { + getCredentialsProvider().clearCredentials(); + setDirty(true); + } + + /** * Useful utility method. Fully implemented, no need to override.
* @return the password information for the primary subsystem of this * connector service. Assumes it has been set by the subsystem at the * time the subsystem acquires the connector service. */ - final protected SystemSignonInformation getPasswordInformation() { - return _passwordInfo; + final protected SystemSignonInformation getSignonInformation() { + SystemSignonInformation result = null; + ICredentialsProvider provider = getCredentialsProvider(); + ICredentials credentials = provider.getCredentials(); + result = (SystemSignonInformation) credentials; + return result; } - /** - * Useful utility method. Fully implemented, no need to override.
- * Sets the password information for this system's subsystem. - * @param passwordInfo the password information object - */ - final protected void setPasswordInformation(SystemSignonInformation passwordInfo) { - _passwordInfo = passwordInfo; - if (passwordInfo != null) { - _userId = passwordInfo.getUserid(); - } - } - - /** - * Useful utility method. Fully implemented, no need to override.
- * Set the password if you got it from somewhere - * @param matchingUserId the user for which to set the password - * @param password the password to set for this userid - * @param persist true if the password is to be persisted as well - */ - public void setPassword(String matchingUserId, String password, boolean persist) { - if (getPrimarySubSystem().forceUserIdToUpperCase()) { - matchingUserId = matchingUserId.toUpperCase(); - } - SystemSignonInformation tempPasswordInfo = new SystemSignonInformation(getHostName(), matchingUserId, password, getHostType()); - setPasswordInformation(tempPasswordInfo); - if (persist) { // if password should be persisted, then add to disk - PasswordPersistenceManager.getInstance().add(tempPasswordInfo, true, true); - } else { // otherwise, remove from both memory and disk - String systemType = getHostType(); - String hostName = getHostName(); - PasswordPersistenceManager.getInstance().remove(systemType, hostName, _userId); - } - } - - /** - * Useful utility method. Fully implemented, no need to override.
- * Should passwords be folded to uppercase? - * By default, returns: - *

getSubSystem().forceUserIdToUpperCase()
- */ - protected boolean forcePasswordToUpperCase() - { - return getPrimarySubSystem().forceUserIdToUpperCase(); - } - - /** - * Useful utility method. Fully implemented, no need to override.
- * Get the userId input validator to use in the password dialog prompt. - *

- * By default, returns

- *
getSubSystem().getParentSubSystemConfiguration().getUserIdValidator()
- */ - final public ISystemValidator getUserIdValidator() - { - ISubSystemConfiguration ssFactory = getPrimarySubSystem().getSubSystemConfiguration(); - ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter)ssFactory.getAdapter(ISubSystemConfigurationAdapter.class); - return adapter.getUserIdValidator(ssFactory); - } - - /** - * Useful utility method. Fully implemented, no need to override.
- * Get the password input validator to use in the password dialog prompt. - *

- * By default, returns:

- *
getSubSystem().getParentSubSystemConfiguration().getPasswordValidator()
- */ - final public ISystemValidator getPasswordValidator() - { - ISubSystemConfiguration ssFactory = getPrimarySubSystem().getSubSystemConfiguration(); - ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter)ssFactory.getAdapter(ISubSystemConfigurationAdapter.class); - return adapter.getPasswordValidator(ssFactory); - } - - /** - * Optionally overridable, not implemented by default.
- * Get the signon validator to use in the password dialog prompt. - * By default, returns null. - */ - public ICredentialsValidator getSignonValidator() - { - return null; - } - - - /** - * This connection method wrappers the others (internal connect) so that registered subsystems - * can be notified and initialized after a connect - * Previous implementations that overrode this method should now change - * their connect() method to internalConnect() - */ - public final void connect(IProgressMonitor monitor) throws Exception - { - internalConnect(monitor); - intializeSubSystems(monitor); - } - - // protected void internalConnect(IProgressMonitor monitor) throws Exception -// { -// if (supportsServerLaunchProperties()) -// { -// IServerLauncher starter = getRemoteServerLauncher(); -// starter.setSignonInformation(getPasswordInformation()); -// starter.setServerLauncherProperties(getRemoteServerLauncherProperties()); -// launchResult = null; -// if (!starter.isLaunched()) -// { -// try { -// launchResult = starter.launch(monitor); -// } catch (Exception exc) { -// throw new java.lang.reflect.InvocationTargetException(exc); -// } -// } -// connectResult = null; -// try { -// connectResult = starter.connect(monitor, getConnectPort()); -// } catch (Exception exc) { -// throw new java.lang.reflect.InvocationTargetException(exc); -// } -// } -// } - /** - * Disconnects from the remote system. - *

- * You must override - * if subsystem.getParentSubSystemConfiguration().supportsServerLaunchProperties - * returns false. - *

- * If the subsystem supports server launch - * the default behavior is to use the same remote server - * launcher created in connect() and call disconnect(). - *

- * This is called, by default, from the disconnect() - * method of the subsystem. - * @see IServerLauncher#disconnect() - */ - public final void disconnect(IProgressMonitor monitor) throws Exception - { - internalDisconnect(monitor); - unintializeSubSystems(monitor); - clearPassword(false); - } - - /** - * Returns the suppressSignonPrompt flag. If this is set to true then the user - * will not be prompted to signon, instead an InterruptedException will be thrown - * by the promptForPassword method. - * - * @return boolean - */ - public boolean isSuppressed() - { - return _suppressSignonPrompt; - } - - /** - * Sets the suppressSignonPrompt flag. Tool writers can use this to temporarily - * disable the user from being prompted to signon. This would cause the promptForPassword - * method to throw an InterruptedException instead of prompting. The intent of this - * method is to allow tool writeres to prevent multiple signon prompts during a - * set period of time (such as a series of related communication calls) if the user - * cancels the first prompt. It is the callers responsability to set this value - * back to false when the tool no longer needs to suppress the signon prompt or all - * other tools sharing this connection will be affected. - * - * @param suppressSignonPrompt - */ - public void setSuppressed(boolean suppressSignonPrompt) - { - _suppressSignonPrompt = suppressSignonPrompt; - } - - private void logException(Throwable t) { - Logger log = LoggerFactory.getLogger(RSEUIPlugin.getDefault()); - log.logError("Unexpected exception", t); //$NON-NLS-1$ - } - - public NewPasswordInfo promptForNewPassword(SystemMessage prompt) throws InterruptedException - { - ShowPromptForNewPassword msgAction = new ShowPromptForNewPassword(prompt); - Display.getDefault().syncExec(msgAction); - if (msgAction.isCancelled()) throw new InterruptedException(); - return new NewPasswordInfo(msgAction.getNewPassword(), msgAction.isSavePassword()); - } - - private class ShowPromptForNewPassword implements Runnable - { - private SystemMessage _msg; - private String newPassword; - private boolean savePassword; - private boolean cancelled = false; - - public ShowPromptForNewPassword(SystemMessage msg) - { - _msg = msg; - } - - public void run() - { - SystemChangePasswordDialog dlg = new SystemChangePasswordDialog(SystemBasePlugin.getActiveWorkbenchShell(), getHostName(), getUserId(), _msg); - // Check if password was saved, if so preselect the save checkbox - if (getLocalUserId() != null) - { - dlg.setSavePassword(PasswordPersistenceManager.getInstance().passwordExists(getHostType(), getHostName(), getLocalUserId())); + private void updatePasswordForOtherSystemsInConnection(String uid, String password, boolean persist) { + IHost connection = getPrimarySubSystem().getHost(); + ISystemRegistry registry = RSEUIPlugin.getTheSystemRegistry(); + ISubSystem[] subsystems = registry.getSubSystems(connection); + List uniqueSystems = new ArrayList(); + for (int i = 0; i < subsystems.length; i++) { + IConnectorService cs = subsystems[i].getConnectorService(); + if (cs != this && cs.inheritsCredentials()) { + if (!uniqueSystems.contains(cs)) { + uniqueSystems.add(cs); + } } - dlg.open(); - if (dlg.wasCancelled()) - { - cancelled = true; - return; + } + for (int s = 0; s < uniqueSystems.size(); s++) { + IConnectorService system = (IConnectorService) uniqueSystems.get(s); + if (!system.isConnected() && !system.hasPassword(false)) { + if (system.getPrimarySubSystem().forceUserIdToUpperCase()) { + uid = uid.toUpperCase(); + password = password.toUpperCase(); + } + system.setPassword(uid, password, false, false); } - newPassword = dlg.getNewPassword(); - savePassword = dlg.getIsSavePassword(); - return; - } - - public boolean isCancelled() - { - return cancelled; - } - - public String getNewPassword() - { - return newPassword; - } - - public boolean isSavePassword() - { - return savePassword; } } - - public class NewPasswordInfo - { - public String newPassword; - public boolean savePassword; - - public NewPasswordInfo(String newPW, boolean savePW) - { - newPassword = newPW; - savePassword = savePW; + + private void clearPasswordForOtherSystemsInConnection(String uid, boolean persist) { + if (uid != null) { + IHost connection = getHost(); + ISystemRegistry registry = RSEUIPlugin.getTheSystemRegistry(); + ISubSystem[] subsystems = registry.getSubSystems(connection); + List uniqueSystems = new ArrayList(); + for (int i = 0; i < subsystems.length; i++) { + IConnectorService system = subsystems[i].getConnectorService(); + if (system != this && system.inheritsCredentials()) { + if (!uniqueSystems.contains(system)) { + uniqueSystems.add(system); + } + } + } + for (int s = 0; s < uniqueSystems.size(); s++) { + IConnectorService system = (IConnectorService) uniqueSystems.get(s); + if (system.hasPassword(persist)) { + system.clearPassword(persist, false); + } + } + } + } + + /** + * Change the default user Id value in the SubSystem if it is non-null, else + * update it in the Connection object + */ + private void updateDefaultUserId(ISubSystem subsystem, String userId) { + String ssLocalUserId = subsystem.getLocalUserId(); + if (ssLocalUserId != null) { + ISubSystemConfiguration ssc = subsystem.getSubSystemConfiguration(); + ssc.updateSubSystem(subsystem, true, userId, false, 0); + } else { + int whereToUpdate = IRSEUserIdConstants.USERID_LOCATION_HOST; + IHost host = subsystem.getHost(); + ISystemRegistryUI sr = RSEUIPlugin.getTheSystemRegistry(); + sr.updateHost(null, host, host.getSystemType(), host.getAliasName(), host.getHostName(), host.getDescription(), userId, whereToUpdate); } } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java index f0551179bcc..26dcb301cc1 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java @@ -55,11 +55,11 @@ public abstract class AbstractDelegatingConnectorService implements IDelegatingC return false; } - public void clearPassword(boolean clearDiskCache) { + public void clearPassword(boolean clearDiskCache, boolean propagate) { IConnectorService conServ = getRealConnectorService(); if (conServ != null) { - conServ.clearPassword(clearDiskCache); + conServ.clearPassword(clearDiskCache, propagate); } } @@ -370,24 +370,6 @@ public abstract class AbstractDelegatingConnectorService implements IDelegatingC return false; } - public boolean requiresPassword() { - IConnectorService conServ = getRealConnectorService(); - if (conServ != null) - { - return conServ.requiresPassword(); - } - return false; - } - - public boolean requiresUserId() { - IConnectorService conServ = getRealConnectorService(); - if (conServ != null) - { - return conServ.requiresUserId(); - } - return false; - } - public void reset() { IConnectorService conServ = getRealConnectorService(); if (conServ != null) @@ -421,11 +403,11 @@ public abstract class AbstractDelegatingConnectorService implements IDelegatingC } public void setPassword(String matchingUserId, String password, - boolean persist) { + boolean persist, boolean propagate) { IConnectorService conServ = getRealConnectorService(); if (conServ != null) { - conServ.setPassword(matchingUserId, password, persist); + conServ.setPassword(matchingUserId, password, persist, propagate); } } @@ -515,8 +497,39 @@ public abstract class AbstractDelegatingConnectorService implements IDelegatingC } return false; } + + public void saveUserId() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.saveUserId(); + } + } + + public void removeUserId() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.removeUserId(); + } + } + public void savePassword() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.savePassword(); + } + } + public void removePassword() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.removePassword(); + } + } + public boolean wasRestored() { IConnectorService conServ = getRealConnectorService(); if (conServ != null) diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/ui/subsystems/StandardCredentialsProvider.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/ui/subsystems/StandardCredentialsProvider.java index 838c9698dae..3a9290cebe2 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/ui/subsystems/StandardCredentialsProvider.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/ui/subsystems/StandardCredentialsProvider.java @@ -7,15 +7,32 @@ * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService ********************************************************************************/ - package org.eclipse.rse.ui.subsystems; import org.eclipse.rse.core.PasswordPersistenceManager; import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.SystemSignonInformation; import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ICredentials; import org.eclipse.rse.core.subsystems.ICredentialsProvider; +import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; import org.eclipse.rse.core.subsystems.SuperAbstractConnectorService; +import org.eclipse.rse.core.subsystems.util.ISubSystemConfigurationAdapter; +import org.eclipse.rse.logging.Logger; +import org.eclipse.rse.logging.LoggerFactory; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.RSEUIPlugin; +import org.eclipse.rse.ui.dialogs.ICredentialsValidator; +import org.eclipse.rse.ui.dialogs.ISystemPasswordPromptDialog; +import org.eclipse.rse.ui.dialogs.SystemChangePasswordDialog; +import org.eclipse.rse.ui.dialogs.SystemPasswordPromptDialog; +import org.eclipse.rse.ui.messages.SystemMessageDialog; +import org.eclipse.rse.ui.validators.ISystemValidator; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; /** * The {@link StandardCredentialsProvider} is an implementation of @@ -33,13 +50,199 @@ import org.eclipse.rse.core.subsystems.SuperAbstractConnectorService; * specific prompting. */ public class StandardCredentialsProvider implements ICredentialsProvider { - - private IConnectorService connectorService = null; + private class PromptForCredentials implements Runnable { + private boolean canceled = false; + + public boolean isCanceled() { + return canceled; + } + + public void run() { + ISystemPasswordPromptDialog dialog = getPasswordPromptDialog(getShell()); + dialog.setSystemInput(connectorService); + dialog.setForceToUpperCase(forcePasswordToUpperCase()); + dialog.setSignonValidator(getSignonValidator()); + if (supportsUserId()) { + dialog.setUserIdValidator(getUserIdValidator()); + } + if (supportsPassword()) { + dialog.setSavePassword(savePassword); + dialog.setPassword(password); + dialog.setPasswordValidator(getPasswordValidator()); + } + try { + dialog.open(); + } catch (Exception e) { + logException(e); + } + canceled = dialog.wasCancelled(); + if (!canceled) { + userId = dialog.getUserId(); + password = dialog.getPassword(); + saveUserId = dialog.getIsUserIdChangePermanent(); + savePassword = dialog.getIsSavePassword(); + } + } + } + private class PromptForNewPassword implements Runnable { + private SystemMessage message; + private boolean canceled = false; + + public PromptForNewPassword(SystemMessage message) { + this.message = message; + } + + public boolean isCancelled() { + return canceled; + } + + public void run() { + SystemChangePasswordDialog dlg = new SystemChangePasswordDialog(getShell(), connectorService.getHostName(), getUserId(), message); + dlg.setSavePassword(savePassword); + dlg.open(); + canceled = dlg.wasCancelled(); + if (!canceled) { + password = dlg.getNewPassword(); + savePassword = dlg.getIsSavePassword(); + } + } + + } + private IConnectorService connectorService = null; + private String userId = null; + private String password = null; + private boolean suppressed = false; + private boolean savePassword = false; + private boolean saveUserId = false; + public StandardCredentialsProvider(IConnectorService connectorService) { this.connectorService = connectorService; } + /** + * Do not override. + * Sets the signon information for this connector service. + * The search order for the password is as follows:

+ *
    + *
  1. First check if the password is already known by this connector service and that it is still valid. + *
  2. If password not known then look in the password store and verify that it is still valid. + *
  3. If a valid password is not found then prompt the user. + *
+ * Must be run in the UI thread. + * Can be null if the password is known to exist in either this class or in the password store. + * @param reacquire if true then present the prompt even if the password was found and is valid. + * @throws InterruptedException if user is prompted and user cancels that prompt or if isSuppressSignonPrompt is true. + */ + public void acquireCredentials(boolean reacquire) throws InterruptedException { + if (isSuppressed()) { + throw new InterruptedException(); + } + ISubSystem subsystem = getPrimarySubSystem(); + IHost host = subsystem.getHost(); + String hostName = host.getHostName(); + String hostType = host.getSystemType(); + savePassword = false; + if (supportsUserId()) { + boolean sameHost = hostName.equalsIgnoreCase(connectorService.getHostName()); + if (!sameHost) { + clearCredentials(); + } + getUserId(); + } + if (supportsPassword()) { + if (password == null) { + PasswordPersistenceManager ppm = PasswordPersistenceManager.getInstance(); + SystemSignonInformation savedSignonInformation = ppm.find(hostType, hostName, userId); + if (savedSignonInformation != null) { + password = savedSignonInformation.getPassword(); + savePassword = true; + } + } + } + ICredentialsValidator validator = getSignonValidator(); + boolean signonValid = true; + if (validator != null) { + SystemMessage m = validator.validate(getCredentials()); + signonValid = (m == null); + } + // If we ran into an invalid password we need to tell the user. + // Not sure this is necessary, shouldn't this message show up on the password prompt itself? + if (!signonValid) { + SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_INVALID); + msg.makeSubstitution(userId, connectorService.getHostName()); + SystemMessageDialog dialog = new SystemMessageDialog(getShell(), msg); + dialog.open(); + } + if (supportsPassword() || supportsUserId()) { + boolean passwordNeeded = supportsPassword() && password == null; + boolean userIdNeeded = supportsUserId() && userId == null; + if (passwordNeeded || userIdNeeded || reacquire) { + promptForCredentials(); + if (savePassword) { + connectorService.savePassword(); + } else { + connectorService.removePassword(); + } + if (saveUserId) { + connectorService.saveUserId(); + } + } + } + } + + public void clearCredentials() { + password = null; + userId = null; + } + + /** + * Useful utility method. Fully implemented, do not override.
+ * Clear internal password cache. Called when user uses the property dialog to + * change his userId. + */ + final public void clearPassword() { + password = null; + } + + public IConnectorService getConnectorService() { + return connectorService; + } + + public ICredentials getCredentials() { + IHost host = connectorService.getHost(); + String hostName = host.getHostName(); + String systemType = host.getSystemType(); + SystemSignonInformation result = new SystemSignonInformation(hostName, userId, password, systemType); + return result; + } + + /** + * Useful utility method. Fully implemented, do not override.
+ * Returns the active userId if we are connected. + * If not it returns the userId for the primary subsystem ignoring the + * cached userId. + */ + final public String getUserId() { + if (supportsUserId()) { + if (userId == null) { + userId = getSubSystemUserId(); + } + } + return userId; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.IConnectorService#isSuppressed() + */ + public final boolean isSuppressed() { + return suppressed; + } + + public void repairCredentials(SystemMessage prompt) throws InterruptedException { + promptForNewPassword(prompt); + } + public boolean requiresPassword() { return true; } @@ -48,6 +251,48 @@ public class StandardCredentialsProvider implements ICredentialsProvider { return true; } + public void setPassword(String password) { + this.password = password; + } + + /** + * Useful utility method. Fully implemented, no need to override.
+ * Set the password if you got it from somewhere + * @param matchingUserId the user for which to set the password + * @param password the password to set for this userid + * @param persist true if the password is to be persisted as well + */ + public final void setPassword(String matchingUserId, String password, boolean persist) { + if (getPrimarySubSystem().forceUserIdToUpperCase()) { + matchingUserId = matchingUserId.toUpperCase(); + } + SystemSignonInformation signonInformation = new SystemSignonInformation(connectorService.getHostName(), matchingUserId, password, connectorService.getHostType()); + setSignonInformation(signonInformation); + if (persist) { // if password should be persisted, then add to disk + PasswordPersistenceManager.getInstance().add(signonInformation, true, true); + } else { // otherwise, remove from both memory and disk + String systemType = connectorService.getHostType(); + String hostName = connectorService.getHostName(); + PasswordPersistenceManager.getInstance().remove(systemType, hostName, userId); + } + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.IConnectorService#setSuppressed(boolean) + */ + public final void setSuppressed(boolean suppressed) { + this.suppressed = suppressed; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.IConnectorService#setUserId(java.lang.String) + */ + final public void setUserId(String newId) { + if (userId == null || !userId.equals(newId)) { + userId = newId; + } + } + public boolean supportsPassword() { return true; } @@ -56,16 +301,108 @@ public class StandardCredentialsProvider implements ICredentialsProvider { return true; } - protected final IHost getHost() { - return connectorService.getHost(); + /** + * A default implementation is supplied, but can be overridden if desired.
+ * Instantiates and returns the dialog to prompt for the userId and password. + * @return An instance of a dialog class that implements the ISystemPasswordPromptDialog interface + */ + protected ISystemPasswordPromptDialog getPasswordPromptDialog(Shell shell) { + ISystemPasswordPromptDialog dlg = new SystemPasswordPromptDialog(shell, requiresUserId(), requiresPassword()); + return dlg; + } + + /** + * Optionally overridable, not implemented by default.
+ * Get the signon validator to use in the password dialog prompt. + * By default, returns null. + */ + protected ICredentialsValidator getSignonValidator() { + return null; + } + + /** + * Useful utility method. Fully implemented, no need to override.
+ * Should passwords be folded to uppercase? + * By default, returns: + *
getSubSystem().forceUserIdToUpperCase()
+ */ + private boolean forcePasswordToUpperCase() { + return getPrimarySubSystem().forceUserIdToUpperCase(); + } + + /** + * Useful utility method. Fully implemented, no need to override.
+ * Get the password input validator to use in the password dialog prompt. + *

+ * By default, returns:

+ *
getSubSystem().getParentSubSystemConfiguration().getPasswordValidator()
+ */ + private ISystemValidator getPasswordValidator() { + ISubSystemConfiguration ssFactory = getPrimarySubSystem().getSubSystemConfiguration(); + ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) ssFactory.getAdapter(ISubSystemConfigurationAdapter.class); + return adapter.getPasswordValidator(ssFactory); + } + + private ISubSystem getPrimarySubSystem() { + return connectorService.getPrimarySubSystem(); + } + + private Shell getShell() { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + return shell; + } + + /** + * @return the userId from the primary subsystem. + */ + private String getSubSystemUserId() { + ISubSystem ss = getPrimarySubSystem(); + String result = ss.getUserId(); + return result; + } + + /** + * Useful utility method. Fully implemented, no need to override.
+ * Get the userId input validator to use in the password dialog prompt. + *

+ * By default, returns

+ *
getSubSystem().getParentSubSystemConfiguration().getUserIdValidator()
+ */ + private ISystemValidator getUserIdValidator() { + ISubSystemConfiguration ssFactory = getPrimarySubSystem().getSubSystemConfiguration(); + ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) ssFactory.getAdapter(ISubSystemConfigurationAdapter.class); + ISystemValidator validator = adapter.getUserIdValidator(ssFactory); + return validator; + } + + private void logException(Throwable t) { + Logger log = LoggerFactory.getLogger(RSEUIPlugin.getDefault()); + log.logError("Unexpected exception", t); //$NON-NLS-1$ + } + + private void promptForCredentials() throws InterruptedException { + PromptForCredentials runnable = new PromptForCredentials(); + Display.getDefault().syncExec(runnable); + if (runnable.isCanceled()) { + throw new InterruptedException(); + } } - public void acquireCredentials(boolean reacquire) { - // TODO Auto-generated method stub + private void promptForNewPassword(SystemMessage prompt) throws InterruptedException { + PromptForNewPassword runnable = new PromptForNewPassword(prompt); + Display.getDefault().syncExec(runnable); + if (runnable.isCancelled()) { + throw new InterruptedException(); + } } - public void clearCredentials() { - // TODO Auto-generated method stub + /** + * Useful utility method. Fully implemented, no need to override.
+ * Sets the password information for this system's subsystem. + * @param signonInfo the password information object + */ + private void setSignonInformation(SystemSignonInformation signonInfo) { + password = signonInfo.getPassword(); + userId = signonInfo.getUserId(); } - }