1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

[149285] [ssh] multiple prompts and errors in case of incorrect username (Apply patch from Anna Dushistova)

This commit is contained in:
Martin Oberhuber 2008-04-25 21:28:49 +00:00
parent a91925a579
commit b309d5375c

View file

@ -1,24 +1,25 @@
/******************************************************************************** /********************************************************************************
* Copyright (c) 2002, 2008 IBM Corporation and others. All rights reserved. * Copyright (c) 2002, 2008 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms * This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is * of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html * available at http://www.eclipse.org/legal/epl-v10.html
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* Martin Oberhuber (Wind River) - [174945] Remove obsolete icons from rse.shells.ui * Martin Oberhuber (Wind River) - [174945] Remove obsolete icons from rse.shells.ui
* Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty()
* Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect() * Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect()
* Kevin Doyle (IBM) - [187083] Launch Shell action available on folders inside virtual files * Kevin Doyle (IBM) - [187083] Launch Shell action available on folders inside virtual files
* David McKnight (IBM) - [216252] [api][nls] Resource Strings specific to subsystems should be moved from rse.ui into files.ui / shells.ui / processes.ui where possible * David McKnight (IBM) - [216252] [api][nls] Resource Strings specific to subsystems should be moved from rse.ui into files.ui / shells.ui / processes.ui where possible
* David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared * David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared
* Anna Dushistova (MontaVista) - [149285] [ssh] multiple prompts and errors in case of incorrect username
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.shells.ui.actions; package org.eclipse.rse.internal.shells.ui.actions;
@ -29,6 +30,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
@ -77,7 +79,7 @@ import org.eclipse.swt.widgets.Shell;
/** /**
* Launches a shell and/or runs a shell command, displaying the output * Launches a shell and/or runs a shell command, displaying the output
* in the Remote Shell view. * in the Remote Shell view.
*/ */
public class SystemCommandAction extends SystemBaseAction public class SystemCommandAction extends SystemBaseAction
{ {
@ -90,14 +92,14 @@ public class SystemCommandAction extends SystemBaseAction
_cmdsPart = cmdsPart; _cmdsPart = cmdsPart;
_cmd = cmd; _cmd = cmd;
} }
public void run() public void run()
{ {
_cmdsPart.updateOutput(_cmd); _cmdsPart.updateOutput(_cmd);
} }
} }
private class RunShellJob extends Job private class RunShellJob extends Job
{ {
private IRemoteCmdSubSystem _ss; private IRemoteCmdSubSystem _ss;
@ -108,7 +110,7 @@ public class SystemCommandAction extends SystemBaseAction
_ss = ss; _ss = ss;
_cmdsPart = cmdsPart; _cmdsPart = cmdsPart;
} }
public IStatus run(IProgressMonitor monitor) public IStatus run(IProgressMonitor monitor)
{ {
try try
@ -123,6 +125,9 @@ public class SystemCommandAction extends SystemBaseAction
catch (SystemMessageException e) { catch (SystemMessageException e) {
SystemMessageDialog.displayMessage(e); SystemMessageDialog.displayMessage(e);
} }
catch (OperationCanceledException e) {
//do nothing--it's user's action
}
catch (Exception e) { catch (Exception e) {
SystemBasePlugin.logError( SystemBasePlugin.logError(
e.getLocalizedMessage()!=null ? e.getLocalizedMessage() : e.getClass().getName(), e.getLocalizedMessage()!=null ? e.getLocalizedMessage() : e.getClass().getName(),
@ -131,28 +136,40 @@ public class SystemCommandAction extends SystemBaseAction
return Status.OK_STATUS; return Status.OK_STATUS;
} }
} }
public class PromptForPassword implements Runnable public class PromptForPassword implements Runnable
{ {
public SubSystem _ss; public SubSystem _ss;
private boolean connectionCancelled=false;
public PromptForPassword(SubSystem ss) public PromptForPassword(SubSystem ss)
{ {
_ss = ss; _ss = ss;
} }
public void run() public void run()
{ {
try try
{ {
_ss.promptForPassword(); _ss.promptForPassword();
} }
catch (OperationCanceledException canceledEx) {
setConnectionCancelled(true);
}
catch (Exception e) catch (Exception e)
{ {
/* ignore */
} }
} }
public void setConnectionCancelled(boolean connectionCancelled) {
this.connectionCancelled = connectionCancelled;
}
public boolean isConnectionCancelled() {
return connectionCancelled;
}
} }
public class UpdateRegistry implements Runnable public class UpdateRegistry implements Runnable
{ {
private SubSystem _ss; private SubSystem _ss;
@ -160,25 +177,25 @@ public class SystemCommandAction extends SystemBaseAction
{ {
_ss = ss; _ss = ss;
} }
public void run() public void run()
{ {
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
registry.connectedStatusChange(_ss, true, false); registry.connectedStatusChange(_ss, true, false);
} }
} }
private IRemoteFile _selected; private IRemoteFile _selected;
private ISystemFilterReference _selectedFilterRef; private ISystemFilterReference _selectedFilterRef;
private boolean _isShell; private boolean _isShell;
private IRemoteCmdSubSystem _cmdSubSystem; private IRemoteCmdSubSystem _cmdSubSystem;
/** /**
* The command dialog used when running a command. * The command dialog used when running a command.
*/ */
public class CommandDialog extends SystemPromptDialog public class CommandDialog extends SystemPromptDialog
{ {
@ -289,7 +306,7 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* validate the invocation * validate the invocation
* @return a SystemMessage if the invocation is invalid. * @return a SystemMessage if the invocation is invalid.
*/ */
protected SystemMessage validateInvocation() protected SystemMessage validateInvocation()
{ {
@ -299,7 +316,7 @@ public class SystemCommandAction extends SystemBaseAction
if (theNewName.length() == 0) if (theNewName.length() == 0)
{ {
String msgTxt = ShellResources.MSG_UCMD_INVOCATION_EMPTY; String msgTxt = ShellResources.MSG_UCMD_INVOCATION_EMPTY;
_errorMessage = new SimpleSystemMessage(ShellsUIPlugin.PLUGIN_ID, _errorMessage = new SimpleSystemMessage(ShellsUIPlugin.PLUGIN_ID,
"RSEG1260", //$NON-NLS-1$ "RSEG1260", //$NON-NLS-1$
IStatus.ERROR, msgTxt); IStatus.ERROR, msgTxt);
} }
@ -321,7 +338,9 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* Constructor for SystemCommandAction * Constructor for SystemCommandAction
* @param parent *
* @param parent Shell of parent window. Can be null if you don't know it,
* but call setShell when you do.
*/ */
public SystemCommandAction(Shell parent) public SystemCommandAction(Shell parent)
{ {
@ -330,8 +349,11 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* Constructor for SystemCommandAction * Constructor for SystemCommandAction
* @param parent *
* @param isShell indication of whether this action launches a shell or runs a command * @param parent Shell of parent window. Can be null if you don't know it,
* but call setShell when you do.
* @param isShell indication of whether this action launches a shell or runs
* a command
*/ */
public SystemCommandAction(Shell parent, boolean isShell) public SystemCommandAction(Shell parent, boolean isShell)
{ {
@ -340,8 +362,11 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* Constructor for SystemCommandAction * Constructor for SystemCommandAction
* @param parent *
* @param isShell indication of whether this action launches a shell or runs a command * @param parent Shell of parent window. Can be null if you don't know it,
* but call setShell when you do.
* @param isShell indication of whether this action launches a shell or runs
* a command
* @param cmdSubSystem the command subsystem to use if launching a shell * @param cmdSubSystem the command subsystem to use if launching a shell
*/ */
public SystemCommandAction(Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) public SystemCommandAction(Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem)
@ -356,9 +381,12 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* Constructor for SystemCommandAction * Constructor for SystemCommandAction
*
* @param title the title of the action * @param title the title of the action
* @param parent * @param parent Shell of parent window. Can be null if you don't know it,
* @param isShell indication of whether this action launches a shell or runs a command * but call setShell when you do.
* @param isShell indication of whether this action launches a shell or runs
* a command
* @param cmdSubSystem the command subsystem to use if launching a shell * @param cmdSubSystem the command subsystem to use if launching a shell
*/ */
public SystemCommandAction(String title, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) public SystemCommandAction(String title, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem)
@ -369,12 +397,15 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* Constructor for SystemCommandAction * Constructor for SystemCommandAction
*
* @param title the title of the action * @param title the title of the action
* @param tooltip the tooltip for the action * @param tooltip the tooltip for the action
* @param parent * @param parent Shell of parent window. Can be null if you don't know it,
* @param isShell indication of whether this action launches a shell or runs a command * but call setShell when you do.
* @param isShell indication of whether this action launches a shell or runs
* a command
* @param cmdSubSystem the command subsystem to use if launching a shell * @param cmdSubSystem the command subsystem to use if launching a shell
*/ */
public SystemCommandAction(String title, String tooltip, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) public SystemCommandAction(String title, String tooltip, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem)
{ {
this( this(
@ -389,13 +420,16 @@ public class SystemCommandAction extends SystemBaseAction
/** /**
* Constructor for SystemCommandAction * Constructor for SystemCommandAction
*
* @param title the title of the action * @param title the title of the action
* @param tooltip the tooltip for the action * @param tooltip the tooltip for the action
* @param descriptor the image descriptor for the action * @param descriptor the image descriptor for the action
* @param parent * @param parent Shell of parent window. Can be null if you don't know it,
* @param isShell indication of whether this action launches a shell or runs a command * but call setShell when you do.
* @param isShell indication of whether this action launches a shell or runs
* a command
* @param cmdSubSystem the command subsystem to use if launching a shell * @param cmdSubSystem the command subsystem to use if launching a shell
*/ */
public SystemCommandAction(String title, String tooltip, ImageDescriptor descriptor, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) public SystemCommandAction(String title, String tooltip, ImageDescriptor descriptor, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem)
{ {
super(title, tooltip, descriptor, parent); super(title, tooltip, descriptor, parent);
@ -411,7 +445,7 @@ public class SystemCommandAction extends SystemBaseAction
{ {
_cmdSubSystem = ss; _cmdSubSystem = ss;
} }
/** /**
* Runs the command action. If the action is for launching a shell, the shell is launched * Runs the command action. If the action is for launching a shell, the shell is launched
* and the remote shell view shows it's output. If the action is for running a command, a * and the remote shell view shows it's output. If the action is for running a command, a
@ -452,11 +486,11 @@ public class SystemCommandAction extends SystemBaseAction
} }
} }
} }
IRemoteFile selectedFile = _selected; IRemoteFile selectedFile = _selected;
if (_selected == null) if (_selected == null)
{ {
return _cmdSubSystem; return _cmdSubSystem;
} }
IHost sysConn = selectedFile.getSystemConnection(); IHost sysConn = selectedFile.getSystemConnection();
@ -491,7 +525,7 @@ public class SystemCommandAction extends SystemBaseAction
try try
{ {
//Shell shell = getShell(); //Shell shell = getShell();
if (_selectedFilterRef != null) if (_selectedFilterRef != null)
{ {
ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_selectedFilterRef).getAdapter(ISystemViewElementAdapter.class); ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_selectedFilterRef).getAdapter(ISystemViewElementAdapter.class);
@ -508,7 +542,7 @@ public class SystemCommandAction extends SystemBaseAction
} }
} }
} }
IProgressMonitor monitor = new NullProgressMonitor(); IProgressMonitor monitor = new NullProgressMonitor();
if (_selected != null) if (_selected != null)
{ {
@ -595,7 +629,7 @@ public class SystemCommandAction extends SystemBaseAction
{ {
SystemCommandsUI commandsUI = SystemCommandsUI.getInstance(); SystemCommandsUI commandsUI = SystemCommandsUI.getInstance();
SystemCommandsViewPart cmdsPart = commandsUI.activateCommandsView(); SystemCommandsViewPart cmdsPart = commandsUI.activateCommandsView();
RunShellJob job = new RunShellJob(cmdSubSystem, cmdsPart); RunShellJob job = new RunShellJob(cmdSubSystem, cmdsPart);
job.schedule(); job.schedule();
} }
@ -608,16 +642,20 @@ public class SystemCommandAction extends SystemBaseAction
} }
} }
private boolean connect(SubSystem ss, IProgressMonitor monitor) throws Exception private boolean connect(SubSystem ss, IProgressMonitor monitor) throws Exception
{ {
if (!ss.isConnected()) if (!ss.isConnected())
{ {
Display dis = Display.getDefault(); Display dis = Display.getDefault();
dis.syncExec(new PromptForPassword(ss)); PromptForPassword passPrompt = new PromptForPassword(ss);
ss.getConnectorService().connect(monitor); dis.syncExec(passPrompt);
dis.asyncExec(new UpdateRegistry(ss)); if(!passPrompt.isConnectionCancelled()){
ss.getConnectorService().connect(monitor);
dis.asyncExec(new UpdateRegistry(ss));
}else
throw new OperationCanceledException();
} }
return true; return true;
} }
@ -636,7 +674,7 @@ public class SystemCommandAction extends SystemBaseAction
* Called when the selection changes in the systems view. This determines * Called when the selection changes in the systems view. This determines
* the input object for the command and whether to enable or disable * the input object for the command and whether to enable or disable
* the action. * the action.
* *
* @param selection the current seleciton * @param selection the current seleciton
* @return whether to enable or disable the action * @return whether to enable or disable the action
*/ */
@ -686,7 +724,7 @@ public class SystemCommandAction extends SystemBaseAction
if (_cmdSubSystem != cmdSubSystem) if (_cmdSubSystem != cmdSubSystem)
{ {
_cmdSubSystem = cmdSubSystem; _cmdSubSystem = cmdSubSystem;
enable = _cmdSubSystem.canRunCommand(); enable = _cmdSubSystem.canRunCommand();
} }
} }
else if (_cmdSubSystem != null) else if (_cmdSubSystem != null)