You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/08/20 17:22:13 UTC
git commit: CAMEL-6653 Support to set preferredAuthentications on SFTP
Updated Branches:
refs/heads/master c8b48628c -> 5ca2f87de
CAMEL-6653 Support to set preferredAuthentications on SFTP
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5ca2f87d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5ca2f87d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5ca2f87d
Branch: refs/heads/master
Commit: 5ca2f87de447b5d1d9c565a50d0fbe32d48f2b85
Parents: c8b4862
Author: Willem Jiang <ni...@apache.org>
Authored: Tue Aug 20 18:21:16 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Tue Aug 20 23:21:36 2013 +0800
----------------------------------------------------------------------
.../file/remote/SftpConfiguration.java | 9 ++++
.../component/file/remote/SftpOperations.java | 6 +++
.../file/remote/sftp/SftpSetOperationsTest.java | 53 ++++++++++++++++++++
3 files changed, 68 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5ca2f87d/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
index 4569859..9171520 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConfiguration.java
@@ -41,6 +41,7 @@ public class SftpConfiguration extends RemoteFileConfiguration {
// null means default jsch list will be used
private String ciphers;
private int compression;
+ private String preferredAuthentications;
public SftpConfiguration() {
setProtocol("sftp");
@@ -176,4 +177,12 @@ public class SftpConfiguration extends RemoteFileConfiguration {
public void setCompression(int compression) {
this.compression = compression;
}
+
+ public void setPreferredAuthentications(String pAuthentications) {
+ this.preferredAuthentications = pAuthentications;
+ }
+
+ public String getPreferredAuthentications() {
+ return preferredAuthentications;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5ca2f87d/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 4f8f894..392c1f5 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
@@ -270,6 +270,12 @@ 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
+ if (sftpConfig.getPreferredAuthentications() != null) {
+ LOG.debug("Using PreferredAuthentications: {}", sftpConfig.getPreferredAuthentications());
+ session.setConfig("PreferredAuthentications", sftpConfig.getPreferredAuthentications());
+ }
// set user information
session.setUserInfo(new ExtendedUserInfo() {
http://git-wip-us.apache.org/repos/asf/camel/blob/5ca2f87d/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetOperationsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetOperationsTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetOperationsTest.java
new file mode 100644
index 0000000..ca40540
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSetOperationsTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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 java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.file.remote.SftpEndpoint;
+import org.junit.Test;
+
+public class SftpSetOperationsTest extends SftpServerTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testSftpSetOperations() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ String preferredAuthentications = "password,publickey";
+ String uri = "sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR
+ + "?username=admin&password=admin&ciphers=blowfish-cbc"
+ + "&preferredAuthentications=password,publickey";
+ template.sendBodyAndHeader(uri , "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ // test setting the cipher doesn't interfere with message payload
+ File file = new File(FTP_ROOT_DIR + "/hello.txt");
+ assertTrue("File should exist: " + file, file.exists());
+ assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file));
+
+ // did we actually set the preferedAuthentifications
+ SftpEndpoint endpoint = context.getEndpoint(uri, SftpEndpoint.class);
+ assertEquals(preferredAuthentications, endpoint.getConfiguration().getPreferredAuthentications());
+ }
+}
\ No newline at end of file