net.schmizz.sshj.userauth.password.PasswordUtils Java Examples

The following examples show how to use net.schmizz.sshj.userauth.password.PasswordUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SSHClientRebuilder.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public SSHClient build() throws IOException {
  SSHClient sshClient = new SSHClient(config);
  if (knownHosts != null) {
    sshClient.loadKnownHosts(knownHosts);
  } else {
    sshClient.addHostKeyVerifier(new PromiscuousVerifier());
  }
  KeyProvider keyProvider = null;
  if (password == null) {
    if (keyLocation != null) {
      if (keyPassphrase != null) {
        keyProvider = sshClient.loadKeys(keyLocation, keyPassphrase);
      } else {
        keyProvider = sshClient.loadKeys(keyLocation);
      }
    } else {
      if (keyPassphrase != null) {
        keyProvider = sshClient.loadKeys(keyPlainText, null, PasswordUtils.createOneOff(keyPassphrase.toCharArray()));
      } else {
        keyProvider = sshClient.loadKeys(keyPlainText, null, null);
      }
    }
  }
  sshClient.connect(hostname, port);
  if (password == null) {
    sshClient.authPublickey(username, keyProvider);
  } else {
    sshClient.authPassword(username, password);
  }
  sshClient.setTimeout(socketTimeout * 1000);
  sshClient.setConnectTimeout(connectionTimeout * 1000);
  return sshClient;
}