[jbosstools-commits] JBoss Tools SVN: r43862 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard and 2 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Sep 20 09:52:34 EDT 2012
Author: adietish
Date: 2012-09-20 09:52:33 -0400 (Thu, 20 Sep 2012)
New Revision: 43862
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java
Log:
[JBIDE-11912] added links to ssh prefs and validation
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -10,15 +10,139 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.utils;
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jsch.internal.core.IConstants;
import org.eclipse.jsch.internal.core.JSchCorePlugin;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
/**
* @author Andre Dietisheim
*/
public class SSHUtils {
+ private static final String SSH_PREFERENCE_PAGE_ID = "org.eclipse.jsch.ui.SSHPreferences";
+ private static final String KEYS_SEPARATOR = ",";
+
public static String getSSH2Home() {
return JSchCorePlugin.getPlugin().getPluginPreferences().getString(IConstants.KEY_SSH2HOME);
}
+
+ public static void setPrivateKeyPermissions(File privateKey) {
+ // set f permission to correspond to 'chmod 0600' read/write only for
+ // user
+ // First clear all permissions for both user and others
+ privateKey.setReadable(false, false);
+ privateKey.setWritable(false, false);
+ // Enable only readable for user
+ privateKey.setReadable(true, true);
+ privateKey.setWritable(true, true);
+ }
+
+ public static String[] getPrivateKeysFromPreferences() {
+ String privateKeys =
+ JSchCorePlugin.getPlugin().getPluginPreferences().getString(IConstants.KEY_PRIVATEKEY);
+ if (privateKeys != null
+ && privateKeys.trim().length() > 0) {
+ return privateKeys.split(KEYS_SEPARATOR);
+ } else {
+ return new String[0];
+ }
+ }
+
+ public static boolean isPrivateKeyForPublicKeyKnownToSsh(String publicKeyPath) {
+ if (StringUtils.isEmpty(publicKeyPath)) {
+ return false;
+ }
+ for (String preferencesKey : getPrivateKeysFromPreferences()) {
+ try {
+ File privateKey = SshPrivateKeysPreferences.getKeyFile(preferencesKey);
+ if (privateKey == null
+ || !FileUtils.canRead(privateKey)) {
+ continue;
+ }
+ if (publicKeyPath.startsWith(privateKey.getAbsolutePath() + ".")
+ || publicKeyPath.startsWith(privateKey.getPath() + ".")) {
+ return true;
+ }
+ } catch (FileNotFoundException e) {
+ continue;
+ }
+ }
+ return false;
+ }
+
+ public static void addToPrivateKeysPreferences(File privateKey) {
+ Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
+ String privateKeys = preferences.getString(IConstants.KEY_PRIVATEKEY);
+ if (privateKeys != null
+ && privateKeys.trim().length() > 0) {
+ privateKeys = privateKeys + "," + privateKey.getAbsolutePath();
+ } else {
+ privateKeys = privateKey.getAbsolutePath();
+ }
+ preferences.setValue(IConstants.KEY_PRIVATEKEY, privateKeys);
+ JSchCorePlugin.getPlugin().setNeedToLoadKeys(true);
+ JSchCorePlugin.getPlugin().savePluginPreferences();
+ }
+
+ public static int openPreferencesPage(Shell shell) {
+ PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(
+ shell, SSH_PREFERENCE_PAGE_ID, null, null);
+ return dialog.open();
+
+ }
+
+ /**
+ * Returns <code>true</code> if the given
+ * @param publicKeyPath
+ * @return
+ */
+ public static boolean publicKeyMatchesPrivateKeyInPreferences(File publicKey) {
+ for (String preferencesKey : SSHUtils.getPrivateKeysFromPreferences()) {
+ try {
+ File privateKey = SshPrivateKeysPreferences.getKeyFile(preferencesKey.trim());
+ if (privateKey == null) {
+ continue;
+ }
+ if (publicKey.getAbsolutePath().startsWith(privateKey.getAbsolutePath() + ".")) {
+ return true;
+ }
+ } catch (FileNotFoundException e) {
+ continue;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the key file for a given relative or absolute keyPath. The
+ * keyPath may be absolute or relative to the ssh home directory.
+ *
+ * @param keyPath
+ * @return
+ * @throws FileNotFoundException
+ */
+ public static File getKeyForRelativeOrAbsolutePath(String keyPath) throws FileNotFoundException {
+ if (isEmpty(keyPath)) {
+ return null;
+ }
+
+ if (keyPath.startsWith(File.separator)) {
+ return new File(keyPath);
+ } else {
+ return new File(getSSH2Home(), keyPath);
+ }
+ }
+
+ private static boolean isEmpty(String string) {
+ return string == null
+ || string.isEmpty();
+ }
+
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/GitCloningSettingsWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -178,7 +178,7 @@
new RemoteNameValidationStatusProvider(remoteNameTextObservable, projectNameModelObservable));
Link sshPrefsLink = new Link(parent, SWT.NONE);
- sshPrefsLink.setText("Make sure your SSH key used with the domain is listed in <a>SSH2 Preferences</a>.");
+ sshPrefsLink.setText("Make sure your SSH key used with your user " + wizardModel.getUser().getUsername() + "\nis listed in <a>SSH2 Preferences</a>.");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).indent(10, 0)
.applyTo(sshPrefsLink);
sshPrefsLink.addSelectionListener(onSshPrefs());
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -235,7 +235,7 @@
return ValidationStatus.warning(
NLS.bind("Your SSH config ({0}) contains fixed keys for OpenShift servers. " +
"This can override any Eclipse specific SSH key preferences.", new SSHUserConfig(SSHUtils.getSSH2Home()).getFile()));
- } else if (!isKeyKnownToSsh((String) value)) {
+ } else if (!SSHUtils.publicKeyMatchesPrivateKeyInPreferences(new File((String) value))) {
return ValidationStatus.warning(
NLS.bind("Could not find the private portion for your public key in the preferences. "
+ "Make sure it is listed in the ssh2 preferences.", value));
@@ -243,27 +243,6 @@
return ValidationStatus.ok();
}
- private boolean isKeyKnownToSsh(String publicKeyPath) {
- if (StringUtils.isEmpty(publicKeyPath)) {
- return false;
- }
- for (String preferencesKey : pageModel.getPrivateKeysFromPreferences()) {
- try {
- File privateKey = SshPrivateKeysPreferences.getKeyFile(preferencesKey);
- if (privateKey == null
- || !FileUtils.canRead(privateKey)) {
- continue;
- }
- if (publicKeyPath.startsWith(privateKey.getAbsolutePath() + ".")
- || publicKeyPath.startsWith(privateKey.getPath() + ".")) {
- return true;
- }
- } catch (FileNotFoundException e) {
- continue;
- }
- }
- return false;
- }
}
private class NamespaceValidator extends MultiValidator {
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -180,17 +180,6 @@
file.setReadable(true, true);
file.setWritable(true, true);
}
-
- public String[] getPrivateKeysFromPreferences() {
- String privateKeys =
- JSchCorePlugin.getPlugin().getPluginPreferences().getString(IConstants.KEY_PRIVATEKEY);
- if (privateKeys != null
- && privateKeys.trim().length() > 0) {
- return privateKeys.split(KEYS_SEPARATOR);
- } else {
- return new String[0];
- }
- }
private void addToPrivateKeysPreferences(SSHKeyPair keyPair) {
Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AbstractSSHKeyWizardPageModel.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -12,7 +12,10 @@
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
+import com.openshift.client.OpenShiftException;
+
/**
* @author Andre Dietisheim
*/
@@ -48,4 +51,14 @@
protected UserDelegate getUser() {
return user;
}
+
+ protected String checkedGetSSH2Home() throws OpenShiftException {
+ String ssh2Home = SSHUtils.getSSH2Home();
+ if (ssh2Home == null
+ || ssh2Home.trim().length() == 0) {
+ throw new OpenShiftException("Could not determine your ssh2 home directory");
+ }
+ return ssh2Home;
+ }
+
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyJob.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -32,7 +32,7 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- model.addConfiguredSSHKey();
+ model.addSSHKey();
return Status.OK_STATUS;
} catch (Exception e) {
return OpenShiftUIActivator.createErrorStatus(
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -30,8 +30,10 @@
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.common.ui.databinding.ParametrizableWizardPageSupport;
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -49,7 +51,7 @@
private AddSSHKeyWizardPageModel pageModel;
public AddSSHKeyWizardPage(UserDelegate user, IWizard wizard) {
- super("Add existing SSH Key", "Add an exiting SSH key to your OpenShift account",
+ super("Add existing SSH Key", "Add an exiting SSH key to your OpenShift user " + user.getUsername(),
"AddSSHKeysPage", wizard);
this.pageModel = new AddSSHKeyWizardPageModel(user);
}
@@ -109,6 +111,14 @@
dbc.addValidationStatusProvider(sshPublicKeyValidator);
ControlDecorationSupport.create(
sshPublicKeyValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
+
+ Link sshPrefsLink = new Link(parent, SWT.NONE);
+ sshPrefsLink
+ .setText("Please make sure that your private key for this public key is listed in the\n<a>SSH2 Preferences</a>");
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).applyTo(sshPrefsLink);
+ sshPrefsLink.addSelectionListener(onSshPrefs(dbc));
+
}
private SelectionListener onBrowse() {
@@ -126,6 +136,18 @@
};
}
+ private SelectionAdapter onSshPrefs(final DataBindingContext dbc) {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SSHUtils.openPreferencesPage(getShell());
+ // trigger revalidation after prefs were changed
+ dbc.updateTargets();
+ }
+ };
+ }
+
public IStatus addConfiguredSSHKey() {
try {
return WizardUtils.runInWizard(new AddSSHKeyJob(pageModel), getContainer());
@@ -133,4 +155,11 @@
return OpenShiftUIActivator.createErrorStatus("Could not add ssh key " + pageModel.getName() + ".");
}
}
+
+ @Override
+ protected void setupWizardPageSupport(DataBindingContext dbc) {
+ ParametrizableWizardPageSupport.create(
+ IStatus.ERROR | IStatus.INFO | IStatus.CANCEL, this,
+ dbc);
+ }
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPageModel.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -15,6 +15,7 @@
import java.io.IOException;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUserConfig;
import com.openshift.client.OpenShiftException;
import com.openshift.client.SSHPublicKey;
@@ -48,7 +49,7 @@
return getUser().hasSSHPublicKey(publicKeyContent);
}
- public void addConfiguredSSHKey() throws FileNotFoundException, OpenShiftException, IOException {
+ public void addSSHKey() throws FileNotFoundException, OpenShiftException, IOException {
SSHPublicKey sshPublicKey = new SSHPublicKey(getPublicKey());
getUser().putSSHKey(getName(), sshPublicKey);
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ISSHKeyWizardPageModel.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -31,7 +31,7 @@
public boolean hasPublicKey(String publicKeyContent);
- public void addConfiguredSSHKey() throws FileNotFoundException, OpenShiftException, IOException;
+ public void addSSHKey() throws FileNotFoundException, OpenShiftException, IOException;
public File getPublicKey();
}
\ No newline at end of file
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/ManageSSHKeysWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -14,10 +14,12 @@
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.viewers.ViewerProperties;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -33,6 +35,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.statushandlers.StatusManager;
@@ -41,6 +44,7 @@
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.utils.JobChainBuilder;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder;
import org.jboss.tools.openshift.express.internal.ui.utils.TableViewerBuilder.IColumnLabelProvider;
@@ -57,7 +61,8 @@
private TableViewer viewer;
public ManageSSHKeysWizardPage(UserDelegate user, IWizard wizard) {
- super("Manage SSH Keys", "Manage the SSH keys that are available to your OpenShift account",
+ super("Manage SSH Keys",
+ "Manage the SSH keys that are available to your OpenShift user\n" + user.getUsername(),
"ManageSSHKeysPage", wizard);
this.pageModel = new ManageSSHKeysWizardPageModel(user);
}
@@ -98,7 +103,19 @@
.align(SWT.FILL, SWT.FILL).applyTo(removeButton);
removeButton.setText("Remove...");
removeButton.addSelectionListener(onRemove());
+ ValueBindingBuilder
+ .bind(WidgetProperties.enabled().observe(removeButton))
+ .to(ViewerProperties.singleSelection().observe(viewer))
+ .converting(new Converter(IOpenShiftSSHKey.class, Boolean.class) {
+ @Override
+ public Object convert(Object fromObject) {
+ IOpenShiftSSHKey key = (IOpenShiftSSHKey) fromObject;
+ return key != null;
+ }
+ })
+ .in(dbc);
+
Composite filler = new Composite(sshKeysGroup, SWT.None);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).applyTo(filler);
@@ -108,6 +125,13 @@
.align(SWT.FILL, SWT.END).applyTo(refreshButton);
refreshButton.setText("Refresh...");
refreshButton.addSelectionListener(onRefresh());
+
+ Link sshPrefsLink = new Link(parent, SWT.NONE);
+ sshPrefsLink
+ .setText("Please make sure that your private keys for these public keys are listed in the\n<a>SSH2 Preferences</a>");
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).applyTo(sshPrefsLink);
+ sshPrefsLink.addSelectionListener(onSshPrefs());
}
private SelectionListener onRemove() {
@@ -163,11 +187,11 @@
@Override
public void widgetSelected(SelectionEvent e) {
- if(WizardUtils.openWizardDialog(new NewSSHKeyWizard(pageModel.getUser()), getShell())
+ if (WizardUtils.openWizardDialog(new NewSSHKeyWizard(pageModel.getUser()), getShell())
== Dialog.CANCEL) {
return;
}
-
+
try {
WizardUtils.runInWizard(
new RefreshViewerJob(),
@@ -246,6 +270,16 @@
};
}
+ private SelectionAdapter onSshPrefs() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SSHUtils.openPreferencesPage(getShell());
+ }
+ };
+ }
+
private class RemoveKeyJob extends Job {
private RemoveKeyJob() {
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -31,6 +31,7 @@
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
@@ -182,6 +183,14 @@
.in(dbc);
ControlDecorationSupport.create(
publicKeyBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
+
+ Link sshPrefsLink = new Link(parent, SWT.NONE);
+ sshPrefsLink
+ .setText("The private key of your new SSH key pair will get added to the \n<a>SSH2 Preferences</a>");
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).applyTo(sshPrefsLink);
+ sshPrefsLink.addSelectionListener(onSshPrefs());
+
}
private SelectionListener onBrowse(final Text ssh2HomeText) {
@@ -232,4 +241,15 @@
return OpenShiftUIActivator.createErrorStatus("Could not add ssh key " + pageModel.getName() + ".");
}
}
+
+ private SelectionAdapter onSshPrefs() {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SSHUtils.openPreferencesPage(getShell());
+ }
+ };
+ }
+
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/NewSSHKeyWizardPageModel.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -74,10 +74,10 @@
if (StringUtils.isEmpty(publicKeyName)) {
setPublicKeyName(privateKeyName + PUBLICKEY_SUFFIX);
} else {
- String publicKeyNameNoSuffix = StringUtils.getWithoutSuffix(publicKeyName, PUBLICKEY_SUFFIX);
+ String publicKeyNameNoSuffix = StringUtils.getWithoutSuffix(publicKeyName, PUBLICKEY_SUFFIX);
if (privateKeyName.startsWith(publicKeyNameNoSuffix)) {
setPublicKeyName(privateKeyName + PUBLICKEY_SUFFIX);
- }
+ }
}
}
@@ -96,17 +96,24 @@
public void setSSH2Home(String ssh2Home) {
firePropertyChange(PROPERTY_SSH2_HOME, this.ssh2Home, this.ssh2Home = ssh2Home);
}
-
+
public File getPublicKey() {
return new File(ssh2Home, publicKeyName);
}
-
- public void addConfiguredSSHKey() throws FileNotFoundException, OpenShiftException, IOException {
- String privateKeyPath = new File(ssh2Home, privateKeyName).getAbsolutePath();
- String publicKeyPath = new File(ssh2Home, publicKeyName).getAbsolutePath();
- SSHKeyPair keyPair = SSHKeyPair.create(privateKeyPathphrase, privateKeyPath, publicKeyPath);
+
+ public void addSSHKey() throws FileNotFoundException, OpenShiftException, IOException {
+ SSHKeyPair keyPair = createSSHKey();
+ SSHUtils.addToPrivateKeysPreferences(new File(keyPair.getPrivateKeyPath()));
getUser().putSSHKey(getName(), keyPair);
}
+ private SSHKeyPair createSSHKey() {
+ File privateKey = new File(ssh2Home, privateKeyName);
+ File publicKey = new File(ssh2Home, publicKeyName);
+ SSHKeyPair keyPair =
+ SSHKeyPair.create(privateKeyPathphrase, privateKey.getAbsolutePath(), publicKey.getAbsolutePath());
+ SSHUtils.setPrivateKeyPermissions(privateKey);
+ return keyPair;
+ }
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java 2012-09-20 12:46:19 UTC (rev 43861)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/databinding/SSHPublicKeyValidator.java 2012-09-20 13:52:33 UTC (rev 43862)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard.ssh.databinding;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -17,7 +18,9 @@
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUserConfig;
+import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.AddSSHKeyWizardPageModel;
@@ -51,12 +54,32 @@
} catch (FileNotFoundException e) {
return ValidationStatus.error("Could not load file: " + e.getMessage());
} catch (OpenShiftException e) {
- return ValidationStatus.error(filePath + "is not a valid public SSH key: " + e.getMessage());
+ return ValidationStatus.error(filePath + " is not a valid public SSH key: " + e.getMessage());
} catch (IOException e) {
return ValidationStatus.error("Could not load file: " + e.getMessage());
}
- return Status.OK_STATUS;
+ if (hasSSHConfigurationIdentityKey()) {
+ return ValidationStatus.warning(
+ NLS.bind("Your SSH config ({0}) contains fixed keys for OpenShift servers. " +
+ "This can override any Eclipse specific SSH key preferences.", new SSHUserConfig(SSHUtils.getSSH2Home()).getFile()));
+ } else if (!SSHUtils.publicKeyMatchesPrivateKeyInPreferences(new File(filePath))) {
+ return ValidationStatus.warning(
+ NLS.bind("Could not find the private key for your public key in the preferences. "
+ + "Make sure it is listed in the ssh2 preferences.", filePath));
+ }
+
+
+ return ValidationStatus.ok();
}
+ public boolean hasSSHConfigurationIdentityKey() {
+ try {
+ SSHUserConfig sshUserConfig = new SSHUserConfig(SSHUtils.getSSH2Home());
+ return sshUserConfig.hasLibraIdentifyFile();
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
}
More information about the jbosstools-commits
mailing list