139.8. 身份验证
SSH 组件可以使用以下两个机制之一对远程 SSH 服务器进行身份验证:
- 公钥证书
- 用户名/密码
根据如何和设定选项,配置 SSH 组件如何进行身份验证。
-
首先,它将查看是否设置了
certResource选项,如果已设置,则使用它来查找引用的公钥证书,并使用该证书进行身份验证。 -
如果没有设置
certResource,它将查看是否设置了keyPairProvider,如果设置了,它将使用它来使用基于证书的身份验证。 -
如果没有设置
certResource或keyPairProvider,它将使用选项进行身份验证。即使在端点配置中提供了用户名和密码用户名和密码,但使用SshConstants.USERNAME_HEADER(CamelSshUsername)和SshConstants.PASSWORD_HEADER(CamelSshPassword)设置的标头设置的端点配置会被使用。
以下路由片段演示了使用 classpath 中的证书进行 SSH 轮询消费者。
XML DSL
<route>
<from uri="ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A"/>
<log message="${body}"/>
</route>
<route>
<from uri="ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A"/>
<log message="${body}"/>
</route>
Java DSL
from("ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A")
.log("${body}");
from("ssh://scott@localhost:8101?certResource=classpath:test_rsa&useFixedDelay=true&delay=5000&pollCommand=features:list%0A")
.log("${body}");
例如,/camel-example-ssh-security 中提供了使用公钥身份验证的示例。