Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te')
-rw-r--r--terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/activator/UIPlugin.java111
-rw-r--r--terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java425
-rw-r--r--terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java181
-rw-r--r--terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshMementoHandler.java133
-rw-r--r--terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.java37
-rw-r--r--terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.properties14
6 files changed, 901 insertions, 0 deletions
diff --git a/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/activator/UIPlugin.java b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/activator/UIPlugin.java
new file mode 100644
index 000000000..8349dae57
--- /dev/null
+++ b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/activator/UIPlugin.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2015 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.ssh.activator;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tcf.te.core.terminals.tracing.TraceHandler;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class UIPlugin extends AbstractUIPlugin {
+ // The shared instance
+ private static UIPlugin plugin;
+ // The trace handler instance
+ private static volatile TraceHandler traceHandler;
+
+ /**
+ * The constructor
+ */
+ public UIPlugin() {
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static UIPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Convenience method which returns the unique identifier of this plugin.
+ */
+ public static String getUniqueIdentifier() {
+ if (getDefault() != null && getDefault().getBundle() != null) {
+ return getDefault().getBundle().getSymbolicName();
+ }
+ return "org.eclipse.tcf.te.ui.terminals.ssh"; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the bundles trace handler.
+ *
+ * @return The bundles trace handler.
+ */
+ public static TraceHandler getTraceHandler() {
+ if (traceHandler == null) {
+ traceHandler = new TraceHandler(getUniqueIdentifier());
+ }
+ return traceHandler;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
+ */
+ @Override
+ protected void initializeImageRegistry(ImageRegistry registry) {
+ }
+
+ /**
+ * Loads the image registered under the specified key from the image
+ * registry and returns the <code>Image</code> object instance.
+ *
+ * @param key The key the image is registered with.
+ * @return The <code>Image</code> object instance or <code>null</code>.
+ */
+ public static Image getImage(String key) {
+ return getDefault().getImageRegistry().get(key);
+ }
+
+ /**
+ * Loads the image registered under the specified key from the image
+ * registry and returns the <code>ImageDescriptor</code> object instance.
+ *
+ * @param key The key the image is registered with.
+ * @return The <code>ImageDescriptor</code> object instance or <code>null</code>.
+ */
+ public static ImageDescriptor getImageDescriptor(String key) {
+ return getDefault().getImageRegistry().getDescriptor(key);
+ }
+}
diff --git a/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java
new file mode 100644
index 000000000..36f238e4d
--- /dev/null
+++ b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/controls/SshWizardConfigurationPanel.java
@@ -0,0 +1,425 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2015 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.ssh.controls;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.tcf.te.core.terminals.TerminalContextPropertiesProviderFactory;
+import org.eclipse.tcf.te.core.terminals.interfaces.ITerminalContextPropertiesProvider;
+import org.eclipse.tcf.te.core.terminals.interfaces.constants.IContextPropertiesConstants;
+import org.eclipse.tcf.te.core.terminals.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanelContainer;
+import org.eclipse.tcf.te.ui.terminals.panels.AbstractExtendedConfigurationPanel;
+import org.eclipse.tcf.te.ui.terminals.ssh.nls.Messages;
+import org.eclipse.tm.internal.terminal.provisional.api.AbstractSettingsPage;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
+import org.eclipse.tm.internal.terminal.ssh.SshConnector;
+import org.eclipse.tm.internal.terminal.ssh.SshSettings;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * SSH wizard configuration panel implementation.
+ */
+@SuppressWarnings("restriction")
+public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPanel {
+
+ private static final String SAVE_USER = "saveUser"; //$NON-NLS-1$
+ private static final String SAVE_PASSWORD = "savePassword"; //$NON-NLS-1$
+
+ private SshSettings sshSettings;
+ private ISettingsPage sshSettingsPage;
+ private Button userButton;
+ private Button passwordButton;
+
+ /**
+ * Constructor.
+ *
+ * @param container The configuration panel container or <code>null</code>.
+ */
+ public SshWizardConfigurationPanel(IConfigurationPanelContainer container) {
+ super(container);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
+ */
+ @Override
+ public void setupPanel(Composite parent, FormToolkit toolkit) {
+ Composite panel = new Composite(parent, SWT.NONE);
+ panel.setLayout(new GridLayout());
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ panel.setLayoutData(data);
+
+ // Create the host selection combo
+ if (isWithoutSelection()) createHostsUI(panel, true);
+
+ SshConnector conn = new SshConnector();
+ sshSettings = (SshSettings) conn.getSshSettings();
+ sshSettings.setHost(getSelectionHost());
+ sshSettings.setUser(getDefaultUser());
+
+ sshSettingsPage = conn.makeSettingsPage();
+ if (sshSettingsPage instanceof AbstractSettingsPage) {
+ ((AbstractSettingsPage)sshSettingsPage).setHasControlDecoration(true);
+ }
+ sshSettingsPage.createControl(panel);
+
+ // Add the listener to the settings page
+ sshSettingsPage.addListener(new ISettingsPage.Listener() {
+ @Override
+ public void onSettingsPageChanged(Control control) {
+ if (getContainer() != null) getContainer().validate();
+ }
+ });
+
+ // Create the encoding selection combo
+ createEncodingUI(panel, true);
+
+ // if user and password for host should be saved or not
+ createSaveButtonsUI(panel, true);
+
+ setControl(panel);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#setupData(java.util.Map)
+ */
+ @Override
+ public void setupData(Map<String, Object> data) {
+ if (data == null || sshSettings == null || sshSettingsPage == null) return;
+
+ String value = (String)data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
+ if (value != null) sshSettings.setHost(value);
+
+ Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT);
+ value = v != null ? v.toString() : null;
+ if (value != null) sshSettings.setPort(value);
+
+ v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
+ value = v != null ? v.toString() : null;
+ if (value != null) sshSettings.setTimeout(value);
+
+ v = data.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
+ value = v != null ? v.toString() : null;
+ if (value != null) sshSettings.setKeepalive(value);
+
+ value = (String)data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
+ if (value != null) sshSettings.setPassword(value);
+
+ value = (String)data.get(ITerminalsConnectorConstants.PROP_SSH_USER);
+ if (value != null) sshSettings.setUser(value);
+
+ value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING);
+ if (value != null) setEncoding(value);
+
+ sshSettingsPage.loadSettings();
+ }
+
+ /**
+ * Returns the default user name.
+ *
+ * @return The default user name.
+ */
+ private String getDefaultUser() {
+ ISelection selection = getSelection();
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Object element = ((IStructuredSelection) selection).getFirstElement();
+ ITerminalContextPropertiesProvider provider = TerminalContextPropertiesProviderFactory.getProvider(element);
+ if (provider != null) {
+ Object user = provider.getProperty(element, IContextPropertiesConstants.PROP_DEFAULT_USER);
+ if (user instanceof String) return ((String) user).trim();
+ }
+ }
+
+ return System.getProperty("user.name"); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#extractData(java.util.Map)
+ */
+ @Override
+ public void extractData(Map<String, Object> data) {
+ if (data == null) return;
+
+ // set the terminal connector id for ssh
+ data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.internal.terminal.ssh.SshConnector"); //$NON-NLS-1$
+
+ sshSettingsPage.saveSettings();
+ data.put(ITerminalsConnectorConstants.PROP_IP_HOST,sshSettings.getHost());
+ data.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.valueOf(sshSettings.getPort()));
+ data.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.valueOf(sshSettings.getTimeout()));
+ data.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.valueOf(sshSettings.getKeepalive()));
+ data.put(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, sshSettings.getPassword());
+ data.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser());
+ data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String)
+ */
+ @Override
+ protected void fillSettingsForHost(String host) {
+ boolean saveUser = true;
+ boolean savePassword = false;
+ if (host != null && host.length() != 0){
+ if (hostSettingsMap.containsKey(host)){
+ Map<String, String> hostSettings = hostSettingsMap.get(host);
+ if (hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) {
+ sshSettings.setHost(hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST));
+ }
+ if (hostSettings.get(ITerminalsConnectorConstants.PROP_IP_PORT) != null) {
+ sshSettings.setPort(hostSettings.get(ITerminalsConnectorConstants.PROP_IP_PORT));
+ }
+ if (hostSettings.get(ITerminalsConnectorConstants.PROP_TIMEOUT) != null) {
+ sshSettings.setTimeout(hostSettings.get(ITerminalsConnectorConstants.PROP_TIMEOUT));
+ }
+ if (hostSettings.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE) != null) {
+ sshSettings.setKeepalive(hostSettings.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE));
+ }
+ if (hostSettings.get(ITerminalsConnectorConstants.PROP_SSH_USER) != null) {
+ sshSettings.setUser(hostSettings.get(ITerminalsConnectorConstants.PROP_SSH_USER));
+ }
+ if (hostSettings.get(SAVE_PASSWORD) != null) {
+ savePassword = new Boolean(hostSettings.get(SAVE_PASSWORD)).booleanValue();
+ }
+ if (!savePassword){
+ sshSettings.setPassword(""); //$NON-NLS-1$
+ } else {
+ String password = accessSecurePassword(sshSettings.getHost());
+ if (password != null) {
+ sshSettings.setPassword(password);
+ }
+ }
+
+ String encoding = hostSettings.get(ITerminalsConnectorConstants.PROP_ENCODING);
+ if (encoding == null || "null".equals(encoding)) { //$NON-NLS-1$
+ String defaultEncoding = getSelectionEncoding();
+ encoding = defaultEncoding != null && !"".equals(defaultEncoding.trim()) ? defaultEncoding.trim() : "ISO-8859-1"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ setEncoding(encoding);
+ } else {
+ sshSettings.setHost(getSelectionHost());
+ sshSettings.setUser(getDefaultUser());
+ saveUser = true;
+ savePassword = false;
+ }
+ // set settings in page
+ sshSettingsPage.loadSettings();
+ userButton.setSelection(saveUser);
+ passwordButton.setSelection(savePassword);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
+ */
+ @Override
+ public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
+ saveSettingsForHost(true);
+ super.doSaveWidgetValues(settings, idPrefix);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean)
+ */
+ @Override
+ protected void saveSettingsForHost(boolean add) {
+ boolean saveUser = userButton.getSelection();
+ boolean savePassword = passwordButton.getSelection();
+ String host = getHostFromSettings();
+ if (host != null && host.length() != 0) {
+ if (hostSettingsMap.containsKey(host)){
+ Map<String, String> hostSettings = hostSettingsMap.get(host);
+ hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());
+ hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(sshSettings.getPort()));
+ hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(sshSettings.getTimeout()));
+ hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.toString(sshSettings.getKeepalive()));
+ if (saveUser) {
+ String defaultUser = getDefaultUser();
+ if (defaultUser == null || !defaultUser.equals(sshSettings.getUser())) {
+ hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser());
+ } else {
+ hostSettings.remove(ITerminalsConnectorConstants.PROP_SSH_USER);
+ }
+ }
+ else {
+ hostSettings.remove(ITerminalsConnectorConstants.PROP_SSH_USER);
+ }
+
+ String encoding = getEncoding();
+ if (encoding != null) {
+ String defaultEncoding = getSelectionEncoding();
+ if (defaultEncoding != null && defaultEncoding.trim().equals(encoding)) {
+ encoding = null;
+ }
+ }
+ hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, encoding);
+ hostSettings.put(SAVE_USER, Boolean.toString(saveUser));
+ hostSettings.put(SAVE_PASSWORD, Boolean.toString(savePassword));
+
+ if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0){
+ saveSecurePassword(host, sshSettings.getPassword());
+ }
+
+ // maybe unchecked the password button - so try to remove a saved password - if any
+ if (!savePassword) removeSecurePassword(host);
+ } else if (add) {
+ Map<String, String> hostSettings = new HashMap<String, String>();
+ hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());
+ hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(sshSettings.getPort()));
+ hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(sshSettings.getTimeout()));
+ hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.toString(sshSettings.getKeepalive()));
+ if (saveUser) {
+ String defaultUser = getDefaultUser();
+ if (defaultUser == null || !defaultUser.equals(sshSettings.getUser())) {
+ hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser());
+ }
+ }
+ hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
+ hostSettings.put(SAVE_USER, Boolean.toString(saveUser));
+ hostSettings.put(SAVE_PASSWORD, Boolean.toString(savePassword));
+ hostSettingsMap.put(host, hostSettings);
+
+ if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0){
+ saveSecurePassword(host, sshSettings.getPassword());
+ }
+ }
+ }
+ }
+
+ /**
+ * Save the password to the secure storage.
+ *
+ * @param host The host. Must not be <code>null</code>.
+ * @param password The password. Must not be <code>null</code>.
+ */
+ private void saveSecurePassword(String host, String password) {
+ Assert.isNotNull(host);
+ Assert.isNotNull(password);
+
+ // To access the secure storage, we need the preference instance
+ ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
+ if (preferences != null) {
+ // Construct the secure preferences node key
+ String nodeKey = "/Target Explorer SSH Password/" + host; //$NON-NLS-1$
+ ISecurePreferences node = preferences.node(nodeKey);
+ if (node != null) {
+ try {
+ node.put("password", password, true); //$NON-NLS-1$
+ }
+ catch (StorageException ex) { /* ignored on purpose */ }
+ }
+ }
+ }
+
+ /**
+ * Reads the password from the secure storage.
+ *
+ * @param host The host. Must not be <code>null</code>.
+ * @return The password or <code>null</code>.
+ */
+ private String accessSecurePassword(String host) {
+ Assert.isNotNull(host);
+
+ // To access the secure storage, we need the preference instance
+ ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
+ if (preferences != null) {
+ // Construct the secure preferences node key
+ String nodeKey = "/Target Explorer SSH Password/" + host; //$NON-NLS-1$
+ ISecurePreferences node = preferences.node(nodeKey);
+ if (node != null) {
+ String password = null;
+ try {
+ password = node.get("password", null); //$NON-NLS-1$
+ }
+ catch (StorageException ex) { /* ignored on purpose */ }
+
+ return password;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#removeSecurePassword(java.lang.String)
+ */
+ @Override
+ protected void removeSecurePassword(String host) {
+ Assert.isNotNull(host);
+
+ // To access the secure storage, we need the preference instance
+ ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
+ if (preferences != null) {
+ // Construct the secure preferences node key
+ String nodeKey = "/Target Explorer SSH Password/" + host; //$NON-NLS-1$
+ ISecurePreferences node = preferences.node(nodeKey);
+ if (node != null) {
+ node.remove("password"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.controls.panels.AbstractWizardConfigurationPanel#isValid()
+ */
+ @Override
+ public boolean isValid(){
+ return isEncodingValid() && sshSettingsPage.validateSettings();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#getHostFromSettings()
+ */
+ @Override
+ protected String getHostFromSettings() {
+ sshSettingsPage.saveSettings();
+ return sshSettings.getHost();
+ }
+
+ private void createSaveButtonsUI(final Composite parent, boolean separator) {
+ Assert.isNotNull(parent);
+
+ if (separator) {
+ Label sep = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
+ sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ }
+
+ Composite panel = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ userButton = new Button(panel, SWT.CHECK);
+ userButton.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false));
+ userButton.setText(Messages.SshWizardConfigurationPanel_saveUser);
+
+ passwordButton = new Button(panel, SWT.CHECK);
+ passwordButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ passwordButton.setText(Messages.SshWizardConfigurationPanel_savePassword);
+ }
+}
diff --git a/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java
new file mode 100644
index 000000000..3fd55ba81
--- /dev/null
+++ b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshLauncherDelegate.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2015 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.ssh.launcher;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.te.core.terminals.TerminalServiceFactory;
+import org.eclipse.tcf.te.core.terminals.interfaces.ITerminalService;
+import org.eclipse.tcf.te.core.terminals.interfaces.ITerminalService.Done;
+import org.eclipse.tcf.te.core.terminals.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanel;
+import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanelContainer;
+import org.eclipse.tcf.te.ui.terminals.interfaces.IMementoHandler;
+import org.eclipse.tcf.te.ui.terminals.internal.SettingsStore;
+import org.eclipse.tcf.te.ui.terminals.launcher.AbstractLauncherDelegate;
+import org.eclipse.tcf.te.ui.terminals.ssh.controls.SshWizardConfigurationPanel;
+import org.eclipse.tcf.te.ui.terminals.ssh.nls.Messages;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
+import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension;
+import org.eclipse.tm.internal.terminal.ssh.SshSettings;
+
+/**
+ * SSH launcher delegate implementation.
+ */
+@SuppressWarnings("restriction")
+public class SshLauncherDelegate extends AbstractLauncherDelegate {
+ // The SSH terminal connection memento handler
+ private final IMementoHandler mementoHandler = new SshMementoHandler();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#needsUserConfiguration()
+ */
+ @Override
+ public boolean needsUserConfiguration() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#getPanel(org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanelContainer)
+ */
+ @Override
+ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
+ return new SshWizardConfigurationPanel(container);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#execute(java.util.Map, org.eclipse.tcf.te.core.terminals.interfaces.ITerminalService.Done)
+ */
+ @Override
+ public void execute(Map<String, Object> properties, Done done) {
+ Assert.isNotNull(properties);
+
+ // Set the terminal tab title
+ String terminalTitle = getTerminalTitle(properties);
+ if (terminalTitle != null) {
+ properties.put(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle);
+ }
+
+ // For SSH terminals, force a new terminal tab each time it is launched,
+ // if not set otherwise from outside
+ if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) {
+ properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE);
+ }
+
+ // SSH terminals do have a disconnect button
+ if (!properties.containsKey(ITerminalsConnectorConstants.PROP_HAS_DISCONNECT_BUTTON)) {
+ properties.put(ITerminalsConnectorConstants.PROP_HAS_DISCONNECT_BUTTON, Boolean.TRUE);
+ }
+
+ // Get the terminal service
+ ITerminalService terminal = TerminalServiceFactory.getService();
+ // If not available, we cannot fulfill this request
+ if (terminal != null) {
+ terminal.openConsole(properties, done);
+ }
+ }
+
+ /**
+ * Returns the terminal title string.
+ * <p>
+ * The default implementation constructs a title like &quot;SSH @ host (Start time) &quot;.
+ *
+ * @return The terminal title string or <code>null</code>.
+ */
+ private String getTerminalTitle(Map<String, Object> properties) {
+ String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
+ String user = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER);
+
+ if (host != null && user!= null) {
+ DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+ String date = format.format(new Date(System.currentTimeMillis()));
+ return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[]{user, host, date});
+ }
+ return Messages.SshLauncherDelegate_terminalTitle_default;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (IMementoHandler.class.equals(adapter)) {
+ return mementoHandler;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map)
+ */
+ @Override
+ public ITerminalConnector createTerminalConnector(Map<String, Object> properties) {
+ Assert.isNotNull(properties);
+
+ // Check for the terminal connector id
+ String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
+ if (connectorId == null) connectorId = "org.eclipse.tm.internal.terminal.ssh.SshConnector"; //$NON-NLS-1$
+
+ // Extract the ssh properties
+ String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
+ Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
+ String port = value != null ? value.toString() : null;
+ value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
+ String timeout = value != null ? value.toString() : null;
+ value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
+ String keepAlive = value != null ? value.toString() : null;
+ String password = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
+ String user = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER);
+
+ int portOffset = 0;
+ if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) {
+ portOffset = ((Integer)properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
+ if (portOffset < 0) portOffset = 0;
+ }
+
+ // The real port to connect to is port + portOffset
+ port = Integer.toString(Integer.decode(port).intValue() + portOffset);
+
+ // Construct the ssh settings store
+ ISettingsStore store = new SettingsStore();
+
+ // Construct the telnet settings
+ SshSettings sshSettings = new SshSettings();
+ sshSettings.setHost(host);
+ sshSettings.setPort(port);
+ sshSettings.setTimeout(timeout);
+ sshSettings.setKeepalive(keepAlive);
+ sshSettings.setPassword(password);
+ sshSettings.setUser(user);
+
+ // And save the settings to the store
+ sshSettings.save(store);
+
+ // MWE TODO make sure this is NOT passed outside as this is plain text
+ store.put("Password", password); //$NON-NLS-1$
+
+ // Construct the terminal connector instance
+ ITerminalConnector connector = TerminalConnectorExtension.makeTerminalConnector(connectorId);
+ if (connector != null) {
+ // Apply default settings
+ connector.makeSettingsPage();
+ // And load the real settings
+ connector.load(store);
+ }
+
+ return connector;
+ }
+}
diff --git a/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshMementoHandler.java b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshMementoHandler.java
new file mode 100644
index 000000000..f0ce4c2c0
--- /dev/null
+++ b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/launcher/SshMementoHandler.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2015 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.ssh.launcher;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
+import org.eclipse.tcf.te.core.terminals.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tcf.te.ui.terminals.interfaces.IMementoHandler;
+import org.eclipse.ui.IMemento;
+
+/**
+ * SSH terminal connection memento handler implementation.
+ */
+public class SshMementoHandler implements IMementoHandler {
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.IMementoHandler#saveState(org.eclipse.ui.IMemento, java.util.Map)
+ */
+ @Override
+ public void saveState(IMemento memento, Map<String, Object> properties) {
+ Assert.isNotNull(memento);
+ Assert.isNotNull(properties);
+
+ // Do not write the terminal title to the memento -> needs to
+ // be recreated at the time of restoration.
+ memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
+ Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
+ memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, value instanceof Integer ? ((Integer)value).intValue() : -1);
+ value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
+ memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, value instanceof Integer ? ((Integer)value).intValue() : -1);
+ value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
+ memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, value instanceof Integer ? ((Integer)value).intValue() : -1);
+ memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER, (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER));
+ memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
+
+ // The password is stored within the Eclipse secure preferences -> no need to store it to the memento
+ //
+ // If ever needed, this is an example on how to encrypt the password using 3DES. Do not remove!
+
+ /*
+ String password = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
+ if (password != null) {
+ try {
+ // Generate a temporary key. In practice, you would save this key.
+ // See also Encrypting with DES Using a Pass Phrase.
+ // SecretKey key = KeyGenerator.getInstance("DESede").generateKey();
+
+ SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede"); //$NON-NLS-1$
+ SecretKey key = factory.generateSecret(new DESKeySpec((ITerminalsConnectorConstants.PROP_SSH_PASSWORD + ".SshMementoHandler").getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); //$NON-NLS-1$
+ cipher.init(Cipher.ENCRYPT_MODE, key);
+
+ String encrypedPwd = new String(Base64.encode(cipher.doFinal(password.getBytes("UTF-8")))); //$NON-NLS-1$
+ memento.putString(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, encrypedPwd);
+ }
+ catch (Exception e) {
+ if (Platform.inDebugMode()) e.printStackTrace();
+ }
+ }
+ */
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.IMementoHandler#restoreState(org.eclipse.ui.IMemento, java.util.Map)
+ */
+ @Override
+ public void restoreState(IMemento memento, Map<String, Object> properties) {
+ Assert.isNotNull(memento);
+ Assert.isNotNull(properties);
+
+ // Restore the terminal properties from the memento
+ properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST));
+ properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT));
+ properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT));
+ properties.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, memento.getInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE));
+ properties.put(ITerminalsConnectorConstants.PROP_SSH_USER, memento.getString(ITerminalsConnectorConstants.PROP_SSH_USER));
+ properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
+
+ // The password is stored within the Eclipse secure preferences -> restore it from there
+ // To access the secure storage, we need the preference instance
+ String password = null;
+ ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
+ if (preferences != null && (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) {
+ // Construct the secure preferences node key
+ String nodeKey = "/Target Explorer SSH Password/" + (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); //$NON-NLS-1$
+ ISecurePreferences node = preferences.node(nodeKey);
+ if (node != null) {
+ try {
+ password = node.get("password", null); //$NON-NLS-1$
+ }
+ catch (StorageException ex) { /* ignored on purpose */ }
+ }
+ }
+
+ // Example of restoring the password from an 3DES encrypted string. Do not remove!
+ /*
+ String encrypedPwd = memento.getString(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
+ if (encrypedPwd != null) {
+ try {
+ SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede"); //$NON-NLS-1$
+ SecretKey key = factory.generateSecret(new DESKeySpec((ITerminalsConnectorConstants.PROP_SSH_PASSWORD + ".SshMementoHandler").getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); //$NON-NLS-1$
+ cipher.init(Cipher.DECRYPT_MODE, key);
+
+ byte[] encBytes = Base64.decode(encrypedPwd.getBytes("UTF-8")); //$NON-NLS-1$
+ byte[] decBytes = cipher.doFinal(encBytes);
+
+ password = new String(decBytes);
+ }
+ catch (Exception e) {
+ if (Platform.inDebugMode()) e.printStackTrace();
+ }
+ }
+ */
+
+ properties.put(ITerminalsConnectorConstants.PROP_SSH_PASSWORD, password);
+ }
+
+}
diff --git a/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.java b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.java
new file mode 100644
index 000000000..265c2e0d0
--- /dev/null
+++ b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 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:
+ * Wind River Systems - initial API and implementation
+ * Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.ssh.nls;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Target Explorer TCF terminals extensions UI plug-in externalized strings management.
+ */
+public class Messages extends NLS {
+
+ // The plug-in resource bundle name
+ private static final String BUNDLE_NAME = "org.eclipse.tcf.te.ui.terminals.ssh.nls.Messages"; //$NON-NLS-1$
+
+ /**
+ * Static constructor.
+ */
+ static {
+ // Load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ // **** Declare externalized string id's down here *****
+
+ public static String SshLauncherDelegate_terminalTitle;
+ public static String SshLauncherDelegate_terminalTitle_default;
+ public static String SshWizardConfigurationPanel_saveUser;
+ public static String SshWizardConfigurationPanel_savePassword;
+}
diff --git a/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.properties b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.properties
new file mode 100644
index 000000000..ca27a39c1
--- /dev/null
+++ b/terminals/plugins/org.eclipse.tcf.te.ui.terminals.ssh/src/org/eclipse/tcf/te/ui/terminals/ssh/nls/Messages.properties
@@ -0,0 +1,14 @@
+###############################################################################
+# Copyright (c) 2012, 2014 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:
+# Wind River Systems - initial API and implementation
+###############################################################################
+
+SshLauncherDelegate_terminalTitle=SSH {0}@{1} ({2})
+SshLauncherDelegate_terminalTitle_default=SSH Terminal
+SshWizardConfigurationPanel_saveUser=Save user
+SshWizardConfigurationPanel_savePassword=Save password

Back to the top