/** * Authenticate {@code username} using the {@code "password"} authentication method and as a * fallback basic challenge-response authentication.. The {@code password} array is blanked out * after use. * * @param username user to authenticate * @param password the password to use for authentication * @throws UserAuthException in case of authentication failure * @throws TransportException if there was a transport-layer error */ public void authPassword(final String username, final char[] password) throws UserAuthException, TransportException { try { authPassword( username, new PasswordFinder() { @Override public char[] reqPassword(Resource<?> resource) { return password.clone(); } @Override public boolean shouldRetry(Resource<?> resource) { return false; } }); } finally { PasswordUtils.blankOut(password); } }
/** * Utility function for createing a {@link KeyProvider} instance from given location on the file * system. Creates a one-off {@link PasswordFinder} using {@link * PasswordUtils#createOneOff(char[])}, and calls {@link #loadKeys(String, PasswordFinder)}. * * @param location location of the key file * @param passphrase passphrase as a char-array * @return the key provider ready for use in authentication * @throws SSHException if there was no suitable key provider available for the file format; * typically because BouncyCastle is not in the classpath * @throws IOException if the key file format is not known, if the file could not be read, etc. */ public KeyProvider loadKeys(String location, char[] passphrase) throws IOException { return loadKeys(location, PasswordUtils.createOneOff(passphrase)); }