mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
[186570] handle invalid user id and password more gracefully
This commit is contained in:
parent
3a06d112fd
commit
ac33b43623
8 changed files with 132 additions and 34 deletions
|
@ -11,6 +11,8 @@
|
||||||
bin.includes = .,\
|
bin.includes = .,\
|
||||||
META-INF/,\
|
META-INF/,\
|
||||||
about.html,\
|
about.html,\
|
||||||
|
icons/,\
|
||||||
plugin.properties
|
plugin.properties
|
||||||
source.. = src/
|
source.. = src/
|
||||||
output.. = bin/
|
output.. = bin/
|
||||||
|
src.includes = about.html
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 230 B |
Binary file not shown.
After Width: | Height: | Size: 246 B |
|
@ -15,3 +15,6 @@
|
||||||
|
|
||||||
pluginName = RSE Telnet Connector Service
|
pluginName = RSE Telnet Connector Service
|
||||||
providerName = Eclipse.org
|
providerName = Eclipse.org
|
||||||
|
|
||||||
|
TelnetSystemLabel = Telnet Only
|
||||||
|
TelnetSystemDescription = Connection for Telnet access to remote systems
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (c) 2006, 2007 Celunite 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:
|
||||||
|
* Sheldon D'souza (Celunite) - initial API and implementation
|
||||||
|
-->
|
||||||
|
<?eclipse version="3.1"?>
|
||||||
|
<plugin>
|
||||||
|
<extension point="org.eclipse.rse.core.systemTypes">
|
||||||
|
<systemType
|
||||||
|
description="%TelnetSystemDescription"
|
||||||
|
label="%TelnetSystemLabel"
|
||||||
|
icon="icons/full/obj16/systemcommands_obj.gif"
|
||||||
|
iconLive="icons/full/obj16/systemcommandslive_obj.gif"
|
||||||
|
id="org.eclipse.rse.systemtype.telnet"
|
||||||
|
name="Telnet Only"/>
|
||||||
|
</extension>
|
||||||
|
</plugin>
|
|
@ -16,6 +16,7 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
|
@ -45,6 +46,17 @@ public class Activator extends AbstractUIPlugin {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an image descriptor for the image file at the given
|
||||||
|
* plug-in relative path.
|
||||||
|
*
|
||||||
|
* @param path the path
|
||||||
|
* @return the image descriptor
|
||||||
|
*/
|
||||||
|
public static ImageDescriptor getImageDescriptor(String path) {
|
||||||
|
return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||||
|
|
|
@ -25,8 +25,10 @@ public class TelnetConnectorResources extends NLS {
|
||||||
|
|
||||||
public static String TelnetConnectorService_Name;
|
public static String TelnetConnectorService_Name;
|
||||||
public static String TelnetConnectorService_Description;
|
public static String TelnetConnectorService_Description;
|
||||||
|
|
||||||
public static String PropertySet_Description;
|
//Telnet property set
|
||||||
|
|
||||||
|
public static String PropertySet_Description;
|
||||||
|
|
||||||
public static String TelnetConnectorService_ErrorDisconnecting;
|
public static String TelnetConnectorService_ErrorDisconnecting;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
* Martin Oberhuber (Wind River) - apply refactorings for StandardConnectorService
|
* Martin Oberhuber (Wind River) - apply refactorings for StandardConnectorService
|
||||||
* Martin Oberhuber (Wind River) - [178606] fix endless loop in readUntil()
|
* 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) - [186536] login and password should be configurable
|
||||||
|
* Sheldon D'souza (Celunite) - [186570] handle invalid user id and password more gracefully
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.rse.internal.connectorservice.telnet;
|
package org.eclipse.rse.internal.connectorservice.telnet;
|
||||||
|
|
||||||
|
@ -32,12 +33,13 @@ import org.eclipse.rse.core.model.IHost;
|
||||||
import org.eclipse.rse.core.model.IPropertySet;
|
import org.eclipse.rse.core.model.IPropertySet;
|
||||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||||
import org.eclipse.rse.core.model.PropertyType;
|
import org.eclipse.rse.core.model.PropertyType;
|
||||||
|
import org.eclipse.rse.core.model.SystemSignonInformation;
|
||||||
import org.eclipse.rse.core.subsystems.CommunicationsEvent;
|
import org.eclipse.rse.core.subsystems.CommunicationsEvent;
|
||||||
import org.eclipse.rse.core.subsystems.IConnectorService;
|
import org.eclipse.rse.core.subsystems.IConnectorService;
|
||||||
import org.eclipse.rse.core.subsystems.ICredentials;
|
|
||||||
import org.eclipse.rse.core.subsystems.SubSystemConfiguration;
|
import org.eclipse.rse.core.subsystems.SubSystemConfiguration;
|
||||||
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
|
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
|
||||||
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
||||||
|
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
|
||||||
import org.eclipse.rse.ui.ISystemMessages;
|
import org.eclipse.rse.ui.ISystemMessages;
|
||||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||||
import org.eclipse.rse.ui.SystemBasePlugin;
|
import org.eclipse.rse.ui.SystemBasePlugin;
|
||||||
|
@ -58,11 +60,14 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
public static final String PROPERTY_COMMAND_PROMPT = "Command.Prompt"; //$NON-NLS-1$
|
public static final String PROPERTY_COMMAND_PROMPT = "Command.Prompt"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final int TELNET_DEFAULT_PORT = 23;
|
private static final int TELNET_DEFAULT_PORT = 23;
|
||||||
private static TelnetClient fTelnetClient = new TelnetClient();
|
private TelnetClient fTelnetClient = new TelnetClient();
|
||||||
private SessionLostHandler fSessionLostHandler;
|
private SessionLostHandler fSessionLostHandler;
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private PrintStream out;
|
private PrintStream out;
|
||||||
private IPropertySet telnetPropertySet = null;
|
private IPropertySet telnetPropertySet = null;
|
||||||
|
private static final int ERROR_CODE = 100; // filed error code
|
||||||
|
private static final int SUCCESS_CODE = 150; // login pass code
|
||||||
|
private static final int CONNECT_CLOSED = 200; // code for end of login attempts
|
||||||
|
|
||||||
public TelnetConnectorService(IHost host) {
|
public TelnetConnectorService(IHost host) {
|
||||||
super(TelnetConnectorResources.TelnetConnectorService_Name,
|
super(TelnetConnectorResources.TelnetConnectorService_Name,
|
||||||
|
@ -86,7 +91,7 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
telnetSet = createPropertySet(PROPERTY_SET_NAME,
|
telnetSet = createPropertySet(PROPERTY_SET_NAME,
|
||||||
TelnetConnectorResources.PropertySet_Description);
|
TelnetConnectorResources.PropertySet_Description);
|
||||||
telnetSet.addProperty(PROPERTY_LOGIN_REQUIRED,
|
telnetSet.addProperty(PROPERTY_LOGIN_REQUIRED,
|
||||||
"true", PropertyType.getEnumPropertyType(new String[] { "true", "false" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
"true", PropertyType.getEnumPropertyType(new String[] { "true", "false" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
telnetSet.addProperty(PROPERTY_LOGIN_PROMPT,
|
telnetSet.addProperty(PROPERTY_LOGIN_PROMPT,
|
||||||
"ogin: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$
|
"ogin: ", PropertyType.getStringPropertyType()); //$NON-NLS-1$
|
||||||
telnetSet.addProperty(PROPERTY_PASSWORD_PROMPT,
|
telnetSet.addProperty(PROPERTY_PASSWORD_PROMPT,
|
||||||
|
@ -106,39 +111,31 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
String host = getHostName();
|
String host = getHostName();
|
||||||
String user = getUserId();
|
String user = getUserId();
|
||||||
String password = ""; //$NON-NLS-1$
|
String password = ""; //$NON-NLS-1$
|
||||||
telnetPropertySet = getTelnetPropertySet();
|
|
||||||
String login_required = telnetPropertySet
|
|
||||||
.getPropertyValue(PROPERTY_LOGIN_REQUIRED);
|
|
||||||
String login_prompt = telnetPropertySet
|
|
||||||
.getPropertyValue(PROPERTY_LOGIN_PROMPT);
|
|
||||||
String password_prompt = telnetPropertySet
|
|
||||||
.getPropertyValue(PROPERTY_PASSWORD_PROMPT);
|
|
||||||
String command_prompt = telnetPropertySet
|
|
||||||
.getPropertyValue(PROPERTY_COMMAND_PROMPT);
|
|
||||||
try {
|
try {
|
||||||
Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
|
Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
|
||||||
fTelnetClient.connect(host, TELNET_DEFAULT_PORT);
|
fTelnetClient.connect(host, TELNET_DEFAULT_PORT);
|
||||||
ICredentials cred = getCredentialsProvider().getCredentials();
|
SystemSignonInformation ssi = getSignonInformation();
|
||||||
if (cred != null) {
|
if (ssi != null) {
|
||||||
password = cred.getPassword();
|
password = ssi.getPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
in = fTelnetClient.getInputStream();
|
in = fTelnetClient.getInputStream();
|
||||||
out = new PrintStream(fTelnetClient.getOutputStream());
|
out = new PrintStream(fTelnetClient.getOutputStream());
|
||||||
// Send login and password if needed
|
|
||||||
if (Boolean.valueOf(login_required).booleanValue()) {
|
LoginThread checkLogin = new LoginThread(user, password);
|
||||||
if (login_prompt != null && login_prompt.length() > 0) {
|
checkLogin.start();
|
||||||
readUntil(login_prompt);
|
checkLogin.join();
|
||||||
write(user);
|
int status = checkLogin.getLoginStatus();
|
||||||
}
|
if (status != SUCCESS_CODE) {
|
||||||
if (password_prompt != null && password_prompt.length() > 0) {
|
SystemMessage msg = RSEUIPlugin
|
||||||
readUntil(password_prompt);
|
.getPluginMessage(ISystemMessages.MSG_COMM_CONNECT_FAILED);
|
||||||
write(password);
|
msg.makeSubstitution(getHost().getAliasName());
|
||||||
}
|
internalDisconnect(null);
|
||||||
}
|
throw new SystemMessageException(msg);
|
||||||
if (command_prompt != null && command_prompt.length() > 0) {
|
|
||||||
readUntil(command_prompt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
|
Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
|
||||||
} catch (SocketException se) {
|
} catch (SocketException se) {
|
||||||
Activator.trace("Telnet Service failed: " + se.toString()); //$NON-NLS-1$
|
Activator.trace("Telnet Service failed: " + se.toString()); //$NON-NLS-1$
|
||||||
|
@ -174,19 +171,25 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readUntil(String pattern) {
|
public int readUntil(String pattern) {
|
||||||
try {
|
try {
|
||||||
char lastChar = pattern.charAt(pattern.length() - 1);
|
char lastChar = pattern.charAt(pattern.length() - 1);
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
int ch = (char) in.read();
|
int ch = in.read();
|
||||||
while (ch >= 0) {
|
while (ch >= 0) {
|
||||||
char tch = (char) ch;
|
char tch = (char) ch;
|
||||||
if (Activator.isTracingOn())
|
if (Activator.isTracingOn())
|
||||||
System.out.print(tch);
|
System.out.print(tch);
|
||||||
sb.append(tch);
|
sb.append(tch);
|
||||||
|
if (tch=='t' && sb.indexOf("incorrect") >= 0) { //$NON-NLS-1$
|
||||||
|
return ERROR_CODE;
|
||||||
|
}
|
||||||
|
if (tch=='d' && sb.indexOf("closed") >= 0) { //$NON-NLS-1$
|
||||||
|
return CONNECT_CLOSED;
|
||||||
|
}
|
||||||
if (tch == lastChar) {
|
if (tch == lastChar) {
|
||||||
if (sb.toString().endsWith(pattern)) {
|
if (sb.toString().endsWith(pattern)) {
|
||||||
return sb.toString();
|
return SUCCESS_CODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ch = in.read();
|
ch = in.read();
|
||||||
|
@ -194,7 +197,7 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SystemBasePlugin.logError(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), e);
|
SystemBasePlugin.logError(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return CONNECT_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(String value) {
|
public void write(String value) {
|
||||||
|
@ -216,6 +219,7 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$
|
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$
|
||||||
|
|
||||||
boolean sessionLost = (fSessionLostHandler != null && fSessionLostHandler.isSessionLost());
|
boolean sessionLost = (fSessionLostHandler != null && fSessionLostHandler.isSessionLost());
|
||||||
// no more interested in handling session-lost, since we are
|
// no more interested in handling session-lost, since we are
|
||||||
// disconnecting anyway
|
// disconnecting anyway
|
||||||
|
@ -429,6 +433,58 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A Login Thread to catch errors during login into telnet session
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class LoginThread extends Thread {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private int status = SUCCESS_CODE;
|
||||||
|
|
||||||
|
public LoginThread(String username, String password) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
telnetPropertySet = getTelnetPropertySet();
|
||||||
|
String login_required = telnetPropertySet
|
||||||
|
.getPropertyValue(PROPERTY_LOGIN_REQUIRED);
|
||||||
|
String login_prompt = telnetPropertySet
|
||||||
|
.getPropertyValue(PROPERTY_LOGIN_PROMPT);
|
||||||
|
String password_prompt = telnetPropertySet
|
||||||
|
.getPropertyValue(PROPERTY_PASSWORD_PROMPT);
|
||||||
|
String command_prompt = telnetPropertySet
|
||||||
|
.getPropertyValue(PROPERTY_COMMAND_PROMPT);
|
||||||
|
|
||||||
|
if (Boolean.valueOf(login_required).booleanValue()) {
|
||||||
|
status = SUCCESS_CODE;
|
||||||
|
if (login_prompt != null && login_prompt.length() > 0) {
|
||||||
|
status = readUntil(login_prompt);
|
||||||
|
write(username);
|
||||||
|
}
|
||||||
|
if (status == SUCCESS_CODE && password_prompt != null && password_prompt.length() > 0) {
|
||||||
|
status = readUntil(password_prompt);
|
||||||
|
write(password);
|
||||||
|
}
|
||||||
|
if (status == SUCCESS_CODE && command_prompt != null && command_prompt.length() > 0) {
|
||||||
|
status = readUntil(command_prompt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (command_prompt != null && command_prompt.length() > 0) {
|
||||||
|
status = readUntil(command_prompt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLoginStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notification from sub-services that our session was lost. Notify all
|
* Notification from sub-services that our session was lost. Notify all
|
||||||
* subsystems properly.
|
* subsystems properly.
|
||||||
|
|
Loading…
Add table
Reference in a new issue