springsshspring-bootmina

ssh access to spring boot application


On Spring Boot 1.2.3.RELEASE trying to setup SSH on JDK 1.8, Windows 7.

I got the application.properties configured as:

shell.ssh.port=2212
shell.ssh.enabled=true
shell.auth=simple
shell.auth.simple.user.name=user
shell.auth.simple.user.password=password

When the application starts and trying to access it via putty, the following exception appears:

java.lang.IllegalStateException: No session available
    at org.apache.sshd.common.AbstractSessionIoHandler.exceptionCaught(AbstractSessionIoHandler.java:52) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:697) ~[mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:791) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:111) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:483) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireExceptionCaught(DefaultIoFilterChain.java:471) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:359) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$700(DefaultIoFilterChain.java:46) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionCreated(DefaultIoFilterChain.java:771) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.IoFilterAdapter.sessionCreated(IoFilterAdapter.java:79) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireSessionCreated(DefaultIoFilterChain.java:350) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.service.IoServiceListenerSupport.fireSessionCreated(IoServiceListenerSupport.java:211) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:514) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:481) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$200(AbstractPollingIoProcessor.java:67) [mina-core-2.0.2.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1071) [mina-core-2.0.2.jar:na]
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) [mina-core-2.0.2.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
Caused by: java.lang.AbstractMethodError: org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.loadKeys()[Ljava/security/KeyPair;
    at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.server.session.ServerSession.sendKexInit(ServerSession.java:331) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.server.session.ServerSession.<init>(ServerSession.java:92) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.server.session.SessionFactory.doCreateSession(SessionFactory.java:43) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.common.session.AbstractSessionFactory.createSession(AbstractSessionFactory.java:38) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.sshd.common.AbstractSessionIoHandler.sessionCreated(AbstractSessionIoHandler.java:37) ~[sshd-core-0.6.0.jar:0.6.0]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.sessionCreated(DefaultIoFilterChain.java:643) ~[mina-core-2.0.2.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionCreated(DefaultIoFilterChain.java:357) [mina-core-2.0.2.jar:na]

Is there something I am missing here?

Thanks.


Update: Thanks for the pointers. Here is my dependency tree:

[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
[INFO]    +- org.crashub:crash.cli:jar:1.3.1:compile
[INFO]    +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
[INFO]    |  +- org.apache.sshd:sshd-core:jar:0.6.0:compile
[INFO]    |  +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
[INFO]    |  |  \- net.sf.jpam:jpam:jar:1.1:compile
[INFO]    |  +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
[INFO]    |  \- org.apache.mina:mina-core:jar:2.0.2:compile
[INFO]    +- org.crashub:crash.embed.spring:jar:1.3.1:compile
[INFO]    +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
[INFO]    |  \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
[INFO]    +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
[INFO]    |  \- javax.mail:mail:jar:1.4.7:compile
[INFO]    |     \- javax.activation:activation:jar:1.1:compile
[INFO]    +- org.crashub:crash.shell:jar:1.3.1:compile
[INFO]    \- org.codehaus.groovy:groovy:jar:2.3.11:compile

All dependencies appear transitive from spring-boot-starter-remote-shell. I will try to fix up with manual override.


Solution

  • I started a spring boot project with jdk1.8, added the spring-boot-starter-remote-shell maven dependency & your configuration, gave it a go, and everything went smooth.

    However java.lang.AbstractMethodError made me suspect a classpath issue, so I quickly ran a mvn dependency:tree on my project and, among others, spring-boot-starter-remote-shell:jar:1.2.3.RELEASE has org.apache.sshd:sshd-core:jar:0.11.0 as a transitive dependency as you can see below.

    [INFO] +- org.springframework.boot:spring-boot-starter-remote-shell:jar:1.2.3.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.3.RELEASE:compile
    [INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:1.2.3.RELEASE:compile
    [INFO] |  +- org.crashub:crash.cli:jar:1.3.1:compile
    [INFO] |  +- org.crashub:crash.connectors.ssh:jar:1.3.1:compile
    [INFO] |  |  +- org.apache.sshd:sshd-core:jar:0.11.0:compile <===THIS ONE===
    [INFO] |  |  +- org.apache.sshd:sshd-pam:jar:0.11.0:compile
    [INFO] |  |  |  \- net.sf.jpam:jpam:jar:1.1:compile
    [INFO] |  |  +- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
    [INFO] |  |  +- org.bouncycastle:bcpkix-jdk15on:jar:1.51:compile
    [INFO] |  |  \- org.apache.mina:mina-core:jar:2.0.7:compile
    [INFO] |  +- org.crashub:crash.embed.spring:jar:1.3.1:compile
    [INFO] |  +- org.crashub:crash.plugins.cron:jar:1.3.1:compile
    [INFO] |  |  \- it.sauronsoftware.cron4j:cron4j:jar:2.2.5:compile
    [INFO] |  +- org.crashub:crash.plugins.mail:jar:1.3.1:compile
    [INFO] |  |  \- javax.mail:mail:jar:1.4:compile
    [INFO] |  |     \- javax.activation:activation:jar:1.1:compile
    [INFO] |  +- org.crashub:crash.shell:jar:1.3.1:compile
    [INFO] |  \- org.codehaus.groovy:groovy:jar:2.3.11:compile
    

    Another quick look at your stacktrace revealed that you seemed to have a different version on the classpath at org.apache.sshd.common.keyprovider.AbstractKeyPairProvider.getKeyTypes(AbstractKeyPairProvider.java:49) ~[sshd-core-0.6.0.jar:0.6.0] so what I did next was to manually specify this version as a dependency in the pom. When I rerun the app and attempted to connect via SSH I got the same exception as you did.

    Also looking at the classes, the AbstractKeyPairProvider.loadKeys() method has a different signature which most likely messes up the implementations depending on the 0.11.0 contract, such as URLKeyPairProvider:

    method inconsistencies

    So, either you also have added this version unintentionally, or some of your other dependencies are referring it, effectively shadowing 0.11.0 on the classpath. In my case I enabled the spring boot actuator HTTP endpoints confirming the above: classpath order

    In conclusion, check your dependency tree and figure out where does the sshd-core 0.6.0 and perhaps mina-core 2.0.2 come from and exclude them.