INT-3200: SFTP: use byte[] for the PrivateKey

JIRA: https://jira.spring.io/browse/INT-3200

INT-3200: Remove reduntant test case

INT-3200: remove trailing space
This commit is contained in:
David Liu
2014-07-31 09:54:59 +03:00
committed by Artem Bilan
parent 36cabb7f3c
commit afc8214c52
2 changed files with 11 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.file.remote.session.SharedSessionCapable;
import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import com.jcraft.jsch.ChannelSftp.LsEntry;
@@ -42,6 +43,7 @@ import com.jcraft.jsch.UserInfo;
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
* @author David Liu
*
* @since 2.0
*/
@@ -367,12 +369,12 @@ public class DefaultSftpSessionFactory implements SessionFactory<LsEntry>, Share
// private key
if (this.privateKey != null) {
String privateKeyFilePath = this.privateKey.getFile().getAbsolutePath();
byte[] keyByteArray = StreamUtils.copyToByteArray(this.privateKey.getInputStream());
if (StringUtils.hasText(this.privateKeyPassphrase)) {
this.jsch.addIdentity(privateKeyFilePath, this.privateKeyPassphrase);
this.jsch.addIdentity(this.user, keyByteArray, null, this.privateKeyPassphrase.getBytes());
}
else {
this.jsch.addIdentity(privateKeyFilePath);
this.jsch.addIdentity(this.user, keyByteArray, null, null);
}
}
com.jcraft.jsch.Session jschSession = this.jsch.getSession(this.user, this.host, this.port);

View File

@@ -30,7 +30,6 @@ import java.security.PublicKey;
import java.security.spec.RSAPublicKeySpec;
import java.util.Arrays;
import com.jcraft.jsch.ChannelSftp.LsEntry;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.file.FileSystemView;
@@ -45,13 +44,17 @@ import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.sftp.SftpSubsystem;
import org.junit.Test;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.util.StreamUtils;
import com.jcraft.jsch.ChannelSftp.LsEntry;
/**
* @author Gary Russell
* @author David Liu
* @since 4.1
*
*/
@@ -150,7 +153,8 @@ public class SftpServerTests {
f.setHost("localhost");
f.setPort(port);
f.setUser("user");
f.setPrivateKey(new ClassPathResource("id_rsa"));
InputStream stream = new ClassPathResource("id_rsa").getInputStream();
f.setPrivateKey(new ByteArrayResource(StreamUtils.copyToByteArray(stream)));
Session<LsEntry> session = f.getSession();
doTest(server, session);
}