You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2008/11/25 18:36:33 UTC

svn commit: r720547 - in /activemq/camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/ test/java/org/apache/camel/component/file/remote/

Author: janstey
Date: Tue Nov 25 09:36:33 2008
New Revision: 720547

URL: http://svn.apache.org/viewvc?rev=720547&view=rev
Log:
CAMEL-1118 - Add ability to configure known hosts file.

Modified:
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java?rev=720547&r1=720546&r2=720547&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Tue Nov 25 09:36:33 2008
@@ -35,6 +35,7 @@
     private FTPClientConfig ftpClientConfig;
     private Expression expression;
     private boolean passiveMode;
+    private String knownHosts;
 
     public RemoteFileConfiguration() {
     }
@@ -92,6 +93,14 @@
         this.file = file;
     }
 
+    public String getKnownHosts() {
+        return knownHosts;
+    }
+
+    public void setKnownHosts(String knownHosts) {
+        this.knownHosts = knownHosts;
+    }
+
     public String getHost() {
         return host;
     }

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java?rev=720547&r1=720546&r2=720547&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java Tue Nov 25 09:36:33 2008
@@ -23,8 +23,12 @@
 import com.jcraft.jsch.UserInfo;
 
 import org.apache.camel.Processor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class SftpEndpoint extends RemoteFileEndpoint<RemoteFileExchange> {
+    protected final transient Log log = LogFactory.getLog(getClass());
+    
     public SftpEndpoint(String uri, RemoteFileComponent remoteFileComponent, RemoteFileConfiguration configuration) {
         super(uri, remoteFileComponent, configuration);
     }
@@ -45,6 +49,12 @@
 
     protected Session createSession() throws JSchException {
         final JSch jsch = new JSch();
+        String knownHostsFile = getConfiguration().getKnownHosts();
+        if (knownHostsFile != null && knownHostsFile.trim().length() > 0) {
+            log.debug("Using knownHosts: " + knownHostsFile);
+            jsch.setKnownHosts(knownHostsFile);
+        }
+      
         final Session session = jsch.getSession(getConfiguration().getUsername(), getConfiguration().getHost(), getConfiguration().getPort());
         session.setUserInfo(new UserInfo() {
             public String getPassphrase() {
@@ -61,10 +71,12 @@
 
             public boolean promptPassphrase(String string) {
                 return true;
-            }
+            }           
 
             public boolean promptYesNo(String string) {
-                return true;
+                log.error(string);
+                // Return 'false' indicating modification of the hosts file is disabled.
+                return false;
             }
 
             public void showMessage(String string) {

Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java?rev=720547&r1=720546&r2=720547&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java Tue Nov 25 09:36:33 2008
@@ -106,4 +106,20 @@
         String file = endpoint.getConfiguration().getFile();
         assertEquals("For uri: " + endpointUri + " the file is not equal", expectedFile, file);
     }
+    
+    public void testSftpKnownHostsConfiguration() {
+        Endpoint endpoint = context.getEndpoint("sftp://user@hostname:1021/some/file?password=secret&binary=true&directory=false&knownHosts=/home/janstey/.ssh/known_hosts");
+        assertTrue("Endpoint not an SftpEndpoint: " + endpoint, endpoint instanceof SftpEndpoint);
+        SftpEndpoint sftpEndpoint = (SftpEndpoint) endpoint;
+        RemoteFileConfiguration config = sftpEndpoint.getConfiguration();
+        
+        assertEquals("sftp", config.getProtocol());
+        assertEquals("hostname", config.getHost());
+        assertEquals(1021, config.getPort());
+        assertEquals("user", config.getUsername());
+        assertEquals("secret", config.getPassword());
+        assertEquals(true, config.isBinary());
+        assertEquals(false, config.isDirectory());
+        assertEquals("/home/janstey/.ssh/known_hosts", config.getKnownHosts());
+    }
 }