You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Camel SFTP配置账号密码后仍提示输入Kerberos用户名的问题

问题:Apache Camel SFTP路由配置用户名密码后仍需手动输入Kerberos用户名

已添加依赖:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>3.20.1</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-ftp</artifactId>
    <version>3.20.1</version>
</dependency>

构建SFTP路由的代码:

URI uri = new URIBuilder().setScheme("sftp").setHost("HOST.com").setPort(22)
           .setUser("demo_user", "demo_password").build();

from(uri.toString()).to("file://src/main/resources");

运行时控制台输出警告并要求手动输入:

19:01:41:158 [main] WARN o.a.c.c.file.remote.SftpOperations - JSCH
Kerberos username: 

期望配置的用户名密码自动生效,无需手动输入。


解决方案

该问题是因为Camel依赖的JSCH库默认优先尝试Kerberos认证,即便配置了用户名密码,仍会触发Kerberos认证流程导致手动输入提示。可通过以下方式解决:

1. 在SFTP URI中强制指定优先使用密码认证

修改URI构建逻辑,添加preferredAuthentications=password参数,强制JSCH优先采用密码认证:

URI uri = new URIBuilder().setScheme("sftp")
           .setHost("HOST.com")
           .setPort(22)
           .setUser("demo_user", "demo_password")
           .addParameter("preferredAuthentications", "password")
           .build();

from(uri.toString()).to("file://src/main/resources");

也可直接拼接URI字符串:

String sftpUri = "sftp://demo_user:demo_password@HOST.com:22?preferredAuthentications=password";
from(sftpUri).to("file://src/main/resources");

2. 全局配置SFTP组件的认证偏好

若存在多个SFTP路由,可全局设置组件默认认证方式,避免重复配置:

SftpComponent sftpComponent = context.getComponent("sftp", SftpComponent.class);
sftpComponent.setPreferredAuthentications("password");

3. 检查JSCH配置文件

若上述方法无效,排查项目中是否存在jsch.config配置文件,确保其中没有强制开启Kerberos认证的配置项,如有则修改或移除相关内容。

内容的提问来源于stack exchange,提问作者Santanu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 11:33:31