首页 文章

spring integration:sftp入站适配器身份验证失败

提问于
浏览
1

我使用sftp入站适配器每天8:00下载文件 . 为此,我将凭据(用户和密码)声明到文件user.properties中 .

执行此操作时身份验证失败,但如果我直接将密码写入application-context.xml,则验证失败 .

我的源代码:

<bean id="defaultSftpSessionFactory"
        class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">

        <property name="host" value="${host}" />
        <property name="port" value="${port}" />
        <property name="user" value="${user}" />
        <property name="privateKey" value="${private.keyfile}"/>
        <property name="privateKeyPassphrase" value="${passphrase}"/>

        <property name="allowUnknownKeys" value="true" />
    </bean>


An exception is occured:

    LoggingHandler:145 - org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory; nested exception is org.springframework.messaging.MessagingException: Failed to obtain pooled item; nested exception is java.lang.IllegalStateException: failed to create SFTP Session
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:266)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.doReceive(AbstractInboundFileSynchronizingMessageSource.java:193)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.doReceive(AbstractInboundFileSynchronizingMessageSource.java:59)
    at org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:134)
    at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:175)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:224)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:57)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:176)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:173)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:330)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:324)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.messaging.MessagingException: Failed to obtain pooled item; nested exception is java.lang.IllegalStateException: failed to create SFTP Session
    at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:178)
    at org.springframework.integration.file.remote.session.CachingSessionFactory.getSession(CachingSessionFactory.java:123)
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:408)
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:223)
    ... 22 more
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
    at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:382)
    at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:55)
    at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:81)
    at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:78)
    at org.springframework.integration.util.SimplePool.doGetItem(SimplePool.java:188)
    at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:169)
    ... 25 more
Caused by: java.lang.IllegalStateException: failed to connect
    at org.springframework.integration.sftp.session.SftpSession.connect(SftpSession.java:272)
    at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:377)
    ... 30 more
Caused by: com.jcraft.jsch.JSchException: Auth cancel
    at com.jcraft.jsch.Session.connect(Session.java:511)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at org.springframework.integration.sftp.session.SftpSession.connect(SftpSession.java:263)
    ... 31 more

和jsch调试:

jsch:52 - Connecting to 10.241.22.22 port 22
2015-12-22 08:35:04 INFO  jsch:52 - Connection established
2015-12-22 08:35:04 INFO  jsch:52 - Remote version string: SSH-2.0-xlightftpd_release_3.8.5.1
2015-12-22 08:35:04 INFO  jsch:52 - Local version string: SSH-2.0-JSCH-0.1.53
2015-12-22 08:35:04 INFO  jsch:52 - CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
2015-12-22 08:35:04 INFO  jsch:52 - aes256-ctr is not available.
2015-12-22 08:35:04 INFO  jsch:52 - aes192-ctr is not available.
2015-12-22 08:35:04 INFO  jsch:52 - aes256-cbc is not available.
2015-12-22 08:35:04 INFO  jsch:52 - aes192-cbc is not available.
2015-12-22 08:35:04 INFO  jsch:52 - CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
2015-12-22 08:35:04 INFO  jsch:52 - diffie-hellman-group14-sha1 is not available.
2015-12-22 08:35:04 INFO  jsch:52 - CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
2015-12-22 08:35:04 INFO  jsch:52 - SSH_MSG_KEXINIT sent
2015-12-22 08:35:04 INFO  jsch:52 - SSH_MSG_KEXINIT received
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: ssh-rsa
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: aes256-cbc,aes192-cbc,aes128-cbc,blowfish-cbc,3des-cbc
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: aes256-cbc,aes192-cbc,aes128-cbc,blowfish-cbc,3des-cbc
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: hmac-sha1
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: hmac-sha1
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: none
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: none
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: 
2015-12-22 08:35:04 INFO  jsch:52 - kex: server: 
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: none
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: none
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: 
2015-12-22 08:35:04 INFO  jsch:52 - kex: client: 
2015-12-22 08:35:04 INFO  jsch:52 - kex: server->client aes128-cbc hmac-sha1 none
2015-12-22 08:35:04 INFO  jsch:52 - kex: client->server aes128-cbc hmac-sha1 none
2015-12-22 08:35:04 INFO  jsch:52 - SSH_MSG_KEX_DH_GEX_REQUEST(1024<1024<1024) sent
2015-12-22 08:35:04 INFO  jsch:52 - expecting SSH_MSG_KEX_DH_GEX_GROUP
2015-12-22 08:35:04 INFO  jsch:52 - SSH_MSG_KEX_DH_GEX_INIT sent
2015-12-22 08:35:04 INFO  jsch:52 - expecting SSH_MSG_KEX_DH_GEX_REPLY
2015-12-22 08:35:05 INFO  jsch:52 - ssh_rsa_verify: signature true
2015-12-22 08:35:05 INFO  jsch:52 - Host '10.241.22.22' is known and matches the RSA host key
2015-12-22 08:35:05 INFO  jsch:52 - SSH_MSG_NEWKEYS sent
2015-12-22 08:35:05 INFO  jsch:52 - SSH_MSG_NEWKEYS received
2015-12-22 08:35:05 INFO  jsch:52 - SSH_MSG_SERVICE_REQUEST sent
2015-12-22 08:35:05 INFO  jsch:52 - SSH_MSG_SERVICE_ACCEPT received
2015-12-22 08:35:05 INFO  jsch:52 - Authentications that can continue: password
2015-12-22 08:35:05 INFO  jsch:52 - Next authentication method: password
2015-12-22 08:35:05 INFO  jsch:52 - Disconnecting from 10.241.22.22 port 22

1 回答

  • 0

    Spring上关于此问题的标准功能称为 property-placeholder . 而且你在那里的 properties 人口中使用它的风格 .

    但看起来你没有属性占位符基础设施 . 像这样的东西:

    <context:property-placeholder location="classpath:user.properties"/>
    

    在Spring Framework Reference Manual中查找更多信息 .

相关问题