diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/ISshConstants.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/ISshConstants.java new file mode 100644 index 00000000000..ec6f7143679 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/ISshConstants.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Martin Oberhuber (Wind River) - extracted from various team.cvs plugins + *******************************************************************************/ +package org.eclipse.rse.connectorservice.ssh; + + +/** + * Defines the constants used by the terminal.ssh Plugin + */ +public interface ISshConstants { + + // These are from ISSHContants + public static final String KEY_SSH2HOME="CVSSSH2PreferencePage.SSH2HOME"; //$NON-NLS-1$ + public static final String KEY_PRIVATEKEY="CVSSSH2PreferencePage.PRIVATEKEY"; //$NON-NLS-1$ + + // These are from ICVSUIConstants + public static final String PREF_USE_PROXY = "proxyEnabled"; //$NON-NLS-1$ + public static final String PREF_PROXY_TYPE = "proxyType"; //$NON-NLS-1$ + public static final String PREF_PROXY_HOST = "proxyHost"; //$NON-NLS-1$ + public static final String PREF_PROXY_PORT = "proxyPort"; //$NON-NLS-1$ + public static final String PREF_PROXY_AUTH = "proxyAuth"; //$NON-NLS-1$ + + // These are from CVSProviderPlugin + public static final String PROXY_TYPE_HTTP = "HTTP"; //$NON-NLS-1$ + public static final String PROXY_TYPE_SOCKS5 = "SOCKS5"; //$NON-NLS-1$ + public static final String HTTP_DEFAULT_PORT="80"; //$NON-NLS-1$ + public static final String SOCKS5_DEFAULT_PORT="1080"; //$NON-NLS-1$ + + // These are from cvs.ui.IHelpContextIds + public static final String CVSUIPREFIX = "org.eclipse.team.cvs.ui."; //$NON-NLS-1$ + public static final String HELP_USER_VALIDATION_DIALOG = CVSUIPREFIX + "user_validation_dialog_context"; //$NON-NLS-1$ + public static final String HELP_KEYBOARD_INTERACTIVE_DIALOG = CVSUIPREFIX + "keyboard_interactive_dialog_context"; //$NON-NLS-1$ + +} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/KeyboardInteractiveDialog.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/KeyboardInteractiveDialog.java new file mode 100644 index 00000000000..85040956378 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/KeyboardInteractiveDialog.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. + * IBM Corporation - ongoing maintenance + * Martin Oberhuber (Wind River) - copied and adapted from team.cvs.ui + *******************************************************************************/ +package org.eclipse.rse.connectorservice.ssh; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +/** + * A dialog for keyboad-interactive authentication for the ssh2 connection. + */ +public class KeyboardInteractiveDialog extends TrayDialog { + // widgets + private Text[] texts; + + protected String domain; + protected String destination; + protected String name; + protected String instruction; + protected String lang; + protected String[] prompt; + protected boolean[] echo; + private String message; + private String[] result; + + /** + * Creates a nwe KeyboardInteractiveDialog. + * + * @param parentShell the parent shell + * @param connectionId an id for the connection + * @param destination the location + * @param name the name + * @param instruction the instruction + * @param prompt the titles for textfields + * @param echo '*' should be used or not + */ + public KeyboardInteractiveDialog(Shell parentShell, + String connectionId, + String destination, + String name, + String instruction, + String[] prompt, + boolean[] echo){ + super(parentShell); + this.domain=connectionId; + this.destination=destination; + this.name=name; + this.instruction=instruction; + this.prompt=prompt; + this.echo=echo; + this.message=NLS.bind(SshConnectorResources.KeyboardInteractiveDialog_message, new String[] { destination+(name!=null && name.length()>0 ? ": "+name : "") }); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ + } + /** + * @see Window#configureShell + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(message); + } + /** + * @see Window#create + */ + public void create() { + super.create(); + if(texts.length>0){ + texts[0].setFocus(); + } + } + /** + * @see Dialog#createDialogArea + */ + protected Control createDialogArea(Composite parent) { + Composite main=new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.numColumns=3; + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_BOTH)); + + // set F1 help + PlatformUI.getWorkbench().getHelpSystem().setHelp(main, ISshConstants.HELP_KEYBOARD_INTERACTIVE_DIALOG); + + if (message!=null) { + Label messageLabel=new Label(main, SWT.WRAP); + messageLabel.setText(message); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=3; + messageLabel.setLayoutData(data); + } + if(domain!=null){ + Label label = new Label(main, SWT.WRAP); + label.setText(NLS.bind(SshConnectorResources.KeyboardInteractiveDialog_labelConnection, new String[] { domain })); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=3; + label.setLayoutData(data); + } + if (instruction!=null && instruction.length()>0) { + Label messageLabel=new Label(main, SWT.WRAP); + messageLabel.setText(instruction); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=3; + messageLabel.setLayoutData(data); + } + createPasswordFields(main); + return main; + } + /** + * Creates the widgets that represent the entry area. + * + * @param parent the parent of the widgets + */ + protected void createPasswordFields(Composite parent) { + texts=new Text[prompt.length]; + + for(int i=0; i + * The default implementation of this framework method sets + * this dialog's return code to Window.OK + * and closes the dialog. Subclasses may override. + *

+ */ + protected void okPressed() { + result=new String[prompt.length]; + for(int i=0; i + * The default implementation of this framework method sets + * this dialog's return code to Window.CANCEL + * and closes the dialog. Subclasses may override. + *

+ */ + protected void cancelPressed() { + result=null; + super.cancelPressed(); + } +} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.java index 601d8b336fb..047765020fd 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. + * Copyright (c) 2006 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 @@ -7,6 +7,7 @@ * * Contributors: * Martin Oberhuber (Wind River) - initial API and implementation + * Martin Oberhuber (Wind River) - copy dialogs from team.cvs.ui *******************************************************************************/ package org.eclipse.rse.connectorservice.ssh; @@ -15,6 +16,11 @@ import org.eclipse.osgi.util.NLS; public class SshConnectorResources extends NLS { private static final String BUNDLE_NAME = "org.eclipse.rse.connectorservice.ssh.SshConnectorResources"; //$NON-NLS-1$ + static { + NLS.initializeMessages(BUNDLE_NAME, SshConnectorResources.class); + } + private SshConnectorResources() { + } public static String SshConnectorService_Name; public static String SshConnectorService_Description; @@ -23,11 +29,20 @@ public class SshConnectorResources extends NLS { public static String SshConnectorService_Info; public static String SshConnectorService_Warning; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, SshConnectorResources.class); - } + //These are from org.eclipse.team.cvs.ui.CVSUIMessages + public static String UserValidationDialog_required; + public static String UserValidationDialog_labelUser; + public static String UserValidationDialog_labelPassword; + public static String UserValidationDialog_password; + public static String UserValidationDialog_user; + public static String UserValidationDialog_5; + public static String UserValidationDialog_6; + public static String UserValidationDialog_7; + + public static String KeyboardInteractiveDialog_message; + public static String KeyboardInteractiveDialog_labelConnection; + + //These are from cvs/messages.properties + public static String Socket_timeout; - private SshConnectorResources() { - } } diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.properties b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.properties index f64971d55c5..a35fc48e1af 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.properties +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorResources.properties @@ -1,5 +1,5 @@ ################################################################################ -# Copyright (c) 2006 Wind River Systems, Inc. +# Copyright (c) 2006 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 @@ -7,6 +7,7 @@ # # Contributors: # Martin Oberhuber (Wind River) - initial API and implementation +# Martin Oberhuber (Wind River) - copy dialogs from team.cvs.ui ################################################################################ SshConnectorService_Name=SSH Connector Service @@ -15,3 +16,19 @@ SshConnectorService_Description=SSH Connector Service Description SshConnectorService_ErrorDisconnecting=ConnectionStatusListener: Error disconnecting SshConnectorService_Warning=Warning SshConnectorService_Info=Info + +#These are from cvs.ui/messages.properties +UserValidationDialog_required=Password Required +UserValidationDialog_labelUser={0} +UserValidationDialog_labelPassword={1} +UserValidationDialog_password=&Password: +UserValidationDialog_user=&User name: +UserValidationDialog_5=Connection: +UserValidationDialog_6=&Save password +UserValidationDialog_7=Saved passwords are stored on your computer in a file that is difficult, but not impossible, for an intruder to read. + +KeyboardInteractiveDialog_message=Keyboard Interactive authentication for {0} +KeyboardInteractiveDialog_labelConnection=Enter values for the following connection: {0} + +#These are from cvs/messages.properties +Socket_timeout=A timeout occurred connecting to host {0} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java index e4f2625b6a6..38327728edd 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/SshConnectorService.java @@ -349,7 +349,6 @@ public class SshConnectorService extends AbstractConnectorService implements ISs Socket socket = null; //Allows to cancel the socket creation operation if necessary. //Waits for the timeout specified in CVS Preferences, maximum. - //TODO Get rid of discouraged access by copying into services plugin socket = SshConnectorService.createSocket(host, port, CONNECT_DEFAULT_TIMEOUT, monitor); // Null out the monitor so we don't hold onto anything // (i.e. the SSH2 session will keep a handle to the socket factory around @@ -368,7 +367,6 @@ public class SshConnectorService extends AbstractConnectorService implements ISs protected void internalConnect(IProgressMonitor monitor) throws Exception { - //TODO Set known hosts and identities from Preferences //We could share the preferences from ssh2, or use RSE //ConnectorService Properties / Server Launcher Properties diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/UserValidationDialog.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/UserValidationDialog.java new file mode 100644 index 00000000000..e56218f34de --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/connectorservice/ssh/UserValidationDialog.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Martin Oberhuber (Wind River) - copied from org.eclipse.team.cvs.ui + *******************************************************************************/ +package org.eclipse.rse.connectorservice.ssh; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +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.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; + +/** + * A dialog for prompting for a username and password + */ +public class UserValidationDialog extends TrayDialog { + // widgets + protected Text usernameField; + protected Text passwordField; + protected Button allowCachingButton; + + protected String domain; + protected String defaultUsername; + protected String password = null; + protected boolean allowCaching = false; + protected Image keyLockImage; + + // whether or not the username can be changed + protected boolean isUsernameMutable = true; + protected String username = null; + protected String message = null; + + /** + * Creates a new UserValidationDialog. + * + * @param parentShell the parent shell + * @param location the location + * @param defaultName the default user name + * @param message a mesage to display to the user + */ + public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) { + super(parentShell); + setShellStyle(getShellStyle() | SWT.RESIZE); + this.defaultUsername = defaultName; + this.domain = location; + this.message = message; + } + /** + * @see Window#configureShell + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(SshConnectorResources.UserValidationDialog_required); + // set F1 help + PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, ISshConstants.HELP_USER_VALIDATION_DIALOG); + } + /** + * @see Window#create + */ + public void create() { + super.create(); + // add some default values + usernameField.setText(defaultUsername); + + if (isUsernameMutable) { + // give focus to username field + usernameField.selectAll(); + usernameField.setFocus(); + } else { + usernameField.setEditable(false); + passwordField.setFocus(); + } + } + + /** + * @see Dialog#createDialogArea + */ + protected Control createDialogArea(Composite parent) { + Composite top = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + + top.setLayout(layout); + top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Composite imageComposite = new Composite(top, SWT.NONE); + layout = new GridLayout(); + imageComposite.setLayout(layout); + imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + + Composite main = new Composite(top, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 3; + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label imageLabel = new Label(imageComposite, SWT.NONE); + //keyLockImage = TeamImages.getImageDescriptor(ITeamUIImages.IMG_KEY_LOCK).createImage(); + //imageLabel.setImage(keyLockImage); + GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); + imageLabel.setLayoutData(data); + + if (message != null) { + Label messageLabel = new Label(main, SWT.WRAP); + messageLabel.setText(message); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); + data.horizontalSpan = 3; + data.widthHint = 300; + messageLabel.setLayoutData(data); + } + if (domain != null) { + Label d = new Label(main, SWT.WRAP); + d.setText(SshConnectorResources.UserValidationDialog_5); + data = new GridData(); + d.setLayoutData(data); + Label label = new Label(main, SWT.WRAP); + if (isUsernameMutable) { + label.setText(NLS.bind(SshConnectorResources.UserValidationDialog_labelUser, new String[] { domain })); + } else { + label.setText(NLS.bind(SshConnectorResources.UserValidationDialog_labelPassword, (new Object[]{defaultUsername, domain}))); + } + data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); + data.horizontalSpan = 2; + data.widthHint = 300; + label.setLayoutData(data); + } + createUsernameFields(main); + createPasswordFields(main); + + if(domain != null) { + allowCachingButton = new Button(main, SWT.CHECK); + allowCachingButton.setText(SshConnectorResources.UserValidationDialog_6); + data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); + data.horizontalSpan = 3; + allowCachingButton.setLayoutData(data); + allowCachingButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + allowCaching = allowCachingButton.getSelection(); + } + }); + Composite warningComposite = new Composite(main, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginHeight = 0; + warningComposite.setLayout(layout); + data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + warningComposite.setLayoutData(data); + Label warningLabel = new Label(warningComposite, SWT.NONE); + warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING)); + warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING)); + Label warningText = new Label(warningComposite, SWT.WRAP); + warningText.setText(SshConnectorResources.UserValidationDialog_7); + data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = 300; + warningText.setLayoutData(data); + } + + Dialog.applyDialogFont(parent); + + return main; + } + + /** + * Creates the three widgets that represent the password entry area. + * + * @param parent the parent of the widgets + */ + protected void createPasswordFields(Composite parent) { + new Label(parent, SWT.NONE).setText(SshConnectorResources.UserValidationDialog_password); + + passwordField = new Text(parent, SWT.BORDER | SWT.PASSWORD); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + passwordField.setLayoutData(data); + } + /** + * Creates the three widgets that represent the user name entry area. + * + * @param parent the parent of the widgets + */ + protected void createUsernameFields(Composite parent) { + new Label(parent, SWT.NONE).setText(SshConnectorResources.UserValidationDialog_user); + + usernameField = new Text(parent, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + usernameField.setLayoutData(data); + } + + /** + * Returns the password entered by the user, or null + * if the user canceled. + * + * @return the entered password + */ + public String getPassword() { + return password; + } + + /** + * Returns the username entered by the user, or null + * if the user canceled. + * + * @return the entered username + */ + public String getUsername() { + return username; + } + + /** + * Returns true if the save password checkbox was selected. + * @return true if the save password checkbox was selected and false + * otherwise. + */ + public boolean getAllowCaching() { + return allowCaching; + } + + /** + * Notifies that the ok button of this dialog has been pressed. + *

+ * The default implementation of this framework method sets + * this dialog's return code to Window.OK + * and closes the dialog. Subclasses may override. + *

+ */ + protected void okPressed() { + password = passwordField.getText(); + username = usernameField.getText(); + + super.okPressed(); + } + /** + * Sets whether or not the username field should be mutable. + * This method must be called before create(), otherwise it + * will be ignored. + * + * @param value whether the username is mutable + */ + public void setUsernameMutable(boolean value) { + isUsernameMutable = value; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#close() + */ + public boolean close() { + if(keyLockImage != null) { + keyLockImage.dispose(); + } + return super.close(); + } +}