Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Spring SFTP上设置首选身份验证方法_Spring_Spring Boot_Spring Integration Sftp - Fatal编程技术网

在Spring SFTP上设置首选身份验证方法

在Spring SFTP上设置首选身份验证方法,spring,spring-boot,spring-integration-sftp,Spring,Spring Boot,Spring Integration Sftp,我正试图通过Spring Boot构建一个SFTP连接。我使用的是密码验证,而不是私钥。当我启动应用程序时,它首先尝试通过gssapi进行身份验证,并提示mic和Kerberos输入凭据。在我按下Kerberos键之后,应用程序将尝试查找私钥。在找不到有关密钥的任何详细信息后,它将最终尝试提供给会话工厂的凭据并按预期工作。由于该应用程序将生活在Docker构建中,我需要它首先尝试密码身份验证 此时,我尝试设置会话属性,将AllowUnkownKeys设置为false并将其完全删除,但没有成功 @

我正试图通过Spring Boot构建一个SFTP连接。我使用的是密码验证,而不是私钥。当我启动应用程序时,它首先尝试通过gssapi进行身份验证,并提示mic和Kerberos输入凭据。在我按下Kerberos键之后,应用程序将尝试查找私钥。在找不到有关密钥的任何详细信息后,它将最终尝试提供给会话工厂的凭据并按预期工作。由于该应用程序将生活在Docker构建中,我需要它首先尝试密码身份验证

此时,我尝试设置会话属性,将AllowUnkownKeys设置为false并将其完全删除,但没有成功

@SpringBootApplication
public class SFTPConnector {


public static void main(String[] args){
    new SpringApplicationBuilder(SFTPConnector.class).run(args);
}

@Bean
Properties configProperties(){
    Properties config = new Properties();
    config.setProperty("PreferredAuthenticationMethod", "PASSWORD");
    return config;
}

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller(){
    System.out.println("Initializing Poller");
    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(6000));
    return pollerMetadata;
}
@Bean
SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory(){
    System.out.println("Creating Session");
    DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
    factory.setHost("someSFTPServer");
    factory.setUser("user");
    factory.setPassword("SomePassword");
    factory.setPort(22);
    factory.setAllowUnknownKeys(true);
    factory.setSessionConfig(configProperties());
    return new CachingSessionFactory<ChannelSftp.LsEntry>(factory);
}
@Bean
SftpInboundFileSynchronizer sftpInboundFileSynchronizer(){
    System.out.println("In File Synchronizer");
    SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
    fileSync.setDeleteRemoteFiles(false);
    fileSync.setRemoteDirectory("SomeDir");
    fileSync.setFilter(new SftpSimplePatternFileListFilter("*.csv"));
    return fileSync;
}
@Bean
@InboundChannelAdapter("sftpChannel")
public MessageSource<File> sftpMessageSource(){
    System.out.println("Inside SFTP Message Source");
    SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
    source.setLocalDirectory(new File("/tmp/local_inbound"));
    source.setAutoCreateLocalDirectory(true);
    source.setLocalFilter(new AcceptOnceFileListFilter<File>());
    return source;
}
@Bean
@ServiceActivator(inputChannel = "sftpChannel")
MessageHandler messageHandler(){
    System.out.println("Inisde Message Handler");
    return new MessageHandler() {
        @Override
        public void handleMessage(Message<?> arg0) throws MessagingException {
                File f = (File) arg0.getPayload();
                System.out.println(f.getName());
        }
    };
}
}`

我得到: 019-01-04 11:22:30.938信息11240-[ask-scheduler-1]com.jcraft.jsch:SSH\u MSG\u NEWKEYS已发送 2019-01-04 11:22:30.938信息11240-[ask-scheduler-1]com.jcraft.jsch:SSH_MSG_NEWKEYS已收到 2019-01-04 11:22:30.943信息11240-[ask-scheduler-1]com.jcraft.jsch:SSH\u MSG\u SERVICE\u请求已发送 2019-01-04 11:22:30.948信息11240-[ask-scheduler-1]com.jcraft.jsch:SSH\u MSG\u SERVICE\u ACCEPT已收到 2019-01-04 11:22:30.952信息11240-[ask-scheduler-1]com.jcraft.jsch:可以继续的身份验证:带麦克风的gssapi、公钥、键盘交互、密码 2019-01-04 11:22:30.953信息11240-[ask-scheduler-1]com.jcraft.jsch:下一个身份验证方法:带麦克风的gssapi Kerberos用户名[bradley.dudra]: bradley.dudra的Kerberos密码: 2019-01-04 11:34:28.546信息11240-[ask-scheduler-1]com.jcraft.jsch:可以继续的身份验证:公钥、键盘交互、密码 2019-01-04 11:34:28.547信息11240-[ask-scheduler-1]com.jcraft.jsch:下一个身份验证方法:公钥 2019-01-04 11:34:28.548信息11240-[ask-scheduler-1]com.jcraft.jsch:可以继续的身份验证:密码 2019-01-04 11:34:28.548信息11240-[ask-scheduler-1]com.jcraft.jsch:下一个身份验证方法:密码

在这一点之后,身份验证工作。
我需要从一开始就忽略通过密码进行身份验证的尝试。

我认为会话配置中的属性是错误的: 尝试以下方法:

config.setProperty("PreferredAuthentications", "password");

查看进行上述更改的受支持属性,我现在收到以下错误:2019-01-04 14:18:03.377错误9028-[ask-scheduler-5]o.s.integration.handler.LoggingHandler:org.springframework.messaging.MessagingException:将“/internetlpgms/INTO/Archive/receive”同步到本地目录时出现问题;嵌套异常为org.springframework.messaging.MessaginException:无法在会话上执行;嵌套异常为org.springframework.integration.util.PoolItemNotAvailableException:无法获取池项目。@NoobWebDev将方法更改为密码,我更新了应答谢谢。成功了