1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-23 08:13:50 +02:00

[180313] restoring behavior of StandardCredentialsProvider when invoked with an uninitialized workbench.

This commit is contained in:
David Dykstal 2007-04-03 00:59:43 +00:00
parent 70f93e8772
commit 2f54eead46
2 changed files with 71 additions and 48 deletions

View file

@ -39,6 +39,7 @@ public interface ICredentialsProvider {
* remembered credentials. * remembered credentials.
* @throws InterruptedException if the acquisition of credentials is * @throws InterruptedException if the acquisition of credentials is
* canceled by the user, if the provider is in suppressed state, * canceled by the user, if the provider is in suppressed state,
* a resource (such as the workbench) not being available,
* or interrupted by some other means. * or interrupted by some other means.
*/ */
void acquireCredentials(boolean reacquire) throws InterruptedException; void acquireCredentials(boolean reacquire) throws InterruptedException;
@ -50,7 +51,9 @@ public interface ICredentialsProvider {
* an expired password. * an expired password.
* @param message the message indicating the nature of the damage that must * @param message the message indicating the nature of the damage that must
* be repaired. For example, indicating expiration of a password. * be repaired. For example, indicating expiration of a password.
* @throws InterruptedException if the repair is canceled for some reason. * @throws InterruptedException if the repair is canceled for some reason. This could
* include the inability of a credentials provider to open a dialog or a dialog being
* canceled.
*/ */
void repairCredentials(SystemMessage message)throws InterruptedException; void repairCredentials(SystemMessage message)throws InterruptedException;

View file

@ -9,6 +9,7 @@
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.ui.subsystems; package org.eclipse.rse.ui.subsystems;
import org.eclipse.core.runtime.Platform;
import org.eclipse.rse.core.PasswordPersistenceManager; import org.eclipse.rse.core.PasswordPersistenceManager;
import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.SystemSignonInformation; import org.eclipse.rse.core.model.SystemSignonInformation;
@ -29,9 +30,11 @@ import org.eclipse.rse.ui.dialogs.SystemChangePasswordDialog;
import org.eclipse.rse.ui.dialogs.SystemPasswordPromptDialog; import org.eclipse.rse.ui.dialogs.SystemPasswordPromptDialog;
import org.eclipse.rse.ui.messages.SystemMessageDialog; import org.eclipse.rse.ui.messages.SystemMessageDialog;
import org.eclipse.rse.ui.validators.ISystemValidator; import org.eclipse.rse.ui.validators.ISystemValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/** /**
* The {@link StandardCredentialsProvider} is an extension of * The {@link StandardCredentialsProvider} is an extension of
@ -66,29 +69,34 @@ public class StandardCredentialsProvider extends AbstractCredentialsProvider {
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
public void run() { public void run() {
ISystemPasswordPromptDialog dialog = getPasswordPromptDialog(getShell()); Shell shell = getShell();
dialog.setSystemInput(getConnectorService()); if (shell != null) {
dialog.setForceToUpperCase(forcePasswordToUpperCase()); ISystemPasswordPromptDialog dialog = getPasswordPromptDialog(shell);
dialog.setSignonValidator(getSignonValidator()); dialog.setSystemInput(getConnectorService());
if (supportsUserId()) { dialog.setForceToUpperCase(forcePasswordToUpperCase());
dialog.setUserIdValidator(getUserIdValidator()); dialog.setSignonValidator(getSignonValidator());
} if (supportsUserId()) {
if (supportsPassword()) { dialog.setUserIdValidator(getUserIdValidator());
dialog.setSavePassword(savePassword); }
dialog.setPassword(password); if (supportsPassword()) {
dialog.setPasswordValidator(getPasswordValidator()); dialog.setSavePassword(savePassword);
} dialog.setPassword(password);
try { dialog.setPasswordValidator(getPasswordValidator());
dialog.open(); }
} catch (Exception e) { try {
logException(e); dialog.open();
} } catch (Exception e) {
canceled = dialog.wasCancelled(); logException(e);
if (!canceled) { }
userId = dialog.getUserId(); canceled = dialog.wasCancelled();
password = dialog.getPassword(); if (!canceled) {
saveUserId = dialog.getIsUserIdChangePermanent(); userId = dialog.getUserId();
savePassword = dialog.getIsSavePassword(); password = dialog.getPassword();
saveUserId = dialog.getIsUserIdChangePermanent();
savePassword = dialog.getIsSavePassword();
}
} else {
canceled = true;
} }
} }
} }
@ -110,13 +118,18 @@ public class StandardCredentialsProvider extends AbstractCredentialsProvider {
} }
public void run() { public void run() {
SystemChangePasswordDialog dlg = new SystemChangePasswordDialog(getShell(), getConnectorService().getHostName(), getUserId(), message); Shell shell = getShell();
dlg.setSavePassword(savePassword); if (shell != null) {
dlg.open(); SystemChangePasswordDialog dlg = new SystemChangePasswordDialog(shell, getConnectorService().getHostName(), getUserId(), message);
canceled = dlg.wasCancelled(); dlg.setSavePassword(savePassword);
if (!canceled) { dlg.open();
password = dlg.getNewPassword(); canceled = dlg.wasCancelled();
savePassword = dlg.getIsSavePassword(); if (!canceled) {
password = dlg.getNewPassword();
savePassword = dlg.getIsSavePassword();
}
} else {
canceled = true;
} }
} }
} }
@ -185,14 +198,15 @@ public class StandardCredentialsProvider extends AbstractCredentialsProvider {
if (validator != null) { if (validator != null) {
SystemMessage m = validator.validate(getCredentials()); SystemMessage m = validator.validate(getCredentials());
signonValid = (m == null); signonValid = (m == null);
} if (!signonValid) { // If we ran into an invalid stored password we need to tell the user.
// If we ran into an invalid password we need to tell the user. Shell shell = getShell();
// Not sure this is necessary, shouldn't this message show up on the password prompt itself? if (shell != null) {
if (!signonValid) { SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_INVALID);
SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_INVALID); msg.makeSubstitution(userId, getConnectorService().getHostName());
msg.makeSubstitution(userId, getConnectorService().getHostName()); SystemMessageDialog dialog = new SystemMessageDialog(shell, msg);
SystemMessageDialog dialog = new SystemMessageDialog(getShell(), msg); dialog.open();
dialog.open(); }
}
} }
if (supportsPassword() || supportsUserId()) { if (supportsPassword() || supportsUserId()) {
boolean passwordNeeded = supportsPassword() && password == null; boolean passwordNeeded = supportsPassword() && password == null;
@ -326,9 +340,9 @@ public class StandardCredentialsProvider extends AbstractCredentialsProvider {
} }
private ISystemValidator getPasswordValidator() { private ISystemValidator getPasswordValidator() {
ISubSystemConfiguration ssFactory = getPrimarySubSystem().getSubSystemConfiguration(); ISubSystemConfiguration subsystemConfiguration = getPrimarySubSystem().getSubSystemConfiguration();
ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) ssFactory.getAdapter(ISubSystemConfigurationAdapter.class); ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) Platform.getAdapterManager().getAdapter(subsystemConfiguration, ISubSystemConfigurationAdapter.class);
return adapter.getPasswordValidator(ssFactory); return adapter.getPasswordValidator(subsystemConfiguration);
} }
private ISubSystem getPrimarySubSystem() { private ISubSystem getPrimarySubSystem() {
@ -336,8 +350,14 @@ public class StandardCredentialsProvider extends AbstractCredentialsProvider {
} }
private Shell getShell() { private Shell getShell() {
Display display = Display.getDefault(); Shell shell = null;
Shell shell = new Shell(display, SWT.APPLICATION_MODAL); IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
shell = window.getShell();
}
}
return shell; return shell;
} }
@ -348,9 +368,9 @@ public class StandardCredentialsProvider extends AbstractCredentialsProvider {
} }
private ISystemValidator getUserIdValidator() { private ISystemValidator getUserIdValidator() {
ISubSystemConfiguration ssFactory = getPrimarySubSystem().getSubSystemConfiguration(); ISubSystemConfiguration subsystemConfiguration = getPrimarySubSystem().getSubSystemConfiguration();
ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) ssFactory.getAdapter(ISubSystemConfigurationAdapter.class); ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) Platform.getAdapterManager().getAdapter(subsystemConfiguration, ISubSystemConfigurationAdapter.class);
ISystemValidator validator = adapter.getUserIdValidator(ssFactory); ISystemValidator validator = adapter.getUserIdValidator(subsystemConfiguration);
return validator; return validator;
} }