diff --git a/terminal/org.eclipse.tm.terminal.ssh/META-INF/MANIFEST.MF b/terminal/org.eclipse.tm.terminal.ssh/META-INF/MANIFEST.MF index 83df069e842..1acb1cc4d25 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/META-INF/MANIFEST.MF +++ b/terminal/org.eclipse.tm.terminal.ssh/META-INF/MANIFEST.MF @@ -9,9 +9,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.tm.terminal, org.eclipse.ui, - org.eclipse.team.cvs.core;bundle-version="[3.2.0,4.0.0)", - org.eclipse.team.cvs.ssh2;bundle-version="[3.2.0,4.0.0)", - org.eclipse.team.cvs.ui;bundle-version="[3.2.0,4.0.0)", com.jcraft.jsch;bundle-version="[0.1.28,2.0.0)" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/ISshConstants.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/ISshConstants.java new file mode 100644 index 00000000000..9685df158cc --- /dev/null +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/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.tm.terminal.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/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/KeyboardInteractiveDialog.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/KeyboardInteractiveDialog.java new file mode 100644 index 00000000000..30ed2368b50 --- /dev/null +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/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.tm.terminal.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(SshMessages.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(SshMessages.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/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshConnection.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshConnection.java index 6cf4b0d7793..5773e151b12 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshConnection.java +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshConnection.java @@ -13,21 +13,22 @@ package org.eclipse.tm.terminal.ssh; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Map; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Display; -import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.internal.ccvs.ssh2.CVSSSH2Plugin; -import org.eclipse.team.internal.ccvs.ssh2.ISSHContants; -import org.eclipse.team.internal.ccvs.ui.KeyboardInteractiveDialog; -import org.eclipse.team.internal.ccvs.ui.UserValidationDialog; import org.eclipse.tm.terminal.ITerminalControl; import org.eclipse.tm.terminal.Logger; import org.eclipse.tm.terminal.TerminalState; +import org.eclipse.ui.preferences.ScopedPreferenceStore; import com.jcraft.jsch.ChannelShell; import com.jcraft.jsch.JSch; @@ -66,13 +67,29 @@ class SshConnection extends Thread { } } + private static IPreferenceStore fCvsSsh2PreferenceStore; + static IPreferenceStore getCvsSsh2PreferenceStore() { + if (fCvsSsh2PreferenceStore == null) { + fCvsSsh2PreferenceStore = new ScopedPreferenceStore(new InstanceScope(),"org.eclipse.team.cvs.ssh2"); //$NON-NLS-1$ + } + return fCvsSsh2PreferenceStore; + } + + private static IPreferenceStore fCvsUIPreferenceStore; + static IPreferenceStore getCvsUIPreferenceStore() { + if (fCvsUIPreferenceStore == null) { + fCvsUIPreferenceStore = new ScopedPreferenceStore(new InstanceScope(),"org.eclipse.team.cvs.ui"); //$NON-NLS-1$ + } + return fCvsUIPreferenceStore; + } + // Load ssh prefs from Team/CVS for now. // TODO do our own preference page. static void loadSshPrefs(JSch jsch) { - IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore(); - String ssh_home = store.getString(ISSHContants.KEY_SSH2HOME); - String pkeys = store.getString(ISSHContants.KEY_PRIVATEKEY); + IPreferenceStore store = getCvsSsh2PreferenceStore(); + String ssh_home = store.getString(ISshConstants.KEY_SSH2HOME); + String pkeys = store.getString(ISshConstants.KEY_PRIVATEKEY); try { if (ssh_home.length() == 0) @@ -81,6 +98,7 @@ class SshConnection extends Thread { if (current_ssh_home == null || !current_ssh_home.equals(ssh_home)) { loadKnownHosts(jsch, ssh_home); current_ssh_home = ssh_home; + current_pkeys = ""; //$NON-NLS-1$ } if (!current_pkeys.equals(pkeys)) { @@ -124,33 +142,47 @@ class SshConnection extends Thread { } catch (Exception e) { } } - + + private static final String INFO_PROXY_USER = "org.eclipse.team.cvs.core.proxy.user"; //$NON-NLS-1$ + private static final String INFO_PROXY_PASS = "org.eclipse.team.cvs.core.proxy.pass"; //$NON-NLS-1$ + static Proxy loadSshProxyPrefs() { - //TODO Get rid of discouraged access when bug 154100 is fixed - boolean useProxy = CVSProviderPlugin.getPlugin().isUseProxy(); + //TODO Use official Platform prefs when bug 154100 is fixed + IPreferenceStore store = getCvsUIPreferenceStore(); + boolean useProxy = store.getBoolean(ISshConstants.PREF_USE_PROXY); Proxy proxy = null; if (useProxy) { - String _type = CVSProviderPlugin.getPlugin().getProxyType(); - String _host = CVSProviderPlugin.getPlugin().getProxyHost(); - String _port = CVSProviderPlugin.getPlugin().getProxyPort(); + String _type = store.getString(ISshConstants.PREF_PROXY_TYPE); + String _host = store.getString(ISshConstants.PREF_PROXY_HOST); + String _port = store.getString(ISshConstants.PREF_PROXY_PORT); - boolean useAuth = CVSProviderPlugin.getPlugin().isUseProxyAuth(); + boolean useAuth = store.getBoolean(ISshConstants.PREF_PROXY_AUTH); String _user = ""; //$NON-NLS-1$ String _pass = ""; //$NON-NLS-1$ // Retrieve username and password from keyring. if(useAuth){ - _user=CVSProviderPlugin.getPlugin().getProxyUser(); - _pass=CVSProviderPlugin.getPlugin().getProxyPassword(); + Map authInfo = null; + try { + URL FAKE_URL = new URL("http://org.eclipse.team.cvs.proxy.auth");//$NON-NLS-1$ + authInfo = Platform.getAuthorizationInfo(FAKE_URL, "proxy", ""); //$NON-NLS-1$ //$NON-NLS-2$ + } catch(MalformedURLException e) { + //should never happen + } + if (authInfo==null) authInfo=Collections.EMPTY_MAP; + _user=(String)authInfo.get(INFO_PROXY_USER); + _pass=(String)authInfo.get(INFO_PROXY_PASS); + if (_user==null) _user=""; //$NON-NLS-1$ + if (_pass==null) _pass=""; //$NON-NLS-1$ } String proxyhost = _host + ":" + _port; //$NON-NLS-1$ - if (_type.equals(CVSProviderPlugin.PROXY_TYPE_HTTP)) { + if (_type.equals(ISshConstants.PROXY_TYPE_HTTP)) { proxy = new ProxyHTTP(proxyhost); if (useAuth) { ((ProxyHTTP) proxy).setUserPasswd(_user, _pass); } - } else if (_type.equals(CVSProviderPlugin.PROXY_TYPE_SOCKS5)) { + } else if (_type.equals(ISshConstants.PROXY_TYPE_SOCKS5)) { proxy = new ProxySOCKS5(proxyhost); if (useAuth) { ((ProxySOCKS5) proxy).setUserPasswd(_user, _pass); @@ -181,7 +213,14 @@ class SshConnection extends Thread { session.setTimeout(0); //never time out once connected session.setPassword(password); - UserInfo ui=new MyUserInfo(user, password); + ////Giving a connectionId could be the index into a local + ////Store where passwords are stored + //String connectionId = host; + //if (port!=22) { + // connectionId += ':' + port; + //} + //UserInfo ui=new MyUserInfo(connectionId, user, password); + UserInfo ui=new MyUserInfo(null, user, password); session.setUserInfo(ui); // java.util.Hashtable config=new java.util.Hashtable(); @@ -232,12 +271,14 @@ class SshConnection extends Thread { } private static class MyUserInfo implements UserInfo { + private final String fConnectionId; + private final String fUser; private String fPassword; private String fPassphrase; private int fAttemptCount; - private final String fUser; - public MyUserInfo(String user, String password) { + public MyUserInfo(String connectionId, String user, String password) { + fConnectionId = connectionId; fUser = user; fPassword = password; } @@ -256,12 +297,9 @@ class SshConnection extends Thread { } private String promptSecret(final String message) { final String[] retval = new String[1]; - final String finUser = fUser; getStandardDisplay().syncExec(new Runnable() { public void run() { - //TODO discouraged access: Write our own UserValidationDialog - UserValidationDialog uvd = new UserValidationDialog(null, null, - finUser, message); + UserValidationDialog uvd = new UserValidationDialog(null, fConnectionId, fUser, message); uvd.setUsernameMutable(false); if (uvd.open() == Window.OK) { retval[0] = uvd.getPassword(); @@ -311,9 +349,8 @@ class SshConnection extends Thread { final String[][] finResult = new String[1][]; getStandardDisplay().syncExec(new Runnable() { public void run() { - //TODO discouraged access: write our own KeyboardInteractiveDialog KeyboardInteractiveDialog dialog = new KeyboardInteractiveDialog(null, - null, destination, name, instruction, prompt, echo); + fConnectionId, destination, name, instruction, prompt, echo); dialog.open(); finResult[0]=dialog.getResult(); } diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.java index 347c39430ed..02e1f0d4321 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.java +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.java @@ -25,5 +25,18 @@ public class SshMessages extends NLS { public static String TIMEOUT; public static String WARNING; public static String INFO; + + //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; } diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.properties b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.properties index 1928a323e49..eefa7b01e70 100644 --- a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.properties +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/SshMessages.properties @@ -17,3 +17,16 @@ PASSWORD = Password TIMEOUT = Timeout WARNING = Warning 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} diff --git a/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/UserValidationDialog.java b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/ssh/UserValidationDialog.java new file mode 100644 index 00000000000..5741669160a --- /dev/null +++ b/terminal/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/terminal/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.tm.terminal.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(SshMessages.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(SshMessages.UserValidationDialog_5); + data = new GridData(); + d.setLayoutData(data); + Label label = new Label(main, SWT.WRAP); + if (isUsernameMutable) { + label.setText(NLS.bind(SshMessages.UserValidationDialog_labelUser, new String[] { domain })); + } else { + label.setText(NLS.bind(SshMessages.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(SshMessages.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(SshMessages.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(SshMessages.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(SshMessages.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(); + } +}