You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2017/08/18 17:52:18 UTC
camel git commit: CAMEL-11638: upgrade camel-ftp to use apache-sshd
version 1.6.0
Repository: camel
Updated Branches:
refs/heads/master bc3677e52 -> 4f96d7923
CAMEL-11638: upgrade camel-ftp to use apache-sshd version 1.6.0
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4f96d792
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4f96d792
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4f96d792
Branch: refs/heads/master
Commit: 4f96d7923de54da4961ee904686b6027453bcfa5
Parents: bc3677e
Author: Babak Vahdat <bv...@apache.org>
Authored: Fri Aug 18 19:52:10 2017 +0200
Committer: Babak Vahdat <bv...@apache.org>
Committed: Fri Aug 18 19:52:10 2017 +0200
----------------------------------------------------------------------
.../component/file/remote/SftpOperations.java | 34 +++++++++++++-------
.../remote/sftp/MyPasswordAuthenticator.java | 30 -----------------
.../file/remote/sftp/SftpServerTestSupport.java | 33 +++++++------------
3 files changed, 34 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4f96d792/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index a2b4bcb..1721c40 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -24,6 +24,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.DSAPublicKey;
@@ -162,7 +165,7 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
}
configureBulkRequests();
-
+
return true;
}
@@ -292,7 +295,7 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
LOG.debug("Using StrickHostKeyChecking: {}", sftpConfig.getStrictHostKeyChecking());
session.setConfig("StrictHostKeyChecking", sftpConfig.getStrictHostKeyChecking());
}
-
+
session.setServerAliveInterval(sftpConfig.getServerAliveInterval());
session.setServerAliveCountMax(sftpConfig.getServerAliveCountMax());
@@ -303,8 +306,8 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
session.setConfig("compression.c2s", "zlib@openssh.com,zlib,none");
session.setConfig("compression_level", Integer.toString(sftpConfig.getCompression()));
}
-
- // set the PreferredAuthentications
+
+ // set the PreferredAuthentications
if (sftpConfig.getPreferredAuthentications() != null) {
LOG.debug("Using PreferredAuthentications: {}", sftpConfig.getPreferredAuthentications());
session.setConfig("PreferredAuthentications", sftpConfig.getPreferredAuthentications());
@@ -354,12 +357,12 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
if (configuration.getSoTimeout() > 0) {
session.setTimeout(configuration.getSoTimeout());
}
-
+
// set proxy if configured
if (proxy != null) {
session.setProxy(proxy);
}
-
+
return session;
}
@@ -501,8 +504,15 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
final String[] dirs = dirName.split("/|\\\\");
boolean success = false;
+ boolean first = true;
for (String dir : dirs) {
- sb.append(dir).append('/');
+ if (first) {
+ first = false;
+ } else {
+ sb.append('/');
+ }
+ sb.append(dir);
+
// must normalize the directory name
String directory = endpoint.getConfiguration().normalizePath(sb.toString());
@@ -648,10 +658,10 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
return retrieveFileToStreamInBody(name, exchange);
}
}
-
+
public synchronized void releaseRetreivedFileResources(Exchange exchange) throws GenericFileOperationFailedException {
InputStream is = exchange.getIn().getHeader(RemoteFileComponent.REMOTE_FILE_INPUT_STREAM, InputStream.class);
-
+
if (is != null) {
try {
is.close();
@@ -669,7 +679,7 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
GenericFile<ChannelSftp.LsEntry> target =
(GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
-
+
String remoteName = name;
if (endpoint.getConfiguration().isStepwise()) {
// remember current directory
@@ -687,7 +697,7 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
// use input stream which works with Apache SSHD used for testing
InputStream is = channel.get(remoteName);
-
+
if (endpoint.getConfiguration().isStreamDownload()) {
target.setBody(is);
exchange.getIn().setHeader(RemoteFileComponent.REMOTE_FILE_INPUT_STREAM, is);
@@ -915,7 +925,7 @@ public class SftpOperations implements RemoteFileOperations<ChannelSftp.LsEntry>
}
return true;
-
+
} catch (SftpException e) {
throw new GenericFileOperationFailedException("Cannot store file: " + name, e);
} catch (InvalidPayloadException e) {
http://git-wip-us.apache.org/repos/asf/camel/blob/4f96d792/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java
deleted file mode 100644
index ae01626..0000000
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/MyPasswordAuthenticator.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.file.remote.sftp;
-
-import org.apache.sshd.server.PasswordAuthenticator;
-import org.apache.sshd.server.session.ServerSession;
-
-/**
- * @version
- */
-public class MyPasswordAuthenticator implements PasswordAuthenticator {
-
- public boolean authenticate(String username, String password, ServerSession session) {
- return username != null && username.equals(password);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/4f96d792/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
index 7d20986..638a2ed 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpServerTestSupport.java
@@ -18,23 +18,21 @@ package org.apache.camel.component.file.remote.sftp;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
-import java.security.PublicKey;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.apache.camel.component.file.remote.BaseServerTestSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.io.FileUtils;
-import org.apache.sshd.SshServer;
-import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.file.nativefs.NativeFileSystemFactory;
+import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
-import org.apache.sshd.common.session.AbstractSession;
-import org.apache.sshd.server.Command;
-import org.apache.sshd.server.PublickeyAuthenticator;
-import org.apache.sshd.server.command.ScpCommandFactory;
-import org.apache.sshd.server.session.ServerSession;
-import org.apache.sshd.server.sftp.SftpSubsystem;
+import org.apache.sshd.common.session.helpers.AbstractSession;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.scp.ScpCommandFactory;
+import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.junit.After;
import org.junit.Before;
@@ -75,18 +73,11 @@ public class SftpServerTestSupport extends BaseServerTestSupport {
try {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
- sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"src/test/resources/hostkey.pem"}));
- sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
+ sshd.setKeyPairProvider(new FileKeyPairProvider(Paths.get("src/test/resources/hostkey.pem")));
+ sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
sshd.setCommandFactory(new ScpCommandFactory());
- sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
- PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {
- // consider all keys as authorized for all users
- @Override
- public boolean authenticate(String username, PublicKey key, ServerSession session) {
- return true;
- }
- };
- sshd.setPublickeyAuthenticator(publickeyAuthenticator);
+ sshd.setPasswordAuthenticator((username, password, session) -> true);
+ sshd.setPublickeyAuthenticator((username, password, session) -> true);
sshd.start();
} catch (Exception e) {
// ignore if algorithm is not on the OS