public static com.trilead.ssh2.Connection acquireAuthorizedConnection(String ip, int port, String username, String password) { com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(ip, port); try { sshConnection.connect(null, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT); if (!sshConnection.authenticateWithPassword(username, password)) { String[] methods = sshConnection.getRemainingAuthMethods(username); StringBuffer mStr = new StringBuffer(); for (int i = 0; i < methods.length; i++) { mStr.append(methods[i]); } s_logger.warn("SSH authorizes failed, support authorized methods are " + mStr); return null; } return sshConnection; } catch (IOException e) { s_logger.warn("Get SSH connection failed", e); return null; } }
/** * Checks if a specified authentication method is available. This method is * actually just a wrapper for {@link #getRemainingAuthMethods(String) * getRemainingAuthMethods()}*. * * @param user A <code>String</code> holding the username. * @param method An authentication method name (e.g., "publickey", "password", "keyboard-interactive") as specified by the SSH-2 standard. * @return if the specified authentication method is currently available. * @throws IOException the io exception */ public synchronized boolean isAuthMethodAvailable(String user, String method) throws IOException { if (method == null) throw new IllegalArgumentException("method argument may not be NULL!"); String methods[] = getRemainingAuthMethods(user); for (int i = 0; i < methods.length; i++) { if (methods[i].compareTo(method) == 0) return true; } return false; }
/** * Checks if a specified authentication method is available. This method is * actually just a wrapper for {@link #getRemainingAuthMethods(String) * getRemainingAuthMethods()}. * * @param user * A <code>String</code> holding the username. * @param method * An authentication method name (e.g., "publickey", "password", * "keyboard-interactive") as specified by the SSH-2 standard. * @return if the specified authentication method is currently available. * @throws IOException */ public synchronized boolean isAuthMethodAvailable(String user, String method) throws IOException { if (method == null) throw new IllegalArgumentException("method argument may not be NULL!"); String methods[] = getRemainingAuthMethods(user); for (int i = 0; i < methods.length; i++) { if (methods[i].compareTo(method) == 0) return true; } return false; }
/** * Checks if a specified authentication method is available. This method is * actually just a wrapper for {@link #getRemainingAuthMethods(String) * getRemainingAuthMethods()}. * * @param user * A <code>String</code> holding the username. * @param method * An authentication method name (e.g., "publickey", "password", * "keyboard-interactive") as specified by the SSH-2 standard. * @return if the specified authentication method is currently available. * @throws IOException */ public synchronized boolean isAuthMethodAvailable(String user, String method) throws IOException { if (method == null) throw new IllegalArgumentException("method argument may not be NULL!"); String methods[] = getRemainingAuthMethods(user); for (int i = 0; i < methods.length; i++) { if (methods[i].compareTo(method) == 0) return true; } return false; }
private List<String> getRemainingAuthMethods() throws IOException { return Arrays.asList(getConnection().getRemainingAuthMethods(getUsername())); }
public static com.trilead.ssh2.Connection acquireAuthorizedConnection(final String ip, final int port, final String username, final String password) { final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(ip, port); try { sshConnection.connect(null, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT); if (!sshConnection.authenticateWithPassword(username, password)) { final String[] methods = sshConnection.getRemainingAuthMethods(username); final StringBuffer mStr = new StringBuffer(); for (int i = 0; i < methods.length; i++) { mStr.append(methods[i]); } s_logger.warn("SSH authorizes failed, support authorized methods are " + mStr); return null; } return sshConnection; } catch (final IOException e) { s_logger.warn("Get SSH connection failed", e); return null; } }
/** * {@inheritDoc} */ @Override public boolean canAuthenticate() { try { for (String authMethod : getConnection().getRemainingAuthMethods(getUsername())) { if ("password".equals(authMethod)) { // prefer password return true; } if ("keyboard-interactive".equals(authMethod)) { return true; } } } catch (IOException e) { e.printStackTrace(getListener().error("Failed to authenticate")); } return false; }
String[] methods = connection.getRemainingAuthMethods(myUserName); for (int i = 0; !authenticated && i < methods.length; i++) { if ("password".equals(methods[i])) {
boolean tried = false; List<String> availableMethods = Arrays.asList(connection.getRemainingAuthMethods(username)); if (availableMethods.contains("password")) {
authenticated = connection.authenticateWithPublicKey(userName, privateKey, passphrase); } else if (password != null) { String[] methods = connection.getRemainingAuthMethods(userName); authenticated = false; for (int i = 0; i < methods.length; i++) {
authenticated = connection.authenticateWithPublicKey(userName, privateKey, passphrase); } else if (password != null) { String[] methods = connection.getRemainingAuthMethods(userName); authenticated = false; for (int i = 0; i < methods.length; i++) {