1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Bug 424627 - Fix password login with pubkey available

Put password the first in PreferredAuthentications so that password is
used when password is selected by the user.

Also
- remove the "File with private key" field
- remove the get/setKeyFile from the JSchConnection
- add a link to the network connections preference page
- swap the order of the public key/password areas
- make public key the default

Change-Id: I5aea011e41fd0097aa51b052ab1386d431362ec8
This commit is contained in:
Roland Schulz 2014-09-29 18:45:26 -04:00 committed by John Eblen
parent cda4c419d6
commit b1903767f3
6 changed files with 49 additions and 91 deletions

View file

@ -518,10 +518,6 @@ public class JSchConnection implements IRemoteConnection {
return fAttributes; return fAttributes;
} }
public String getKeyFile() {
return fAttributes.getAttribute(JSchConnectionAttributes.KEYFILE_ATTR, EMPTY_STRING);
}
public JSchConnectionManager getManager() { public JSchConnectionManager getManager() {
return fManager; return fManager;
} }
@ -835,13 +831,13 @@ public class JSchConnection implements IRemoteConnection {
private Session newSession(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException { private Session newSession(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException {
SubMonitor progress = SubMonitor.convert(monitor, 10); SubMonitor progress = SubMonitor.convert(monitor, 10);
try { try {
if (!isPasswordAuth()) {
fJSchService.getJSch().addIdentity(getKeyFile());
}
Session session = fJSchService.createSession(getAddress(), getPort(), getUsername()); Session session = fJSchService.createSession(getAddress(), getPort(), getUsername());
session.setUserInfo(new JSchUserInfo(authenticator)); session.setUserInfo(new JSchUserInfo(authenticator));
if (isPasswordAuth()) { if (isPasswordAuth()) {
session.setConfig("PreferredAuthentications", "password,keyboard-interactive,gssapi-with-mic,publickey"); //$NON-NLS-1$ //$NON-NLS-2$
session.setPassword(getPassword()); session.setPassword(getPassword());
} else {
session.setConfig("PreferredAuthentications", "publickey,gssapi-with-mic,password,keyboard-interactive"); //$NON-NLS-1$ //$NON-NLS-2$
} }
if (getProxyCommand().equals(EMPTY_STRING) && getProxyConnectionName().equals(EMPTY_STRING)) { if (getProxyCommand().equals(EMPTY_STRING) && getProxyConnectionName().equals(EMPTY_STRING)) {
fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10)); // connect without proxy fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10)); // connect without proxy

View file

@ -36,7 +36,6 @@ public class JSchConnectionAttributes {
public static final String PROXYCOMMAND_ATTR = "JSCH_PROXYCOMMAND_ATTR"; //$NON-NLS-1$ public static final String PROXYCOMMAND_ATTR = "JSCH_PROXYCOMMAND_ATTR"; //$NON-NLS-1$
public static final String IS_PASSWORD_ATTR = "JSCH_IS_PASSWORD_ATTR"; //$NON-NLS-1$ public static final String IS_PASSWORD_ATTR = "JSCH_IS_PASSWORD_ATTR"; //$NON-NLS-1$
public static final String PASSPHRASE_ATTR = "JSCH_PASSPHRASE_ATTR"; //$NON-NLS-1$ public static final String PASSPHRASE_ATTR = "JSCH_PASSPHRASE_ATTR"; //$NON-NLS-1$
public static final String KEYFILE_ATTR = "JSCH_KEYFILE_ATTR"; //$NON-NLS-1$
public static final String TIMEOUT_ATTR = "JSCH_TIMEOUT_ATTR"; //$NON-NLS-1$ public static final String TIMEOUT_ATTR = "JSCH_TIMEOUT_ATTR"; //$NON-NLS-1$
public static final String USE_LOGIN_SHELL_ATTR = "JSCH_USE_LOGIN_SHELL_ATTR"; //$NON-NLS-1$ public static final String USE_LOGIN_SHELL_ATTR = "JSCH_USE_LOGIN_SHELL_ATTR"; //$NON-NLS-1$

View file

@ -53,11 +53,6 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
return Collections.unmodifiableMap(fWorkingAttributes.getAttributes()); return Collections.unmodifiableMap(fWorkingAttributes.getAttributes());
} }
@Override
public String getKeyFile() {
return fWorkingAttributes.getAttribute(JSchConnectionAttributes.KEYFILE_ATTR, EMPTY_STRING);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -227,11 +222,6 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
fWorkingAttributes.setAttribute(JSchConnectionAttributes.IS_PASSWORD_ATTR, Boolean.toString(flag)); fWorkingAttributes.setAttribute(JSchConnectionAttributes.IS_PASSWORD_ATTR, Boolean.toString(flag));
} }
public void setKeyFile(String keyFile) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.KEYFILE_ATTR, keyFile);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View file

@ -27,6 +27,7 @@ public class Messages extends NLS {
public static String JSchConnectionPage_Please_enter_name_for_connection; public static String JSchConnectionPage_Please_enter_name_for_connection;
public static String JSchConnectionPage_Proxy; public static String JSchConnectionPage_Proxy;
public static String JSchConnectionPage_Help; public static String JSchConnectionPage_Help;
public static String JSchConnectionPage_KeysAtSSH2;
public static String JSchConnectionPage_SelectCommand; public static String JSchConnectionPage_SelectCommand;
public static String JSchConnectionPage_SelectConnection; public static String JSchConnectionPage_SelectConnection;
public static String JSchConnectionPage_Settings0; public static String JSchConnectionPage_Settings0;

View file

@ -14,6 +14,7 @@ JSchConnectionPage_Edit_properties_of_an_existing_connection=Edit properties of
JSchConnectionPage_Please_enter_name_for_connection=Please enter a name for the connection JSchConnectionPage_Please_enter_name_for_connection=Please enter a name for the connection
JSchConnectionPage_Proxy=SSH Proxy Settings JSchConnectionPage_Proxy=SSH Proxy Settings
JSchConnectionPage_Help=If 'Local' is selected and proxy command is empty, no proxy is used.\nSee <a>Network Connections</a> for SOCKS and HTTP proxy options. JSchConnectionPage_Help=If 'Local' is selected and proxy command is empty, no proxy is used.\nSee <a>Network Connections</a> for SOCKS and HTTP proxy options.
JSchConnectionPage_KeysAtSSH2=Keys are set at <a>Network Connections, SSH2</a>
JSchConnectionPage_SelectCommand=Enter a local or remote command such as 'nc %h %p'. Can be empty for an ssh gateway. JSchConnectionPage_SelectCommand=Enter a local or remote command such as 'nc %h %p'. Can be empty for an ssh gateway.
JSchConnectionPage_SelectConnection=Select 'Remote' for an ssh gateway or a remote proxy command. JSchConnectionPage_SelectConnection=Select 'Remote' for an ssh gateway or a remote proxy command.
JSchConnectionPage_Settings0=Connection Settings JSchConnectionPage_Settings0=Connection Settings

View file

@ -11,7 +11,6 @@
*/ */
package org.eclipse.remote.internal.jsch.ui.wizards; package org.eclipse.remote.internal.jsch.ui.wizards;
import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -28,7 +27,6 @@ import org.eclipse.remote.internal.jsch.core.JSchConnectionAttributes;
import org.eclipse.remote.internal.jsch.core.JSchConnectionWorkingCopy; import org.eclipse.remote.internal.jsch.core.JSchConnectionWorkingCopy;
import org.eclipse.remote.internal.jsch.ui.messages.Messages; import org.eclipse.remote.internal.jsch.ui.messages.Messages;
import org.eclipse.remote.ui.widgets.RemoteConnectionWidget; import org.eclipse.remote.ui.widgets.RemoteConnectionWidget;
import org.eclipse.remote.ui.widgets.RemoteFileWidget;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
@ -70,7 +68,6 @@ public class JSchConnectionPage extends WizardPage {
private Text fPassphraseText; private Text fPassphraseText;
private Text fPortText; private Text fPortText;
private Text fTimeoutText; private Text fTimeoutText;
private RemoteFileWidget fFileWidget;
private String fInitialName = "Remote Host"; //$NON-NLS-1$ private String fInitialName = "Remote Host"; //$NON-NLS-1$
private Set<String> fInvalidConnectionNames; private Set<String> fInvalidConnectionNames;
@ -133,7 +130,6 @@ public class JSchConnectionPage extends WizardPage {
Label portLabel = new Label(settingsComp, SWT.NONE); Label portLabel = new Label(settingsComp, SWT.NONE);
portLabel.setText(Messages.JSchNewConnectionPage_Port); portLabel.setText(Messages.JSchNewConnectionPage_Port);
portLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fPortText = new Text(settingsComp, SWT.BORDER | SWT.SINGLE); fPortText = new Text(settingsComp, SWT.BORDER | SWT.SINGLE);
fPortText.setText(Integer.toString(JSchConnection.DEFAULT_PORT)); fPortText.setText(Integer.toString(JSchConnection.DEFAULT_PORT));
fPortText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); fPortText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
@ -141,7 +137,6 @@ public class JSchConnectionPage extends WizardPage {
Label timeoutLabel = new Label(settingsComp, SWT.NONE); Label timeoutLabel = new Label(settingsComp, SWT.NONE);
timeoutLabel.setText(Messages.JSchNewConnectionPage_Timeout); timeoutLabel.setText(Messages.JSchNewConnectionPage_Timeout);
timeoutLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fTimeoutText = new Text(settingsComp, SWT.BORDER | SWT.SINGLE); fTimeoutText = new Text(settingsComp, SWT.BORDER | SWT.SINGLE);
fTimeoutText.setText(Integer.toString(JSchConnection.DEFAULT_TIMEOUT)); fTimeoutText.setText(Integer.toString(JSchConnection.DEFAULT_TIMEOUT));
fTimeoutText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); fTimeoutText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
@ -158,39 +153,18 @@ public class JSchConnectionPage extends WizardPage {
private void createAuthControls(Composite parent) { private void createAuthControls(Composite parent) {
Composite controls = new Composite(parent, SWT.NONE); Composite controls = new Composite(parent, SWT.NONE);
controls.setLayout(new GridLayout(2, false)); controls.setLayout(new GridLayout(3, false));
controls.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); controls.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label hostLabel = new Label(controls, SWT.NONE); Label hostLabel = new Label(controls, SWT.NONE);
hostLabel.setText(Messages.JSchNewConnectionPage_Host); hostLabel.setText(Messages.JSchNewConnectionPage_Host);
hostLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fHostText = new Text(controls, SWT.BORDER | SWT.SINGLE); fHostText = new Text(controls, SWT.BORDER | SWT.SINGLE);
fHostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fHostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label userLabel = new Label(controls, SWT.NONE); Label userLabel = new Label(controls, SWT.NONE);
userLabel.setText(Messages.JSchNewConnectionPage_User); userLabel.setText(Messages.JSchNewConnectionPage_User);
userLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fUserText = new Text(controls, SWT.BORDER | SWT.SINGLE); fUserText = new Text(controls, SWT.BORDER | SWT.SINGLE);
fUserText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fUserText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
// User option box
fPasswordButton = new Button(controls, SWT.RADIO);
fPasswordButton.setText(Messages.JSchNewConnectionPage_Password_based_authentication);
fPasswordButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
fPasswordButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
validateFields();
updateEnablement();
}
});
// Password field
Label passwordLabel = new Label(controls, SWT.NONE);
passwordLabel.setText(Messages.JSchNewConnectionPage_Password);
passwordLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fPasswordText = new Text(controls, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD);
fPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
// Key option box // Key option box
fPublicKeyButton = new Button(controls, SWT.RADIO); fPublicKeyButton = new Button(controls, SWT.RADIO);
@ -204,24 +178,53 @@ public class JSchConnectionPage extends WizardPage {
} }
}); });
// Key file selection Link link = new Link(controls, SWT.WRAP);
fFileWidget = new RemoteFileWidget(controls, SWT.NONE, 0, null, ""); //$NON-NLS-1$ final GridData linkLayoutData = new GridData(GridData.FILL_HORIZONTAL);
fFileWidget.setConnection(RemoteServices.getLocalServices().getConnectionManager() link.setLayoutData(linkLayoutData);
.getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME)); final String PREFS_PAGE_ID_NET_SSH = "org.eclipse.jsch.ui.SSHPreferences"; //$NON-NLS-1$
fFileWidget.setLabel(Messages.JSchNewConnectionPage_File_with_private_key); link.addSelectionListener(new SelectionListener() {
fFileWidget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); @Override
public void widgetSelected(SelectionEvent e) {
PreferenceDialog dlg = PreferencesUtil.createPreferenceDialogOn(getShell(), PREFS_PAGE_ID_NET_SSH,
new String[] { PREFS_PAGE_ID_NET_SSH }, null);
dlg.open();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
link.setText(Messages.JSchConnectionPage_KeysAtSSH2);
// Passphrase field // Passphrase field
Label passphraseLabel = new Label(controls, SWT.NONE); Label passphraseLabel = new Label(controls, SWT.NONE);
passphraseLabel.setText(Messages.JSchNewConnectionPage_Passphrase); passphraseLabel.setText(Messages.JSchNewConnectionPage_Passphrase);
passphraseLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fPassphraseText = new Text(controls, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD); fPassphraseText = new Text(controls, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD);
fPassphraseText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fPassphraseText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
fPasswordButton.setSelection(true); // User option box
fPublicKeyButton.setSelection(false); fPasswordButton = new Button(controls, SWT.RADIO);
controls.setTabList(new Control[] { fHostText, fUserText, fPasswordButton, fPasswordText, fPublicKeyButton, fFileWidget, fPasswordButton.setText(Messages.JSchNewConnectionPage_Password_based_authentication);
fPassphraseText }); fPasswordButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
fPasswordButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
validateFields();
updateEnablement();
}
});
// Password field
Label passwordLabel = new Label(controls, SWT.NONE);
passwordLabel.setText(Messages.JSchNewConnectionPage_Password);
fPasswordText = new Text(controls, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD);
fPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
fPasswordButton.setSelection(false);
fPublicKeyButton.setSelection(true);
controls.setTabList(new Control[] { fHostText, fUserText, fPublicKeyButton,
fPassphraseText, fPasswordButton, fPasswordText });
} }
@Override @Override
@ -243,7 +246,6 @@ public class JSchConnectionPage extends WizardPage {
Label label = new Label(topControl, SWT.NONE); Label label = new Label(topControl, SWT.NONE);
label.setText(Messages.JSchNewConnectionPage_Connection_name); label.setText(Messages.JSchNewConnectionPage_Connection_name);
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
fConnectionName = new Text(topControl, SWT.BORDER | SWT.SINGLE); fConnectionName = new Text(topControl, SWT.BORDER | SWT.SINGLE);
fConnectionName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fConnectionName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
@ -345,7 +347,6 @@ public class JSchConnectionPage extends WizardPage {
fPasswordText.setText(fConnection.getPassword()); fPasswordText.setText(fConnection.getPassword());
} else { } else {
fPassphraseText.setText(fConnection.getPassphrase()); fPassphraseText.setText(fConnection.getPassphrase());
fFileWidget.setLocationPath(fConnection.getKeyFile());
} }
fProxyCommandText.setText(fConnection.getProxyCommand()); fProxyCommandText.setText(fConnection.getProxyCommand());
@ -380,10 +381,6 @@ public class JSchConnectionPage extends WizardPage {
if (passphrase != null) { if (passphrase != null) {
fPassphraseText.setText(passphrase); fPassphraseText.setText(passphrase);
} }
String file = fInitialAttributes.get(JSchConnectionAttributes.KEYFILE_ATTR);
if (file != null) {
fFileWidget.setLocationPath(file);
}
fProxyConnectionWidget.setConnection(RemoteServices.getLocalServices().getConnectionManager().getConnection( fProxyConnectionWidget.setConnection(RemoteServices.getLocalServices().getConnectionManager().getConnection(
IRemoteConnectionManager.LOCAL_CONNECTION_NAME)); IRemoteConnectionManager.LOCAL_CONNECTION_NAME));
} }
@ -393,7 +390,6 @@ public class JSchConnectionPage extends WizardPage {
fConnectionName.addModifyListener(fDataModifyListener); fConnectionName.addModifyListener(fDataModifyListener);
fHostText.addModifyListener(fDataModifyListener); fHostText.addModifyListener(fDataModifyListener);
fUserText.addModifyListener(fDataModifyListener); fUserText.addModifyListener(fDataModifyListener);
fFileWidget.addModifyListener(fDataModifyListener);
fPasswordText.addModifyListener(fDataModifyListener); fPasswordText.addModifyListener(fDataModifyListener);
fPassphraseText.addModifyListener(fDataModifyListener); fPassphraseText.addModifyListener(fDataModifyListener);
fPortText.addModifyListener(fDataModifyListener); fPortText.addModifyListener(fDataModifyListener);
@ -481,9 +477,6 @@ public class JSchConnectionPage extends WizardPage {
if (!fConnection.getPassphrase().equals(fPassphraseText.getText().trim())) { if (!fConnection.getPassphrase().equals(fPassphraseText.getText().trim())) {
fConnection.setPassphrase(fPassphraseText.getText().trim()); fConnection.setPassphrase(fPassphraseText.getText().trim());
} }
if (!fConnection.getKeyFile().equals(fFileWidget.getLocationPath())) {
fConnection.setKeyFile(fFileWidget.getLocationPath());
}
if (fConnection.isPasswordAuth() != fPasswordButton.getSelection()) { if (fConnection.isPasswordAuth() != fPasswordButton.getSelection()) {
fConnection.setIsPasswordAuth(fPasswordButton.getSelection()); fConnection.setIsPasswordAuth(fPasswordButton.getSelection());
} }
@ -513,7 +506,6 @@ public class JSchConnectionPage extends WizardPage {
boolean isPasswordAuth = fPasswordButton.getSelection(); boolean isPasswordAuth = fPasswordButton.getSelection();
fPasswordText.setEnabled(isPasswordAuth); fPasswordText.setEnabled(isPasswordAuth);
fPassphraseText.setEnabled(!isPasswordAuth); fPassphraseText.setEnabled(!isPasswordAuth);
fFileWidget.setEnabled(!isPasswordAuth);
} }
private String validateAdvanced() { private String validateAdvanced() {
@ -544,9 +536,6 @@ public class JSchConnectionPage extends WizardPage {
} else if (fUserText.getText().trim().length() == 0) { } else if (fUserText.getText().trim().length() == 0) {
message = Messages.JSchNewConnectionPage_User_name_cannot_be_empty; message = Messages.JSchNewConnectionPage_User_name_cannot_be_empty;
} }
if (message == null) {
message = validatePasskey();
}
if (message == null && fProxyConnectionWidget.getConnection() == null) { if (message == null && fProxyConnectionWidget.getConnection() == null) {
message = Messages.JSchConnectionPage_selectProxyConnection; message = Messages.JSchConnectionPage_selectProxyConnection;
} }
@ -558,22 +547,4 @@ public class JSchConnectionPage extends WizardPage {
setPageComplete(message == null); setPageComplete(message == null);
} }
private String validatePasskey() {
if (!fPasswordButton.getSelection()) {
if (fFileWidget.getLocationPath().trim().length() == 0) {
return Messages.JSchNewConnectionPage_Private_key_path_cannot_be_empty;
}
File path = new File(fFileWidget.getLocationPath().trim());
if (!path.exists()) {
return Messages.JSchNewConnectionPage_Private_key_file_does_not_exist;
}
if (!path.isFile()) {
return Messages.JSchNewConnectionPage_Private_key_file_is_invalid;
}
if (!path.canRead()) {
return Messages.JSchNewConnectionPage_Private_key_file_cannot_be_read;
}
}
return null;
}
} }