private String getScpDir(String path) { return String.format("%s:%s@%s:%s", userInfo.getName(), userInfo.getKeyfile() == null ? userInfo.getPassword() : userInfo.getPassphrase(), scp.getHost(), path); }
/** * Constructor for SSHBase. */ public SSHBase() { super(); userInfo = new SSHUserInfo(); }
/** * Sets the keyfile for the user. * * @param keyfile * The new keyfile value */ public void setKeyfile(String keyfile) { exec.setKeyfile(keyfile); scp.setKeyfile(keyfile); userInfo.setKeyfile(keyfile); if (userInfo.getPassphrase() == null) userInfo.setPassphrase(""); }
private void validateArguments() { if (getHost() == null) { throw new BuildException("Host is required."); } if (getUserInfo().getName() == null) { throw new BuildException("Username is required."); } if (getUserInfo().getKeyfile() == null && getUserInfo().getPassword() == null) { throw new BuildException("Password or Keyfile is required."); } if (getRhost() == null || getLport() == null || getRport() == null) { throw new BuildException("Tunnel information is required. \n Either rhost, lport or rport is not set."); } }
/** * Open an ssh session. * * @return the opened session * @throws JSchException * on error */ protected Session openSession() throws JSchException { JSch jsch = new JSch(); if (null != userInfo.getKeyfile()) { jsch.addIdentity(userInfo.getKeyfile()); } if (!userInfo.getTrust() && knownHosts != null) { project.log("Using known hosts: " + knownHosts, Project.MSG_DEBUG); jsch.setKnownHosts(knownHosts); } Session session = jsch.getSession(userInfo.getName(), host, port); session.setUserInfo(userInfo); project.log("Connecting to " + host + ":" + port, Project.MSG_VERBOSE); session.connect(); return session; }
@Override public String getKeyfile() { return getUserInfo().getKeyfile(); }
/** * Username known to remote host. * * @param username * The new username value */ public void setUsername(String username) { userInfo.setName(username); }
/** * Setting this to true trusts hosts whose identity is unknown. * * @param yesOrNo if true trust the identity of unknown hosts. */ public void setTrust(final boolean yesOrNo) { userInfo.setTrust(yesOrNo); }
/** * Sets the password for the user. * * @param password * The new password value */ public void setPassword(String password) { userInfo.setPassword(password); }
/** * Sets the passphrase for the users key. * * @param passphrase The new passphrase value */ public void setPassphrase(final String passphrase) { userInfo.setPassphrase(passphrase); }
/** * Sets the keyfile for the user. * * @param keyfile * The new keyfile value */ public void setKeyfile(String keyfile) { userInfo.setKeyfile(keyfile); }
throw new BuildException("Host is required."); if (userInfo.getName() == null) { throw new BuildException("Username is required."); if (userInfo.getKeyfile() == null && userInfo.getPassword() == null) { throw new BuildException("Password or Keyfile is required.");
if (null != userInfo.getKeyfile()) { jsch.addIdentity(userInfo.getKeyfile()); if (!userInfo.getTrust() && knownHosts != null) { log("Using known hosts: " + knownHosts, Project.MSG_DEBUG); jsch.setKnownHosts(knownHosts); final Session session = jsch.getSession(userInfo.getName(), host, port); session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password");
@Override public String getKeyfile() { return getUserInfo().getKeyfile(); }
/** * Username known to remote host. * * @param username The new username value */ public void setUsername(final String username) { userInfo.setName(username); }
/** * Setting this to true trusts hosts whose identity is unknown. * * @param yesOrNo * if true trust the identity of unknown hosts. */ public void setTrust(boolean yesOrNo) { userInfo.setTrust(yesOrNo); }
/** * Sets the password for the user. * * @param password The new password value */ public void setPassword(final String password) { userInfo.setPassword(password); }
/** * Sets the passphrase for the users key. * * @param passphrase * The new passphrase value */ public void setPassphrase(String passphrase) { userInfo.setPassphrase(passphrase); }
/** * Sets the keyfile for the user. * * @param keyfile The new keyfile value */ public void setKeyfile(final String keyfile) { userInfo.setKeyfile(keyfile); }
if (getUserInfo().getPassword() == null && getUserInfo().getKeyfile() == null) { throw new BuildException( "neither password nor keyfile for user %s has been given. Can't authenticate.", getUserInfo().getName());