Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryamanaka2007-11-02 07:15:50 +0000
committeryamanaka2007-11-02 07:15:50 +0000
commit0c26344515e9e48ef1b29163a86b43dc4d44c497 (patch)
tree630ed2aca73381736e36ee85da70c1aa0af61cac
parent1d7be6ab02d29c156451f5d221e25928167b10ba (diff)
downloadeclipse.platform.team-0c26344515e9e48ef1b29163a86b43dc4d44c497.tar.gz
eclipse.platform.team-0c26344515e9e48ef1b29163a86b43dc4d44c497.tar.xz
eclipse.platform.team-0c26344515e9e48ef1b29163a86b43dc4d44c497.zip
Bug 204138 [SSH2] UI for SSH2 should be pushed down from CVS to jsch.
-rw-r--r--bundles/org.eclipse.jsch.core/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.jsch.core/plugin.xml1
-rw-r--r--bundles/org.eclipse.jsch.core/schema/authenticator.exsd88
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchLocation.java95
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchService.java38
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IPasswordStore.java37
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserAuthenticator.java134
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserInfo.java47
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java1
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchLocation.java128
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchProvider.java124
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/NullUserAuthenticator.java54
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/UserInfoImpl.java225
-rw-r--r--bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java6
-rw-r--r--bundles/org.eclipse.jsch.ui/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.jsch.ui/plugin.xml9
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java61
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java18
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java30
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java338
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java296
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java241
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties16
-rw-r--r--bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java27
24 files changed, 1931 insertions, 87 deletions
diff --git a/bundles/org.eclipse.jsch.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.jsch.core/META-INF/MANIFEST.MF
index 563d107e4..db5e47773 100644
--- a/bundles/org.eclipse.jsch.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.jsch.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jsch.core;singleton:=true
-Bundle-Version: 1.0.100.qualifier
+Bundle-Version: 1.1.100.qualifier
Bundle-Activator: org.eclipse.jsch.internal.core.JSchCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.jsch.core/plugin.xml b/bundles/org.eclipse.jsch.core/plugin.xml
index d2a2dbd9b..d9ae796c6 100644
--- a/bundles/org.eclipse.jsch.core/plugin.xml
+++ b/bundles/org.eclipse.jsch.core/plugin.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
+ <extension-point id="authenticator" name="%Authenticator" schema="schema/authenticator.exsd" />
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
diff --git a/bundles/org.eclipse.jsch.core/schema/authenticator.exsd b/bundles/org.eclipse.jsch.core/schema/authenticator.exsd
new file mode 100644
index 000000000..4339d13d2
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/schema/authenticator.exsd
@@ -0,0 +1,88 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.jsch.core">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.jsch.core" id="authenticator" name="Authenticator"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="authenticator"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="authenticator">
+ <complexType>
+ <sequence>
+ <element ref="run"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="run">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchLocation.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchLocation.java
new file mode 100644
index 000000000..1467617c6
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchLocation.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007 JCraft,Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jsch.core;
+
+import org.eclipse.jsch.internal.core.IUserAuthenticator;
+
+/**
+ * This interface provides access to the specific portions of
+ * the location string for use by ssh2 connection
+ * and the user authenticator.
+ *
+ * It is not intended to implemented by clients.
+ *
+ * @see IUserAuthenticator
+ * @see IPasswordStore
+ * @see org.eclipse.jsch.internal.core.JSchLocation
+ * @since 1.1
+ */
+public interface IJSchLocation{
+
+ /**
+ * port value which indicates to a connection method to use the default port
+ */
+ public static int USE_DEFAULT_PORT=0;
+
+ /**
+ * Returns the host where the repository is located
+ * @return host name
+ */
+ public String getHost();
+
+ /**
+ * Returns the port to connect to or USE_DEFAULT_PORT if
+ * the connection method is to use its default port.
+ * @return port number
+ */
+ public int getPort();
+
+ /**
+ * Sets the user information used for this location
+ * @param username user name
+ */
+ public void setUsername(String username);
+
+ /**
+ * Return the user name
+ * @return user name
+ */
+ public String getUsername();
+
+ /**
+ * Sets the user password used for this location
+ * @param password password
+ */
+ public void setPassword(String password);
+
+ /**
+ * Return the password
+ * @return password
+ */
+ public String getPassword();
+
+ /**
+ * Sets the comment for this location. This comment will be displayed
+ * in prompting for the password.
+ * @param comment
+ */
+ public void setComment(String comment);
+
+ /**
+ * Return the comment
+ * @return comment
+ */
+ public String getComment();
+
+ /**
+ * Sets the password store used for this location
+ * @param store password store
+ */
+ public void setPasswordStore(IPasswordStore store);
+
+ /**
+ * Return the password store.
+ * @return password store.
+ */
+ public IPasswordStore getPasswordStore();
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchService.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchService.java
index 208a7af15..5e54bcf1f 100644
--- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchService.java
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IJSchService.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Atsuhiko Yamanaka, JCraft,Inc. - adding methods for using IJSchLocation
*******************************************************************************/
package org.eclipse.jsch.core;
@@ -44,6 +45,27 @@ public interface IJSchService{
throws JSchException;
/**
+ *
+ * Create a {@link Session} that can be used to make SSH2 connections. This method ensures that
+ * all preferences are properly propagated into JSch before creating the session and also
+ * ensures that the session uses the appropriate proxy settings.
+ * <p>
+ * Calling this method does not connect the session (see {@link #connect(Session, int, IProgressMonitor)}, if connection
+ * throws an exception, clients should check to see if the session is still connected (see {@link Session#isConnected()}.
+ * If it is, they should call {@link Session#disconnect()}.
+ *
+ *
+ * @param location the location which corresponds to user@host:port
+ * @param uinfo an instance of {@link UserInfo} or <code>null</code> if
+ * the internal UserInfo implementation should be used.
+ * @return the created session
+ * @throws JSchException if errors occur
+ * @since 1.1
+ */
+ public abstract Session createSession(IJSchLocation location, UserInfo uinfo)
+ throws JSchException;
+
+ /**
* Connect the session using a responsive socket factory. The timeout value is used
* for socket creation only. Clients that desire a timeout on the session must
* call {@link Session#setTimeout(int)}. If session connection fails due to an exception,
@@ -87,4 +109,20 @@ public interface IJSchService{
public abstract void connect(Proxy proxy, String host, int port, int timeout,
IProgressMonitor monitor) throws JSchException;
+ /**
+ * Get the IJSchLocation according to given user name, host name and port number.
+ *
+ * @param user user name for ssh2 connection
+ * @param host host name for ssh2 connection
+ * @param port port number for ssh2 connection
+ * @return the created IJSchLocation
+ * @since 1.1
+ */
+ public abstract IJSchLocation getLocation(String user, String host, int port);
+
+ /**
+ * Get the singleton instance of JSch allocated in jsch.core plug-in internally.
+ * @return the singleton instance of JSch.
+ */
+ public abstract JSch getJSch();
} \ No newline at end of file
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IPasswordStore.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IPasswordStore.java
new file mode 100644
index 000000000..2f0ddeb39
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/IPasswordStore.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2007 JCraft,Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JCraft,Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jsch.core;
+
+/**
+ * This interface abstracts the password store. The given password
+ * will be stored to via this interface.
+ * @since 1.1
+ */
+public interface IPasswordStore{
+ /**
+ * The cached password should be flushed.
+ * @param location
+ */
+ public void clear(IJSchLocation location);
+
+ /**
+ * This method will check if the password is cached or not.
+ * @param location
+ * @return whether the password is cached.
+ */
+ public boolean isCached(IJSchLocation location);
+
+ /*
+ * The new password "location.getPassword()" will be
+ * cached.
+ */
+ public void update(IJSchLocation location);
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserAuthenticator.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserAuthenticator.java
new file mode 100644
index 000000000..379de39bc
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserAuthenticator.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - adding promptForKeyboradInteractive method
+ * - copying this class from cvs.core plug-in.
+ *******************************************************************************/
+package org.eclipse.jsch.internal.core;
+
+import org.eclipse.jsch.core.IJSchLocation;
+
+/**
+ * IUserAuthenticators are used to ensure that the user
+ * is validated for ssh2 access to the remote.
+ * @since 1.1
+ */
+public interface IUserAuthenticator{
+
+ /**
+ * Button id for an "Ok" button (value 0).
+ */
+ public int OK_ID=0;
+
+ /**
+ * Button id for a "Cancel" button (value 1).
+ */
+ public int CANCEL_ID=1;
+
+ /**
+ * Button id for a "Yes" button (value 2).
+ */
+ public int YES_ID=2;
+
+ /**
+ * Button id for a "No" button (value 3).
+ */
+ public int NO_ID=3;
+
+ /**
+ * Constant for a prompt with no type (value 0).
+ */
+ public final static int NONE=0;
+
+ /**
+ * Constant for an error prompt (value 1).
+ */
+ public final static int ERROR=1;
+
+ /**
+ * Constant for an information prompt (value 2).
+ */
+ public final static int INFORMATION=2;
+
+ /**
+ * Constant for a question prompt (value 3).
+ */
+ public final static int QUESTION=3;
+
+ /**
+ * Constant for a warning dialog (value 4).
+ */
+ public final static int WARNING=4;
+
+ /**
+ * Authenticates the user for access to a given repository.
+ * The obtained values for user name and password will be placed
+ * into the supplied user info object. Implementors are allowed to
+ * save user names and passwords. The user should be prompted for
+ * user name and password if there is no saved one, or if <code>retry</code>
+ * is <code>true</code>.
+ *
+ * @param location The repository location to authenticate the user for or <code>null</code>
+ * if this authentication is not for a CVS repository location.
+ * @param userInfo The object to place user validation information into.
+ * @param message An optional message to display if, e.g., previous authentication failed.
+ */
+ public void promptForUserInfo(IJSchLocation location,
+ IUserInfo userInfo, String message);
+
+ /**
+ * Prompts the user for a number values using text fields. The labels are provided in
+ * the <core>prompt</code> array. Implementors will return the entered values, or null if
+ * the user cancel the prompt.
+ *
+ * @param location The repository location to authenticate the user for or <code>null</code>
+ * if this authentication is not for a CVS repository location.
+ * @param destination The destination in the format like username@hostname:port
+ * @param name A name about this dialog.
+ * @param instruction A message for the instruction.
+ * @param prompt Labels for text fields.
+ * @param echo the array to show which fields are secret.
+ * @return the entered values, or null if the user canceled.
+ */
+ public String[] promptForKeyboradInteractive(IJSchLocation location,
+ String destination, String name, String instruction, String[] prompt,
+ boolean[] echo);
+
+ /**
+ * Prompts the authenticator for additional information regarding this authentication
+ * request. A default implementation of this method should return the <code>defaultResponse</code>,
+ * whereas alternate implementations could prompt the user with a dialog.
+ *
+ * @param location the repository location for this authentication or <code>null</code>
+ * if this authentication is not for a CVS repository location.
+ * @param promptType one of the following values:
+ * <ul>
+ * <li> <code>NONE</code> for a unspecified prompt type </li>
+ * <li> <code>ERROR</code> for an error prompt </li>
+ * <li> <code>INFORMATION</code> for an information prompt </li>
+ * <li> <code>QUESTION </code> for a question prompt </li>
+ * <li> <code>WARNING</code> for a warning prompt </li>
+ * </ul>
+ * @param title the prompt title that could be displayed to the user
+ * @param message the prompt
+ * @param promptResponses the possible responses to the prompt
+ * @param defaultResponseIndex the default response to the prompt
+ * @return the response to the prompt
+ */
+ public int prompt(IJSchLocation location, int promptType,
+ String title, String message, int[] promptResponses,
+ int defaultResponseIndex);
+
+ /**
+ * The host key for the given location has changed.
+ * @param location
+ * @return true if new host key should be accepted
+ */
+ public boolean promptForHostKeyChange(IJSchLocation location);
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserInfo.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserInfo.java
new file mode 100644
index 000000000..c979d58da
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IUserInfo.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - copying this class from cvs.core plug-in
+ *******************************************************************************/
+package org.eclipse.jsch.internal.core;
+/**
+ * Instances of this class represent a user name password pair.
+ * Both values can be set and the user name can be retrieved.
+ * However, it is possible that the user name is not mutable.
+ * Users must check before trying to set the user name.
+ *
+ * Clients are not expected to implement this interface
+ * @since 1.1
+ */
+public interface IUserInfo{
+ /**
+ * Get the user name for this user.
+ * @return user name
+ */
+ public String getUsername();
+
+ /**
+ * Sets the user name for this user. This should not be called if
+ * isUsernameMutable() returns false.
+ * @param username a user name for this user
+ */
+ public void setUsername(String username);
+
+ /**
+ * Return true if the user name is mutable. If not, setUsername should not be called.
+ * @return a flag for isUsernameMutable
+ */
+ public boolean isUsernameMutable();
+
+ /**
+ * Sets the password for this user.
+ * @param password a password for this user
+ */
+ public void setPassword(String password);
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java
index 1eda19b5b..040e0d63c 100644
--- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.jsch.internal.core;
-// import org.eclipse.core.runtime.Plugin;
import java.util.Hashtable;
import java.util.Map;
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchLocation.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchLocation.java
new file mode 100644
index 000000000..4bc5e6a38
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchLocation.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2007 JCraft,Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jsch.internal.core;
+
+import org.eclipse.core.runtime.*;
+import org.eclipse.jsch.core.IJSchLocation;
+import org.eclipse.jsch.core.IPasswordStore;
+
+/**
+ * This class implements IJSchLocation interface.
+ * @since 1.1
+ */
+public class JSchLocation extends PlatformObject implements IJSchLocation{
+ /**
+ * port value which indicates to a connection method to use the default port
+ */
+ private static int DEFAULT_PORT=22;
+
+ private String user;
+ private String password;
+ private String host;
+ private int port=DEFAULT_PORT;
+ private boolean userFixed=true;
+ private String comment=null;
+ private IPasswordStore passwordStore=null;
+
+ /*
+ * Create a JSchLocation from its composite parts.
+ */
+ public JSchLocation(String user, String host, int port){
+ this.user=user;
+ this.host=host;
+ this.port=port;
+ }
+
+ public JSchLocation(String user, String host){
+ this(user, host, DEFAULT_PORT);
+ }
+
+ /**
+ * @see IJSchLocation#getHost()
+ */
+ public String getHost(){
+ return host;
+ }
+
+ /**
+ * @see IJSchLocation#getPort()
+ */
+ public int getPort(){
+ return port;
+ }
+
+ /*
+ * @see IJSchLocation#setUsername(String)
+ */
+ public void setUsername(String user){
+ if(userFixed)
+ throw new UnsupportedOperationException();
+ this.user=user;
+ }
+
+ /**
+ * @see IJSchLocation#getUsername()
+ */
+ public String getUsername(){
+ return user==null ? "" : user; //$NON-NLS-1$
+ }
+
+ /**
+ * @see IJSchLocation#setPassword(String)
+ */
+ public void setPassword(String password){
+ if(password!=null)
+ this.password=password;
+ }
+
+ /**
+ * @see IJSchLocation#getPassword()
+ */
+ public String getPassword(){
+ return password;
+ }
+
+ /**
+ * @see IJSchLocation#setComment(String comment)
+ */
+ public void setComment(String comment){
+ this.comment=comment;
+ }
+
+ /**
+ * @see IJSchLocation#getComment()
+ */
+ public String getComment(){
+ return comment;
+ }
+
+ /**
+ * @see IJSchLocation#setPasswordStore(IPasswordStore store)
+ */
+ public void setPasswordStore(IPasswordStore store){
+ this.passwordStore=store;
+ }
+
+ /**
+ * @see IJSchLocation#getPasswordStore()
+ */
+ public IPasswordStore getPasswordStore(){
+ return passwordStore;
+ }
+
+ /**
+ * Implementation of inherited toString()
+ */
+ public String toString(){
+ return user
+ +"@"+host+((port==DEFAULT_PORT) ? "" : ":"+(new Integer(port).toString())); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchProvider.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchProvider.java
index 305aa6b7c..628867287 100644
--- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchProvider.java
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchProvider.java
@@ -7,11 +7,19 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Atsuhiko Yamanaka, JCraft,Inc. - adding methods referring to IJSchLocation
*******************************************************************************/
package org.eclipse.jsch.internal.core;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jsch.core.IJSchService;
+import org.eclipse.jsch.core.IJSchLocation;
+import org.eclipse.osgi.util.NLS;
import com.jcraft.jsch.*;
@@ -20,7 +28,7 @@ import com.jcraft.jsch.*;
* before a {@link Session} is created.
* @since 1.0
*/
-public class JSchProvider implements IJSchService {
+class JSchProvider implements IJSchService {
private static JSchProvider instance;
@@ -28,8 +36,6 @@ public class JSchProvider implements IJSchService {
* @see org.eclipse.jsch.core.IJSchService#createSession(java.lang.String, int, java.lang.String)
*/
public Session createSession(String host, int port, String username) throws JSchException {
- if(port == -1)
- port = IConstants.SSH_DEFAULT_PORT;
if(JSchCorePlugin.getPlugin().isNeedToLoadKnownHosts()){
JSchCorePlugin.getPlugin().loadKnownHosts();
@@ -43,22 +49,72 @@ public class JSchProvider implements IJSchService {
}
/* (non-Javadoc)
+ * @see org.eclipse.jsch.core.IJSchService#createSession(IJSchLocation location, UserInfo uinfo)
+ */
+ public Session createSession(IJSchLocation location, UserInfo uinfo) throws JSchException {
+
+ Session session=createSession(location.getHost(), location.getPort(), location.getUsername());
+
+ if(uinfo==null){
+ IUserAuthenticator authenticator=getPluggedInAuthenticator();
+ if(authenticator==null)
+ authenticator=new NullUserAuthenticator();
+ uinfo=new UserInfoImpl(location, authenticator, (JSchCorePlugin.getPlugin().getTimeout() * 1000));
+ }
+ if(uinfo!=null)
+ session.setUserInfo(uinfo);
+
+ return session;
+ }
+
+ public Session createSession(IJSchLocation location) throws JSchException {
+ return createSession(location, null);
+ }
+
+ /**
* @see org.eclipse.jsch.core.IJSchService#connect(com.jcraft.jsch.Session, int, org.eclipse.core.runtime.IProgressMonitor)
*/
public void connect(Session session, int timeout,
IProgressMonitor monitor) throws JSchException{
session.setSocketFactory(new ResponsiveSocketFactory(monitor, timeout));
+
+ UserInfo ui=session.getUserInfo();
+
+ if(ui!=null && (ui instanceof UserInfoImpl))
+ ((UserInfoImpl)ui).aboutToConnect();
+
try{
session.connect();
}
catch(JSchException e){
+
+ // Try again since the previous prompt may have obtained
+ // the proper credential from the user.
+ // This logic had been implemented in org.eclipse.team.internal.ccvs.ssh2.JSchSession#getSession.
+ if(isAuthenticationFailure(e)
+ &&ui!=null&&(ui instanceof UserInfoImpl)
+ &&hasPromptExceededTimeout(session)
+ &&((UserInfoImpl)ui).incReuse()==0){
+ String host=session.getHost();
+ String user=session.getUserName();
+ int port=session.getPort();
+ session=Utils.createSession(getJSch(), user, host, port);
+ session.setUserInfo(ui);
+ session.setTimeout(timeout);
+ connect(session, timeout, monitor);
+ return;
+ }
+
if(session.isConnected())
session.disconnect();
throw e;
}
+
+ if(ui!=null && (ui instanceof UserInfoImpl))
+ ((UserInfoImpl)ui).connectionMade();
}
- /* (non-Javadoc)
+ /**
* @see org.eclipse.jsch.core.IJSchService#getProxyForHost(java.lang.String, java.lang.String)
*/
public Proxy getProxyForHost(String host, String proxyType) {
@@ -72,7 +128,7 @@ public class JSchProvider implements IJSchService {
}
/* (non-Javadoc)
- * @see org.eclipse.jsch.core.IJSchService#connect(com.jcraft.jsch.Proxy, java.lang.String, java.lang.String, int, org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.jsch.core.IJSchService#connect(com.jcraft.jsch.Proxy, java.lang.String, int, int, org.eclipse.core.runtime.IProgressMonitor)
*/
public void connect(Proxy proxy, String host, int port, int timeout,
IProgressMonitor monitor) throws JSchException {
@@ -86,5 +142,63 @@ public class JSchProvider implements IJSchService {
new JSchException(e.getMessage());
}
}
+
+ /**
+ * Search for an instance of IUserAuthenticator provided from other plug-in.
+ * @see org.eclipse.jsch.internal.ui.authenticator.WorkbenchUserAuthenticator
+ * @return an instance of IUserAuthenticator.
+ */
+ private IUserAuthenticator getPluggedInAuthenticator(){
+ IExtension[] extensions=Platform.getExtensionRegistry().getExtensionPoint(
+ JSchCorePlugin.ID, JSchCorePlugin.PT_AUTHENTICATOR).getExtensions();
+ if(extensions.length==0)
+ return null;
+ IExtension extension=extensions[0];
+ IConfigurationElement[] configs=extension.getConfigurationElements();
+ if(configs.length==0){
+ JSchCorePlugin
+ .log(
+ IStatus.ERROR,
+ NLS
+ .bind(
+ "User autheticator {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$
+ return null;
+ }
+ try{
+ IConfigurationElement config=configs[0];
+ return (IUserAuthenticator)config.createExecutableExtension("run");//$NON-NLS-1$
+ }
+ catch(CoreException ex){
+ JSchCorePlugin
+ .log(
+ IStatus.ERROR,
+ NLS
+ .bind(
+ "Unable to instantiate user authenticator {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$
+ return null;
+ }
+ }
+
+ public JSch getJSch(){
+ return JSchCorePlugin.getPlugin().getJSch();
+ }
+ private boolean isAuthenticationFailure(JSchException ee){
+ return ee.getMessage().equals("Auth fail"); //$NON-NLS-1$
+ }
+
+ private boolean hasPromptExceededTimeout(Session session){
+ if(session.getUserInfo()==null || !(session.getUserInfo() instanceof UserInfoImpl))
+ return false;
+ return ((UserInfoImpl)session.getUserInfo()).hasPromptExceededTimeout();
+ }
+
+ /**
+ * @see org.eclipse.jsch.core.IJSchService#getLocation(String user, String host, int port)
+ */
+ public IJSchLocation getLocation(String user, String host, int port){
+ IJSchLocation location=null;
+ location=new JSchLocation(user, host, port);
+ return location;
+ }
}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/NullUserAuthenticator.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/NullUserAuthenticator.java
new file mode 100644
index 000000000..b5f337fd2
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/NullUserAuthenticator.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2007 JCraft,Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jsch.internal.core;
+
+import org.eclipse.jsch.core.IJSchLocation;
+
+/**
+ * This class will be used whenever nobody gives
+ * the implementation of IUserAuthenticator.
+ * @since 1.1
+ */
+class NullUserAuthenticator implements IUserAuthenticator{
+
+ /**
+ * @see IUserAuthenticator#prompt(IJSchLocation location, int promptType, String title,
+ String message, int[] promptResponses, int defaultResponseIndex)
+ */
+ public int prompt(IJSchLocation location, int promptType, String title,
+ String message, int[] promptResponses, int defaultResponseIndex){
+ return IUserAuthenticator.CANCEL_ID;
+ }
+
+ /**
+ * @see IUserAuthenticator#promptForHostKeyChange(IJSchLocation location)
+ */
+ public boolean promptForHostKeyChange(IJSchLocation location){
+ return false;
+ }
+
+ /**
+ * @see IUserAuthenticator#promptForKeyboradInteractive(IJSchLocation location, String destination, String name, String instruction, String[] prompt, boolean[] echo)
+ */
+ public String[] promptForKeyboradInteractive(IJSchLocation location,
+ String destination, String name, String instruction, String[] prompt,
+ boolean[] echo){
+ return null;
+ }
+
+ /**
+ * @see IUserAuthenticator#promptForUserInfo(IJSchLocation, IUserInfo, String)
+ */
+ public void promptForUserInfo(IJSchLocation location, IUserInfo userInfo,
+ String message){
+ // no operation
+ }
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/UserInfoImpl.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/UserInfoImpl.java
new file mode 100644
index 000000000..4e2821014
--- /dev/null
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/UserInfoImpl.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - copying this class from o.e.team.cvs.ssh2.JSchSession.
+ *******************************************************************************/
+package org.eclipse.jsch.internal.core;
+
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jsch.core.IJSchLocation;
+
+import com.jcraft.jsch.UIKeyboardInteractive;
+
+/**
+ * User information delegates to the IUserAuthenticator. This allows
+ * head-less access to the connection method.
+ * @since 1.1
+ */
+class UserInfoImpl implements com.jcraft.jsch.UserInfo, UIKeyboardInteractive{
+ private String username;
+ private String password;
+ private String passphrase;
+ private IJSchLocation location;
+ private IUserAuthenticator authenticator;
+ private int attemptCount;
+ private boolean passwordChanged;
+
+ private long startTime;
+ private long endTime;
+ private boolean prompting;
+ private long timeout;
+
+ private int reuse=0;
+
+ UserInfoImpl(IJSchLocation location, IUserAuthenticator authenticator, long timeout){
+ this.location=location;
+ this.username=location.getUsername();
+ this.password=location.getPassword();
+ this.authenticator=authenticator;
+ this.timeout=timeout;
+ }
+
+ public String getPassword(){
+ return password;
+ }
+
+ public String getPassphrase(){
+ return passphrase;
+ }
+
+ public boolean promptYesNo(String str){
+ int prompt=authenticator.prompt(location, IUserAuthenticator.QUESTION,
+ Messages.JSchSession_5, str, new int[] {IUserAuthenticator.YES_ID,
+ IUserAuthenticator.NO_ID}, 0 //yes the default
+ );
+ return prompt==0;
+ }
+
+ private String promptSecret(String message, boolean includeLocation){
+ final String[] _password=new String[1];
+ final String username=location.getUsername();
+ IUserInfo info=new IUserInfo(){
+ public String getUsername(){
+ return username;
+ }
+
+ public boolean isUsernameMutable(){
+ return false;
+ }
+
+ public void setPassword(String password){
+ _password[0]=password;
+ }
+
+ public void setUsername(String username){
+ //
+ }
+ };
+ try{
+ authenticator.promptForUserInfo(includeLocation ? location : null,
+ info, message);
+ }
+ catch(OperationCanceledException e){
+ _password[0]=null;
+ throw e;
+ }
+ return _password[0];
+ }
+
+ public boolean promptPassphrase(String message){
+ try{
+ startTimer();
+ String _passphrase=promptSecret(message, false);
+ if(_passphrase!=null){
+ passphrase=_passphrase;
+ }
+ return _passphrase!=null;
+ }
+ catch(OperationCanceledException e){
+ // The prompt was canceled, but the next authentication
+ // method should be tried.
+ return false;
+ }
+ finally{
+ endTimer();
+ }
+ }
+
+ public boolean promptPassword(String message){
+ try{
+ startTimer();
+
+ String _password=promptSecret(message, true);
+ if(_password!=null){
+ password=_password;
+ // Cache the password with the repository location on the memory.
+ if(location!=null)
+ location.setPassword(password);
+ }
+ return _password!=null;
+ }
+ finally{
+ endTimer();
+ }
+ }
+
+ public void showMessage(String message){
+ authenticator.prompt(location, IUserAuthenticator.INFORMATION,
+ Messages.JSchSession_5, message,
+ new int[] {IUserAuthenticator.OK_ID}, IUserAuthenticator.OK_ID);
+ }
+
+ public String[] promptKeyboardInteractive(String destination, String name,
+ String instruction, String[] prompt, boolean[] echo){
+ if(prompt.length==0){
+ // No need to prompt, just return an empty String array
+ return new String[0];
+ }
+ try{
+ startTimer();
+
+ if(attemptCount==0&&password!=null&&prompt.length==1
+ &&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$
+ // Return the provided password the first time but always prompt on subsequent tries
+ attemptCount++;
+ return new String[] {password};
+ }
+ String[] result=authenticator.promptForKeyboradInteractive(location,
+ destination, name, instruction, prompt, echo);
+ if(result==null)
+ return null; // canceled
+ if(result.length==1&&prompt.length==1
+ &&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$
+ password=result[0];
+ passwordChanged=true;
+ }
+ attemptCount++;
+ return result;
+ }
+ catch(OperationCanceledException e){
+ return null;
+ }
+ finally{
+ endTimer();
+ }
+ }
+
+ /**
+ * Callback to indicate that a connection is about to be attempted
+ */
+ public void aboutToConnect(){
+ attemptCount=0;
+ passwordChanged=false;
+ }
+
+ /**
+ * Callback to indicate that a connection was made
+ */
+ public void connectionMade(){
+ attemptCount=0;
+ if(passwordChanged&&password!=null&&location!=null){
+ // We were prompted for and returned a password so record it with the location
+ location.setPassword(password);
+ }
+ }
+
+ private synchronized void startTimer(){
+ prompting=true;
+ startTime=System.currentTimeMillis();
+ }
+
+ private synchronized void endTimer(){
+ prompting=false;
+ endTime=System.currentTimeMillis();
+ }
+
+ public long getLastDuration(){
+ return Math.max(0, endTime-startTime);
+ }
+
+ public boolean hasPromptExceededTimeout(){
+ if(!isPrompting()){
+ return getLastDuration()>timeout;
+ }
+ return false;
+ }
+
+ public boolean isPrompting(){
+ return prompting;
+ }
+
+ public synchronized int incReuse(){
+ return reuse++;
+ }
+
+ String getUsername(){
+ return username;
+ }
+}
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java
index 929c8c06f..b073d692d 100644
--- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java
+++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java
@@ -20,6 +20,10 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import com.jcraft.jsch.*;
+/**
+ *
+ * @since 1.0
+ */
public class Utils{
public static String loadPrivateKeys(JSch jsch, String current_pkeys){
@@ -68,6 +72,8 @@ public class Utils{
public static Session createSession(JSch jsch, String username,
String hostname, int port) throws JSchException{
+ if(port == -1)
+ port = IConstants.SSH_DEFAULT_PORT;
Session session=jsch.getSession(username, hostname, port);
setProxy(session);
Hashtable config=new Hashtable();
diff --git a/bundles/org.eclipse.jsch.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.jsch.ui/META-INF/MANIFEST.MF
index cdf220d64..67c594de8 100644
--- a/bundles/org.eclipse.jsch.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.jsch.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jsch.ui;singleton:=true
-Bundle-Version: 1.0.100.qualifier
+Bundle-Version: 1.1.100.qualifier
Bundle-Activator: org.eclipse.jsch.internal.ui.JSchUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.jsch.ui/plugin.xml b/bundles/org.eclipse.jsch.ui/plugin.xml
index fa77f3cca..7297d8ac3 100644
--- a/bundles/org.eclipse.jsch.ui/plugin.xml
+++ b/bundles/org.eclipse.jsch.ui/plugin.xml
@@ -19,5 +19,14 @@
<keywordReference id="org.eclipse.jsch.ui.ssh2"/>
</page>
</extension>
+
+ <extension
+ point="org.eclipse.jsch.core.authenticator">
+ <authenticator>
+ <run
+ class="org.eclipse.jsch.internal.ui.authenticator.WorkbenchUserAuthenticator">
+ </run>
+ </authenticator>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java
index 7ca8a2b82..0b3b64325 100644
--- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java
@@ -83,66 +83,7 @@ public class JSchUIPlugin extends AbstractUIPlugin{
* Initializes the table of images used in this plugin.
*/
private void initializeImages() {
- /*
- // objects
- createImageDescriptor(IUIConstants.IMG_REPOSITORY);
- createImageDescriptor(IUIConstants.IMG_REFRESH);
- createImageDescriptor(IUIConstants.IMG_REFRESH_ENABLED);
- createImageDescriptor(IUIConstants.IMG_REFRESH_DISABLED);
- createImageDescriptor(IUIConstants.IMG_LINK_WITH_EDITOR);
- createImageDescriptor(IUIConstants.IMG_LINK_WITH_EDITOR_ENABLED);
- createImageDescriptor(IUIConstants.IMG_COLLAPSE_ALL);
- createImageDescriptor(IUIConstants.IMG_COLLAPSE_ALL_ENABLED);
- createImageDescriptor(IUIConstants.IMG_NEWLOCATION);
- createImageDescriptor(IUIConstants.IMG_CVSLOGO);
- createImageDescriptor(IUIConstants.IMG_TAG);
- createImageDescriptor(IUIConstants.IMG_MODULE);
- createImageDescriptor(IUIConstants.IMG_CLEAR);
- createImageDescriptor(IUIConstants.IMG_CLEAR_ENABLED);
- createImageDescriptor(IUIConstants.IMG_CLEAR_DISABLED);
- createImageDescriptor(IUIConstants.IMG_BRANCHES_CATEGORY);
- createImageDescriptor(IUIConstants.IMG_VERSIONS_CATEGORY);
- createImageDescriptor(IUIConstants.IMG_DATES_CATEGORY);
- createImageDescriptor(IUIConstants.IMG_PROJECT_VERSION);
- createImageDescriptor(IUIConstants.IMG_WIZBAN_MERGE);
- createImageDescriptor(IUIConstants.IMG_WIZBAN_SHARE);
- createImageDescriptor(IUIConstants.IMG_WIZBAN_DIFF);
- createImageDescriptor(IUIConstants.IMG_WIZBAN_KEYWORD);
- createImageDescriptor(IUIConstants.IMG_WIZBAN_NEW_LOCATION);
- createImageDescriptor(IUIConstants.IMG_WIZBAN_IMPORT);
- createImageDescriptor(IUIConstants.IMG_MERGEABLE_CONFLICT);
- createImageDescriptor(IUIConstants.IMG_QUESTIONABLE);
- createImageDescriptor(IUIConstants.IMG_MERGED);
- createImageDescriptor(IUIConstants.IMG_EDITED);
- createImageDescriptor(IUIConstants.IMG_NO_REMOTEDIR);
- createImageDescriptor(IUIConstants.IMG_CVS_CONSOLE);
- createImageDescriptor(IUIConstants.IMG_DATE);
- createImageDescriptor(IUIConstants.IMG_CHANGELOG);
- createImageDescriptor(IUIConstants.IMG_FILTER_HISTORY);
- createImageDescriptor(IUIConstants.IMG_LOCALMODE);
- createImageDescriptor(IUIConstants.IMG_LOCALREMOTE_MODE);
- createImageDescriptor(IUIConstants.IMG_REMOTEMODE);
- createImageDescriptor(IUIConstants.IMG_LOCALMODE_DISABLED);
- createImageDescriptor(IUIConstants.IMG_LOCALREMOTE_MODE_DISABLED);
- createImageDescriptor(IUIConstants.IMG_REMOTEMODE_DISABLED);
- createImageDescriptor(IUIConstants.IMG_LOCALREVISION_TABLE);
- createImageDescriptor(IUIConstants.IMG_REMOTEREVISION_TABLE);
- createImageDescriptor(IUIConstants.IMG_COMPARE_VIEW);
- */
-
createImageDescriptor(IUIConstants.IMG_KEY_LOCK);
-
- /*
- // special
- createImageDescriptor("glyphs/glyph1.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph2.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph3.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph4.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph5.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph6.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph7.gif"); //$NON-NLS-1$
- createImageDescriptor("glyphs/glyph8.gif"); //$NON-NLS-1$
- */
}
/**
@@ -170,10 +111,8 @@ public class JSchUIPlugin extends AbstractUIPlugin{
public IJSchService getJSchService() {
return (IJSchService)tracker.getService();
}
-
public URL getImageUrl(String relative){
return FileLocator.find(Platform.getBundle(ID), new Path(IUIConstants.ICON_PATH + relative), null);
}
-
}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java
index b7fe25182..26dd6c1a1 100644
--- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java
@@ -90,6 +90,9 @@ public class Messages extends NLS{
public static String KeyboardInteractiveDialog_4;
public static String KeyboardInteractiveDialog_5;
public static String KeyboardInteractiveDialog_6;
+ public static String KeyboradInteractiveDialog_message;
+ public static String KeyboardInteractiveDialog_labelRepository;
+
public static String PreferencePage_0;
public static String PreferencePage_1;
public static String UserInfoPrompter_0;
@@ -100,4 +103,19 @@ public class Messages extends NLS{
public static String UserValidationDialog_3;
public static String UserValidationDialog_4;
public static String UserValidationDialog_5;
+
+ public static String UserValidationDialog_6;
+ public static String UserValidationDialog_7;
+
+ 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 WorkbenchUserAuthenticator_cancelled;
+ public static String WorkbenchUserAuthenticator_1;
+ public static String WorkbenchUserAuthenticator_2;
+ public static String WorkbenchUserAuthenticator_The_operation_was_canceled_by_the_user_1;
}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java
new file mode 100644
index 000000000..d9ef67db2
--- /dev/null
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - copying this class from o.e.team.cvs.ui plug-in.
+ *******************************************************************************/
+package org.eclipse.jsch.internal.ui.authenticator;
+
+import org.eclipse.jsch.internal.ui.JSchUIPlugin;
+
+/**
+ * Here's how to reference the help context in code:
+ *
+ * WorkbenchHelp.setHelp(actionOrControl, IHelpContextIds.NAME_DEFIED_BELOW);
+ * @since 1.1
+ */
+public interface IHelpContextIds{
+
+ public static final String PREFIX=JSchUIPlugin.ID+"."; //$NON-NLS-1$
+
+ public static final String KEYBOARD_INTERACTIVE_DIALOG=PREFIX
+ +"keyboard_interactive_dialog_context"; //$NON-NLS-1$
+ public static final String USER_VALIDATION_DIALOG=PREFIX
+ +"user_validation_dialog_context"; //$NON-NLS-1$
+}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java
new file mode 100644
index 000000000..a623229dd
--- /dev/null
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java
@@ -0,0 +1,338 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - copying this class from o.e.team.cvs.ui plug-in.
+ *******************************************************************************/
+package org.eclipse.jsch.internal.ui.authenticator;
+
+import org.eclipse.jface.dialogs.*;
+import org.eclipse.jface.dialogs.Dialog;
+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.*;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.jsch.internal.ui.IUIConstants;
+import org.eclipse.jsch.internal.ui.JSchUIPlugin;
+import org.eclipse.jsch.internal.ui.Messages;
+
+/**
+ * A dialog for keyboard-interactive authentication for the ssh2 connection.
+ * @since 1.1
+ */
+public class KeyboardInteractiveDialog extends TrayDialog{
+ // whether or not the user name can be changed
+ protected boolean isUsernameMutable=false;
+
+ // widgets
+ private Text[] texts;
+ protected Image keyLockImage;
+ protected Button allowCachingButton;
+ protected Text usernameField;
+
+ protected String defaultUsername;
+ protected String comment;
+ protected String destination;
+ protected String name;
+ protected String instruction;
+ protected String lang;
+ protected String[] prompt;
+ protected boolean[] echo;
+ private String message;
+ private String[] result;
+ protected boolean allowCaching=false;
+
+ private boolean isPasswordAuth=false;
+
+ /**
+ * Creates a new KeyboardInteractiveDialog.
+ *
+ * @param parentShell the parent shell
+ * @param comment the comment
+ * @param destination the location
+ * @param name the name
+ * @param userName user name
+ * @param instruction the instruction
+ * @param prompt the titles for text-fields
+ * @param echo '*' should be used or not
+ */
+ public KeyboardInteractiveDialog(Shell parentShell, String comment,
+ String destination, String name, String userName, String instruction, String[] prompt,
+ boolean[] echo){
+ super(parentShell);
+ setShellStyle(getShellStyle()|SWT.RESIZE);
+ this.comment=comment;
+ this.destination=destination;
+ this.name=name;
+ this.defaultUsername=userName;
+ this.instruction=instruction;
+ this.prompt=prompt;
+ this.echo=echo;
+ this.message=NLS.bind(Messages.KeyboradInteractiveDialog_message,
+ new String[] {destination
+ +(name!=null&&name.length()>0 ? ": "+name : "")}); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$
+
+ if(prompt!=null && prompt.length==1 && prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$
+ isPasswordAuth=true;
+ }
+
+ }
+
+ /**
+ * @see Window#configureShell
+ */
+ protected void configureShell(Shell newShell){
+ super.configureShell(newShell);
+ if(isPasswordAuth){
+ newShell.setText(Messages.UserValidationDialog_required);
+ }
+ else{
+ newShell.setText(message);
+ }
+ // set F1 help
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell,
+ IHelpContextIds.KEYBOARD_INTERACTIVE_DIALOG);
+ }
+
+ /**
+ * @see Window#create
+ */
+ public void create(){
+ super.create();
+
+ if(isPasswordAuth&&usernameField!=null){
+ usernameField.setText(defaultUsername);
+ usernameField.setEditable(false);
+ }
+
+ if(texts.length>0){
+ texts[0].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=JSchUIPlugin.getImageDescriptor(IUIConstants.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=400;
+ messageLabel.setLayoutData(data);
+ }
+ if(comment!=null){
+ Label label=new Label(main, SWT.WRAP);
+ if(isUsernameMutable){
+ label.setText(NLS.bind(Messages.UserValidationDialog_labelUser,
+ new String[] {comment}));
+ }
+ else{
+ label.setText(NLS.bind(Messages.UserValidationDialog_labelPassword,
+ (new Object[] {defaultUsername, comment})));
+ }
+ data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL);
+ data.horizontalSpan=3;
+ data.widthHint=400;
+ label.setLayoutData(data);
+ }
+ if(instruction!=null&&instruction.length()>0){
+ Label label=new Label(main, SWT.WRAP);
+ label.setText(instruction);
+ data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL);
+ data.horizontalSpan=3;
+ data.widthHint=400;
+ label.setLayoutData(data);
+ }
+
+ if(isPasswordAuth){
+ createUsernameFields(main);
+ }
+
+ createPasswordFields(main);
+
+ if(isPasswordAuth){
+ allowCachingButton=new Button(main, SWT.CHECK);
+ allowCachingButton.setText(Messages.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(Messages.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 user name entry area.
+ *
+ * @param parent the parent of the widgets
+ */
+ protected void createUsernameFields(Composite parent){
+ new Label(parent, SWT.NONE).setText(Messages.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);
+ }
+
+ /**
+ * 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<prompt.length; i++){
+ new Label(parent, SWT.NONE).setText(prompt[i]);
+ int flag=SWT.BORDER;
+ if(!echo[i]){
+ flag|=SWT.PASSWORD;
+ }
+ texts[i]=new Text(parent, flag);
+ GridData data=new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan=2;
+ data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
+ texts[i].setLayoutData(data);
+ if(!echo[i]){
+ texts[i].setEchoChar('*');
+ }
+ }
+ }
+
+ /**
+ * Returns the entered values, or null
+ * if the user canceled.
+ *
+ * @return the entered values
+ */
+ public String[] getResult(){
+ return result;
+ }
+
+ /**
+ * Returns <code>true</code> if the save password checkbox was selected.
+ * @return <code>true</code> if the save password checkbox was selected and <code>false</code>
+ * otherwise.
+ */
+ public boolean getAllowCaching(){
+ return allowCaching;
+ }
+
+ /**
+ * Notifies that the ok button of this dialog has been pressed.
+ * <p>
+ * The default implementation of this framework method sets
+ * this dialog's return code to <code>Window.OK</code>
+ * and closes the dialog. Subclasses may override.
+ * </p>
+ */
+ protected void okPressed(){
+ result=new String[prompt.length];
+ for(int i=0; i<texts.length; i++){
+ result[i]=texts[i].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;
+ }
+
+ /**
+ * Notifies that the cancel button of this dialog has been pressed.
+ * <p>
+ * The default implementation of this framework method sets
+ * this dialog's return code to <code>Window.CANCEL</code>
+ * and closes the dialog. Subclasses may override.
+ * </p>
+ */
+ protected void cancelPressed(){
+ result=null;
+ super.cancelPressed();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#close()
+ */
+ public boolean close(){
+ if(keyLockImage!=null){
+ keyLockImage.dispose();
+ }
+ return super.close();
+ }
+}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java
new file mode 100644
index 000000000..134c388bf
--- /dev/null
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java
@@ -0,0 +1,296 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - copying this class from o.e.team.cvs.ui plug-in.
+ *******************************************************************************/
+package org.eclipse.jsch.internal.ui.authenticator;
+
+import org.eclipse.jface.dialogs.*;
+import org.eclipse.jface.dialogs.Dialog;
+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.*;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.jsch.internal.ui.IUIConstants;
+import org.eclipse.jsch.internal.ui.JSchUIPlugin;
+import org.eclipse.jsch.internal.ui.Messages;
+
+/**
+ * A dialog for prompting for a user name and password
+ * @since 1.1
+ */
+public class UserValidationDialog extends TrayDialog{
+ // widgets
+ protected Text usernameField;
+ protected Text passwordField;
+ protected Button allowCachingButton;
+
+ protected String comment;
+ protected String defaultUsername;
+ protected String password=null;
+ protected boolean allowCaching=false;
+ protected boolean isAllowCaching=false;
+ protected Image keyLockImage;
+
+ // whether or not the user name 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 comment
+ * the location
+ * @param defaultName
+ * the default user name
+ * @param message
+ * a message to display to the user
+ * @param isAllowCaching
+ * a flag to show a check box to save password
+ */
+ public UserValidationDialog(Shell parentShell, String comment,
+ String defaultName, String message, boolean isAllowCaching){
+ super(parentShell);
+ setShellStyle(getShellStyle()|SWT.RESIZE);
+ this.defaultUsername=defaultName;
+ this.comment=comment;
+ this.message=message;
+ this.isAllowCaching=isAllowCaching;
+ }
+
+ /**
+ * @see Window#configureShell
+ */
+ protected void configureShell(Shell newShell){
+ super.configureShell(newShell);
+ newShell.setText(Messages.UserValidationDialog_required);
+ // set F1 help
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell,
+ IHelpContextIds.USER_VALIDATION_DIALOG);
+ }
+
+ /**
+ * @see Window#create
+ */
+ public void create(){
+ super.create();
+ // add some default values
+ usernameField.setText(defaultUsername);
+
+ if(isUsernameMutable){
+ // give focus to user name 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=JSchUIPlugin.getImageDescriptor(IUIConstants.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=400;
+ messageLabel.setLayoutData(data);
+ }
+ if(comment!=null){
+ Label label=new Label(main, SWT.WRAP);
+ if(isUsernameMutable){
+ label.setText(NLS.bind(Messages.UserValidationDialog_labelUser,
+ new String[] {comment}));
+ }
+ else{
+ label.setText(NLS.bind(Messages.UserValidationDialog_labelPassword,
+ (new Object[] {defaultUsername, comment})));
+ }
+ data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL);
+ data.horizontalSpan=3;
+ data.widthHint=400;
+ label.setLayoutData(data);
+ }
+ createUsernameFields(main);
+ createPasswordFields(main);
+
+ if(isAllowCaching){
+ allowCachingButton=new Button(main, SWT.CHECK);
+ allowCachingButton.setText(Messages.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(Messages.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(Messages.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(Messages.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 <code>true</code> if the save password checkbox was selected.
+ *
+ * @return <code>true</code> if the save password checkbox was selected and
+ * <code>false</code> otherwise.
+ */
+ public boolean getAllowCaching(){
+ return allowCaching;
+ }
+
+ /**
+ * Notifies that the ok button of this dialog has been pressed.
+ * <p>
+ * The default implementation of this framework method sets this dialog's
+ * return code to <code>Window.OK</code> and closes the dialog. Subclasses
+ * may override.
+ * </p>
+ */
+ 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();
+ }
+}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java
new file mode 100644
index 000000000..84c016e8c
--- /dev/null
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 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
+ * Atsuhiko Yamanaka, JCraft,Inc. - implementation of promptForKeyboradInteractive
+ * Atsuhiko Yamanaka, JCraft,Inc. - copying this class from o.e.team.cvs.ui plug-in.
+ *******************************************************************************/
+
+package org.eclipse.jsch.internal.ui.authenticator;
+
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jface.dialogs.*;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.jsch.core.IJSchLocation;
+import org.eclipse.jsch.internal.core.IUserAuthenticator;
+import org.eclipse.jsch.internal.core.IUserInfo;
+import org.eclipse.jsch.internal.ui.Messages;
+
+/**
+ * An authenticator that prompts the user for authentication info,
+ * and stores the results in the Platform's authentication key-ring.
+ * @since 1.1
+ */
+public class WorkbenchUserAuthenticator implements IUserAuthenticator{
+ /**
+ * WorkbenchUserAuthenticator constructor.
+ */
+ public WorkbenchUserAuthenticator(){
+ super();
+ }
+
+ /**
+ * @see IUserAuthenticator#promptForUserInfo(IJSchLocation, IUserInfo, String)
+ */
+ public void promptForUserInfo(final IJSchLocation location,
+ final IUserInfo userinfo, final String message){
+
+ // ask the user for a password
+ final String[] result=new String[2];
+ Display display=Display.getCurrent();
+ final boolean allowCaching[]= {false};
+ if(display!=null){
+ allowCaching[0]=promptForPassword(location, userinfo.getUsername(),
+ message, userinfo.isUsernameMutable(), result);
+ }
+ else{
+ // sync exec in default thread
+ Display.getDefault().syncExec(new Runnable(){
+ public void run(){
+ allowCaching[0]=promptForPassword(location, userinfo.getUsername(),
+ message, userinfo.isUsernameMutable(), result);
+ }
+ });
+ }
+
+ if(result[0]==null){
+ throw new OperationCanceledException(
+ Messages.WorkbenchUserAuthenticator_cancelled);
+ }
+
+ if(userinfo.isUsernameMutable()){
+ userinfo.setUsername(result[0]);
+
+ }
+ userinfo.setPassword(result[1]);
+
+ if(location!=null){
+ if(userinfo.isUsernameMutable()){
+ location.setUsername(result[0]);
+ }
+ location.setPassword(result[1]);
+ if(location.getPasswordStore()!=null){
+ if(allowCaching[0])
+ location.getPasswordStore().update(location);
+ else
+ location.getPasswordStore().clear(location);
+ }
+ }
+ }
+
+ /**
+ * Asks the user to enter a password. Places the
+ * results in the supplied string[]. result[0] must
+ * contain the username, result[1] must contain the password.
+ * If the user canceled, both values must be zero.
+ *
+ * @param location the location to obtain the password for
+ * @param username the username
+ * @param message a message to display to the user
+ * @param userMutable whether the user can be changed in the dialog
+ * @param result a String array of length two in which to put the result
+ */
+ protected boolean promptForPassword(final IJSchLocation location,
+ final String username, final String message, final boolean userMutable,
+ final String[] result){
+ String comment=location==null ? null : location.getComment();
+ UserValidationDialog dialog=new UserValidationDialog(null, comment,
+ (username==null) ? "" : username, message, (location!=null && location.getPasswordStore()!=null));//$NON-NLS-1$
+ dialog.setUsernameMutable(userMutable);
+ dialog.open();
+ result[0]=dialog.getUsername();
+ result[1]=dialog.getPassword();
+ return dialog.getAllowCaching();
+ }
+
+ /**
+ * Asks the user to enter values.
+ *
+ * @param location the location to obtain the password for
+ * @param destination the location
+ * @param name the name
+ * @param instruction the instruction
+ * @param prompt the titles for text fields
+ * @param echo '*' should be used or not
+ * @return the entered values, or null if user canceled.
+ */
+ public String[] promptForKeyboradInteractive(
+ final IJSchLocation location, final String destination,
+ final String name, final String instruction, final String[] prompt,
+ final boolean[] echo){
+ final String[][] result=new String[1][];
+ final boolean[] allowCaching=new boolean[1];
+ Display display=Display.getCurrent();
+ if(display!=null){
+ result[0]=_promptForUserInteractive(location, destination, name,
+ instruction, prompt, echo, allowCaching);
+ }
+ else{
+ // sync exec in default thread
+ Display.getDefault().syncExec(new Runnable(){
+ public void run(){
+ result[0]=_promptForUserInteractive(location, destination, name,
+ instruction, prompt, echo, allowCaching);
+ }
+ });
+ }
+ if(result[0]!=null && location!=null &&
+ prompt!=null && prompt.length==1 && prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$
+ location.setPassword(result[0][0]);
+ if(location.getPasswordStore()!=null){
+ if(allowCaching[0])
+ location.getPasswordStore().update(location);
+ else
+ location.getPasswordStore().clear(location);
+ }
+ }
+ return result[0];
+ }
+
+ protected String[] _promptForUserInteractive(
+ final IJSchLocation location, final String destination,
+ final String name, final String instruction, final String[] prompt,
+ final boolean[] echo, final boolean[] allowCaching){
+ String comment=location==null ? null : location.getComment();
+ String username=location==null ? "" : location.getUsername(); //$NON-NLS-1$
+ KeyboardInteractiveDialog dialog=new KeyboardInteractiveDialog(null,
+ comment, destination, name, username, instruction, prompt, echo);
+ dialog.setUsernameMutable(false);
+ dialog.open();
+ String[] _result=dialog.getResult();
+ if(_result!=null)
+ allowCaching[0]=dialog.getAllowCaching();
+ return _result;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#prompt(org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, int, java.lang.String, java.lang.String, int[], int)
+ */
+ public int prompt(IJSchLocation location, final int promptType,
+ final String title, final String message, final int[] promptResponses,
+ final int defaultResponse){
+ final Display display=getStandardDisplay();
+ final int[] retval=new int[1];
+ final String[] buttons=new String[promptResponses.length];
+ for(int i=0; i<promptResponses.length; i++){
+ int prompt=promptResponses[i];
+ switch(prompt){
+ case IUserAuthenticator.OK_ID:
+ buttons[i]=IDialogConstants.OK_LABEL;
+ break;
+ case IUserAuthenticator.CANCEL_ID:
+ buttons[i]=IDialogConstants.CANCEL_LABEL;
+ break;
+ case IUserAuthenticator.NO_ID:
+ buttons[i]=IDialogConstants.NO_LABEL;
+ break;
+ case IUserAuthenticator.YES_ID:
+ buttons[i]=IDialogConstants.YES_LABEL;
+ break;
+ }
+ }
+
+ display.syncExec(new Runnable(){
+ public void run(){
+ final MessageDialog dialog=new MessageDialog(new Shell(display), title,
+ null, message, promptType, buttons, 1);
+ retval[0]=dialog.open();
+ }
+ });
+ return retval[0];
+ }
+
+ public boolean promptForHostKeyChange(final IJSchLocation location){
+ final boolean[] openConfirm=new boolean[] {false};
+ final Display display=getStandardDisplay();
+ display.syncExec(new Runnable(){
+ public void run(){
+ openConfirm[0]=MessageDialog.openConfirm(null,
+ Messages.WorkbenchUserAuthenticator_1, NLS.bind(
+ Messages.WorkbenchUserAuthenticator_2, new String[] {location
+ .getHost()})); //
+ }
+ });
+ if(!openConfirm[0]){
+ throw new OperationCanceledException();
+ }
+ return openConfirm[0];
+ }
+
+ /**
+ * Returns the standard display to be used. The method first checks, if
+ * the thread calling this method has an associated display. If so, this
+ * display is returned. Otherwise the method returns the default display.
+ * @return standard display
+ */
+ private Display getStandardDisplay(){
+ Display display=Display.getCurrent();
+ if(display==null){
+ display=Display.getDefault();
+ }
+ return display;
+ }
+}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties
index a240f9a47..2606f65c2 100644
--- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties
@@ -90,3 +90,19 @@ UserValidationDialog_4=&Password:
UserValidationDialog_5=&User name:
PreferencePage_0=SSH2 Service not available
PreferencePage_1=The SSH2 service is not available.
+
+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.
+UserValidationDialog_required=Password Required
+UserValidationDialog_labelUser={0}
+UserValidationDialog_labelPassword={1}
+UserValidationDialog_password=&Password:
+UserValidationDialog_user=&User name:
+
+KeyboradInteractiveDialog_message=Keyboard Interactive authentication for {0}
+KeyboardInteractiveDialog_labelRepository=Enter values for the following repository: {0}
+
+WorkbenchUserAuthenticator_cancelled=Operation canceled because login was canceled
+WorkbenchUserAuthenticator_1=Host Key Change
+WorkbenchUserAuthenticator_2=The host key for {0} has changed. It is possible that this was intentional but there is also a chance that you are the target of an attack of some kind. If you know that the host key has changed, click OK and existing host key will be purged. Otherwise, click Cancel and consult with your system administrator
+WorkbenchUserAuthenticator_The_operation_was_canceled_by_the_user_1=The operation was canceled by the user
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java
index a7e278618..9b9a5ccc8 100644
--- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java
@@ -8,6 +8,7 @@
* Contributors:
* Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation.
* IBM Corporation - ongoing maintenance
+ * Atsuhiko Yamanaka, JCraft,Inc. - re-implement the public key transfer by using IJSchLocation.
*******************************************************************************/
package org.eclipse.jsch.internal.ui.preference;
@@ -18,11 +19,11 @@ import org.eclipse.core.runtime.*;
import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.*;
+import org.eclipse.jsch.core.IJSchLocation;
import org.eclipse.jsch.core.IJSchService;
import org.eclipse.jsch.internal.core.*;
import org.eclipse.jsch.internal.ui.JSchUIPlugin;
import org.eclipse.jsch.internal.ui.Messages;
-import org.eclipse.jsch.ui.UserInfoPrompter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
@@ -855,26 +856,19 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
}
}
- void export_via_sftp(String user, String host, int port,
- /* String target, */ byte[] pkey) throws JSchException{
+ void export_via_sftp(String user, String host, int port, byte[] pkey) throws JSchException{
try{
- /*
- * int i=0; String authorized_keys=target; String dir=""; String
- * separator="/"; i=target.lastIndexOf("/"); if(i<0){
- * i=target.lastIndexOf("\\"); if(i>=0){ separator="\\"; } } else{ }
- * if(i>=0){ authorized_keys=target.substring(i+1);
- * dir=target.substring(0, i+1); }
- */
-
int timeout = 60000;
IJSchService service = JSchUIPlugin.getPlugin().getJSchService();
if (service == null) {
MessageDialog.openInformation(getShell(), Messages.PreferencePage_0, Messages.PreferencePage_1);
return;
}
- Session session = service.createSession(host, port, user);
- new UserInfoPrompter(session);
+
+ IJSchLocation location=service.getLocation(user, host, port);
+ // We hope that prompts for jsch are given by IJSchService, so "null" should be passed.
+ Session session = service.createSession(location, null);
session.setTimeout(timeout);
try {
service.connect(session, timeout, new NullProgressMonitor());
@@ -886,7 +880,6 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
channel.connect();
ChannelSftp c=(ChannelSftp)channel;
- /* String pwd= */c.pwd(); // Read off the channel
SftpATTRS attr=null;
try{
@@ -927,13 +920,14 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
NLS.bind(Messages.CVSSSH2PreferencePage_109, (user
+"@"+host+(port==22 ? "" : ":"+port)+":~/.ssh/authorized_keys"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ c.quit();
c.disconnect();
} finally {
session.disconnect();
}
} catch(IOException eee){
setErrorMessage(eee.toString());
- }
+ }
}
private void checkPermission(ChannelSftp c, String path) throws SftpException{
@@ -971,7 +965,6 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
}
private void initControls(){
- // Preferences preferences=JSchCorePlugin.getPlugin().getPreferences();
Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences();
ssh2HomeText.setText(preferences
.getString(org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME));
@@ -997,7 +990,6 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
}
}
- // Preferences preferences=JSchCorePlugin.getPlugin().getPreferences();
Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences();
preferences.setValue(
org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME, home);
@@ -1017,7 +1009,6 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
protected void performDefaults(){
super.performDefaults();
- // Preferences preferences=JSchCorePlugin.getPlugin().getPreferences();
Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences();
ssh2HomeText
.setText(preferences

Back to the top