325.4. 身份验证
SSH 组件可以使用以下两种机制之一向远程 SSH 服务器进行身份验证:公钥证书或用户名/密码。配置 SSH 组件如何进行身份验证以及要设置哪些选项。
- 
							首先,它将查看是否设置了 certResource选项;如果已设置,则使用它找到引用的公钥证书并使用它来进行身份验证。
- 
							如果没有设置 certResource,它将查看keyPairProvider是否已设置,如果已设置,它将使用该证书进行基于证书的身份验证。
- 
							如果没有设置 certResource或keyPairProvider,它将使用用户名和密码SshConstants.USERNAME_HEADER(CamelSshUsername)和SshConstants.PASSWORD_HEADER的端点配置和标题中提供了用户名和密码,但端点配置将超过标头中设置的凭证。
以下路由片段演示了使用 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 提供了使用公钥身份验证的示例。
				
证书依赖项
如果使用基于证书的身份验证,则需要添加一些额外的运行时依赖项。显示的依赖项版本为 Camel 2.11,您可能需要使用更新的版本,具体取决于您使用的 Camel 版本。