328.5. 身份验证

SSH 组件可以使用以下两种机制之一向远程 SSH 服务器进行身份验证:公钥证书或用户名/密码。配置 SSH 组件如何进行身份验证以及要设置哪些选项。

  1. 首先,它将查看是否设置了 certResource 选项;如果已设置,则使用它找到引用的公钥证书并使用它来进行身份验证。
  2. 如果没有设置 certResource,它将查看 keyPairProvider 是否已设置,如果已设置,它将使用该证书进行基于证书的身份验证。
  3. 如果没有设置 certResourcekeyPairProvider,它将使用 用户名和密码 选项进行身份验证。即使在带有 SshConstants.USERNAME_HEADER (CamelSshUsername)和 SshConstants.PASSWORD_HEADER 的端点配置和标题中提供了 用户名和密码,但端点配置将超过标头中设置的凭证。

以下路由片段演示了使用 classpath 中的证书进行 SSH 轮询使用者。

在 XML DSL 中,

<route>
  <from uri="ssh://scott@localhost:8101?certResource=classpath:test_rsa&amp;useFixedDelay=true&amp;delay=5000&amp;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}");

例如 /camel-example-ssh-security 提供了使用公钥身份验证的示例

证书依赖项

如果使用基于证书的身份验证,则需要添加一些额外的运行时依赖项。显示的依赖项版本为 Camel 2.11,您可能需要使用更新的版本,具体取决于您使用的 Camel 版本。

<dependency>
  <groupId>org.apache.sshd</groupId>
  <artifactId>sshd-core</artifactId>
  <version>0.8.0</version>
</dependency>
<dependency>
  <groupId>org.bouncycastle</groupId>
  <artifactId>bcpg-jdk15on</artifactId>
  <version>1.47</version>
</dependency>
<dependency>
  <groupId>org.bouncycastle</groupId>
  <artifactId>bcpkix-jdk15on</artifactId>
  <version>1.47</version>
</dependency>