Reputation: 43
Hello I am using file poller with Spring Integration and we have recently migrated to Java 17. Spring Integration moved from 5.5.15 to 6.0.1
My old bean was:
@Bean
public SessionFactory<LsEntry> sftpSessionFactory(){
DefaultSftpSessionFactory sf = new DefaultSftpSessionFactory();
sf.setHost(serverhost);
sf.setPort(portname);
sf.setUser(username);
Resource resource = resourceLoader.getResource(sftpKeyPrivateKey);
sf.setPrivateKey(resource);
sf.setPrivateKeyPassphrase(sftpKeyPrivateKeyPassword);
sf.setAllowUnknownKeys(true);
return new CachingSessionFactory<LsEntry> (sf);
}
My new code for Session Factory looked like:
@Bean
public SessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry> sftpSessionFactory()
{
DefaultSftpSessionFactory sf = new DefaultSftpSessionFactory();
sf.setHost(serverhost);
sf.setPort(portname);
sf.setUser(username);
Resource resource = resourceLoader.getResource(sftpKeyPrivateKey);
sf.setPrivateKey(resource);
sf.setPrivateKeyPassphrase(sftpKeyPrivateKeyPassword);
sf.setAllowUnknownKeys(true);
return new CachingSessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry(sf);
}
Everything else remains same. Old code was working as expected but in new code when i start my service i get below exception:
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:291)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:67)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:85)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:82)
at org.springframework.integration.util.SimplePool.doGetItem(SimplePool.java:206)
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:187) ... 23 more Caused by: org.apache.sshd.common.SshException: No more authentication methods available
at org.apache.sshd.common.future.AbstractSshFuture.verifyResult(AbstractSshFuture.java:127)
at org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:39)
at org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:32)
at org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:43)
at org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:68)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.initClientSession(DefaultSftpSessionFactory.java:318)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:281) ... 28 more
Caused by: org.apache.sshd.common.SshException: No more authentication methods available
Upvotes: 0
Views: 1960
Reputation: 43
I got the issue, with Java 17 changes we have to use DirEntry from Apache instead of LsEntry.
With JSCH you can ppk file in putty ssh-rsa. But in Apache we need to have our key starting with
-----BEGIN OPENSSH PRIVATE KEY-----
. Because inside code this is the beginner apache has in order to load.
So we can convert our key to OPENSSH private key and it will work as expected.
ssh-keygen -p -N "" -f /path/to/key
Upvotes: 0