From f30488127271a3b72b1a55b89fd6d1504aa41fb3 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Fri, 19 Dec 2008 14:12:06 +0000 Subject: [PATCH] [259367][telnet][api] Allow the ITelnetSessionProvider to configure Telnet options before logging in --- .../META-INF/MANIFEST.MF | 4 +- .../telnet/TelnetConnectorService.java | 54 +++++++++---------- .../telnet/ITelnetSessionProvider.java | 51 +++++++++++++----- .../telnet/terminal/TelnetTerminalShell.java | 2 +- 4 files changed, 69 insertions(+), 42 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.connectorservice.telnet/META-INF/MANIFEST.MF index 89a62a47663..ff9bd350731 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.telnet/META-INF/MANIFEST.MF +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/META-INF/MANIFEST.MF @@ -2,11 +2,11 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.rse.connectorservice.telnet;singleton:=true -Bundle-Version: 1.1.0.qualifier +Bundle-Version: 1.2.0.qualifier Bundle-Activator: org.eclipse.rse.internal.connectorservice.telnet.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime, - org.eclipse.rse.services.telnet;bundle-version="[1.1.0,2.0.0)", + org.eclipse.rse.services.telnet;bundle-version="[1.2.0,2.0.0)", org.eclipse.rse.services;bundle-version="[3.0.0,4.0.0)", org.eclipse.rse.core;bundle-version="[3.0.0,4.0.0)", org.eclipse.rse.ui;bundle-version="[3.0.0,4.0.0)", diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java index ee49e03728e..fa175bf8442 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. - * All rights reserved. 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 available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: + * All rights reserved. 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 available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: * Martin Oberhuber (Wind River) - initial API and implementation * David Dykstal (IBM) - [168977] refactoring IConnectorService and ServerLauncher hierarchies * Sheldon D'souza (Celunite) - adapted from SshConnectorService @@ -13,7 +13,7 @@ * Martin Oberhuber (Wind River) - [178606] fix endless loop in readUntil() * Sheldon D'souza (Celunite) - [186536] login and password should be configurable * Sheldon D'souza (Celunite) - [186570] handle invalid user id and password more gracefully - * Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect() + * Martin Oberhuber (Wind River) - [187218] Fix error reporting for connect() * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells * Sheldon D'souza (Celunite) - [194464] fix create multiple telnet shells quickly * Martin Oberhuber (Wind River) - [186761] make the port setting configurable @@ -94,7 +94,7 @@ public class TelnetConnectorService extends StandardConnectorService implements * Return the telnet property set, and fill it with default values if it has * not been created yet. Extenders may override in order to set different * default values. - * + * * @return a property set holding properties understood by the telnet * connector service. */ @@ -106,9 +106,9 @@ public class TelnetConnectorService extends StandardConnectorService implements telnetSet.addProperty(PROPERTY_LOGIN_REQUIRED, "true", PropertyType.getEnumPropertyType(new String[] { "true", "false" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ telnetSet.addProperty(PROPERTY_LOGIN_PROMPT, - "ogin: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ + "ogin: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ telnetSet.addProperty(PROPERTY_PASSWORD_PROMPT, - "assword: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ + "assword: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$ telnetSet.addProperty(PROPERTY_COMMAND_PROMPT, "$", PropertyType.getStringPropertyType()); //$NON-NLS-1$ } @@ -151,10 +151,10 @@ public class TelnetConnectorService extends StandardConnectorService implements public TelnetClient makeNewTelnetClient(IProgressMonitor monitor ) throws Exception { TelnetClient client = new TelnetClient(); - return makeNewTelnetClient(client, monitor); + return loginTelnetClient(client, monitor); } - - public TelnetClient makeNewTelnetClient(TelnetClient client, IProgressMonitor monitor ) throws Exception { + + public TelnetClient loginTelnetClient(TelnetClient client, IProgressMonitor monitor) throws SystemMessageException { String host = getHostName(); String user = getUserId(); String password = ""; //$NON-NLS-1$ @@ -213,14 +213,14 @@ public class TelnetConnectorService extends StandardConnectorService implements //from the remote side with the SystemMessageException for user diagnostics SystemMessage msg; if (nestedException!=null) { - msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + msg = new SimpleSystemMessage(Activator.PLUGIN_ID, ICommonMessageIds.MSG_EXCEPTION_OCCURRED, - IStatus.ERROR, + IStatus.ERROR, CommonMessages.MSG_EXCEPTION_OCCURRED, nestedException); } else { - msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + msg = new SimpleSystemMessage(Activator.PLUGIN_ID, ICommonMessageIds.MSG_COMM_AUTH_FAILED, - IStatus.ERROR, + IStatus.ERROR, CommonMessages.MSG_COMM_AUTH_FAILED, NLS.bind(CommonMessages.MSG_COMM_AUTH_FAILED_DETAILS, getHost().getAliasName())); @@ -326,7 +326,7 @@ public class TelnetConnectorService extends StandardConnectorService implements * Handle session-lost events. This is generic for any sort of connector * service. Most of this is extracted from dstore's * ConnectionStatusListener. - * + * * TODO should be refactored to make it generally available, and allow * dstore to derive from it. */ @@ -371,11 +371,11 @@ public class TelnetConnectorService extends StandardConnectorService implements // TODO allow users to reconnect from this dialog // SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_UNKNOWNHOST); - SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, ICommonMessageIds.MSG_CONNECT_CANCELLED, - IStatus.CANCEL, + IStatus.CANCEL, NLS.bind(CommonMessages.MSG_CONNECT_CANCELLED, _connection.getHost().getAliasName())); - + SystemMessageDialog dialog = new SystemMessageDialog(getShell(), msg); dialog.open(); try { @@ -489,11 +489,11 @@ public class TelnetConnectorService extends StandardConnectorService implements */ protected void showDisconnectErrorMessage(Shell shell, String hostName, int port, Exception exc) { - SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, ICommonMessageIds.MSG_DISCONNECT_FAILED, IStatus.ERROR, NLS.bind(CommonMessages.MSG_DISCONNECT_FAILED, hostName), exc); - + SystemMessageDialog msgDlg = new SystemMessageDialog(shell,msg); msgDlg.setException(exc); msgDlg.open(); @@ -505,7 +505,7 @@ public class TelnetConnectorService extends StandardConnectorService implements */ protected void showDisconnectCancelledMessage(Shell shell, String hostName, int port) { - SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, + SystemMessage msg = new SimpleSystemMessage(Activator.PLUGIN_ID, ICommonMessageIds.MSG_DISCONNECT_CANCELLED, IStatus.CANCEL, NLS.bind(CommonMessages.MSG_DISCONNECT_CANCELLED, hostName)); @@ -602,7 +602,7 @@ public class TelnetConnectorService extends StandardConnectorService implements * Test if this connector service requires a password. Telnet connector * service returns false since a password is not necessarily required, i.e. * the corresponding password field may be empty. - * + * * @see org.eclipse.rse.core.subsystems.AbstractConnectorService#requiresPassword() * @return false */ @@ -614,7 +614,7 @@ public class TelnetConnectorService extends StandardConnectorService implements * Test if this connector service requires a user id. Telnet connector * service returns false since a user id is not necessarily required, i.e. * the corresponding user id field may be empty. - * + * * @see org.eclipse.rse.core.subsystems.AbstractConnectorService#requiresPassword() * @return false */ @@ -624,7 +624,7 @@ public class TelnetConnectorService extends StandardConnectorService implements /** * Test if this connector service requires logging in. - * + * * @return false if the Property {@link #PROPERTY_LOGIN_REQUIRED} is set and * false. Returns true otherwise. */ diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java index c22e327d49b..f32eae62da7 100644 --- a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 IBM Corporation and others. * All rights reserved. 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 available at @@ -7,10 +7,10 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: * Sheldon D'souza (Celunite) - adapted from ISshSessionProvider * Sheldon D'souza (Celunite) - [187301] support multiple telnet shells @@ -20,24 +20,51 @@ package org.eclipse.rse.internal.services.telnet; import org.apache.commons.net.telnet.TelnetClient; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public interface ITelnetSessionProvider { - + /** - * Create a new Commons.Net TelnetClient. + * Create a new Commons.Net TelnetClient, and authenticate it with the + * remote. + * * @param monitor progress monitor - * @return a new Commons.Net TelnetClient for the given connection, already authenticated + * @return a new Commons.Net TelnetClient for the given connection, already + * authenticated * @throws Exception in case of any error */ public TelnetClient makeNewTelnetClient(IProgressMonitor monitor) throws Exception ; /** - * Initialize a new Commons.Net TelnetClient with a given ptyType. + * Authenticate an existing Commons.Net TelnetClient connection with the + * remote, using the credentials known to RSE. Depending on configuration + * options, this may answer the remote "login:" and "password:" prompts to + * come up with an authenticated client. + * + * By passing in a pre-existing TelnetClient instance, this method allows + * for fine-tuning the TelnetClient options such as ECHO handling through + * the Commons.Net APIs before using RSE to authenticate the client. + * + * Example: + * + *
+ * TelnetClient client = new TelnetClient("vt100"); + * client.addOptionHandler(new EchoOptionHandler(false, true, true, true)); + * client = fSessionProvider.loginTelnetClient(client, new NullProgressMonitor()); + *+ * * @param client telnet client already created * @param monitor progress monitor - * @return authenticated client for the given connection - * @throws Exception in case of any error + * @return authenticated client for the given connection, or + *
null
in case the user cancelled the login through
+ * the progress monitor. The passed-in client is disconnected in
+ * this case.
+ * @throws SystemMessageException in case of an error while authenticating
+ * (such as timeout, communications error, or failure matching
+ * expected prompt). The passed-in TelnetClient remains
+ * connected in this case.
+ * @since 1.2
*/
- public TelnetClient makeNewTelnetClient(TelnetClient client, IProgressMonitor monitor) throws Exception ;
-
+ public TelnetClient loginTelnetClient(TelnetClient client, IProgressMonitor monitor) throws SystemMessageException;
+
}
diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/terminal/TelnetTerminalShell.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/terminal/TelnetTerminalShell.java
index e74508b9404..422a38d8251 100644
--- a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/terminal/TelnetTerminalShell.java
+++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/terminal/TelnetTerminalShell.java
@@ -99,7 +99,7 @@ public class TelnetTerminalShell extends AbstractTerminalShell {
true, true, true));
fTelnetClient.addOptionHandler(new TerminalTypeOptionHandler(
ptyType, true, true, true, true));
- fTelnetClient = fSessionProvider.makeNewTelnetClient(fTelnetClient,
+ fTelnetClient = fSessionProvider.loginTelnetClient(fTelnetClient,
new NullProgressMonitor());
fOutputStream = fTelnetClient.getOutputStream();
if (onUNIX)