Example usage for org.apache.commons.vfs2.auth StaticUserAuthenticator StaticUserAuthenticator

List of usage examples for org.apache.commons.vfs2.auth StaticUserAuthenticator StaticUserAuthenticator

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.auth StaticUserAuthenticator StaticUserAuthenticator.

Prototype

public StaticUserAuthenticator(final String domain, final String username, final String password) 

Source Link

Usage

From source file:org.schedoscope.export.ftp.upload.Uploader.java

/**
 * A constructor to initialize a user name / pub key sftp connection.
 *
 * @param user       The username to use.
 * @param keyFile    The private key file.
 * @param passphrase The passphrase to use (can be null)
 * @param conf       The Hadoop Configuration object.
 * @param passive    A flag to use FTP passive mode (only for ftp connections).
 * @param userIsRoot A flag indicating the user dir is (s)ftp root dir.
 * @throws IOException Is thrown if an error occurs.
 *///from   w  w  w  .  j  a v a 2  s.  c  o m
public Uploader(String user, File keyFile, String passphrase, Configuration conf, boolean passive,
        boolean userIsRoot) throws IOException {

    initFileSystem(conf, passive, userIsRoot);

    // set up authentication - pub/priv key
    LOG.debug("setting up pub key authentication for sftp protocol");
    UserAuthenticator auth = new StaticUserAuthenticator(null, user, null);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    IdentityInfo ident = new IdentityInfo(keyFile);
    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
    SftpFileSystemConfigBuilder.getInstance().setUserInfo(opts, new PassphraseUserInfo(passphrase));
    SftpFileSystemConfigBuilder.getInstance().setIdentityInfo(opts, ident);
}

From source file:watchserver.server.WatchFTPRunner.java

public WatchFTPRunner(FTPConfig config) {
    this.config = config;
    try {/*from ww  w .  j a  v  a2  s .c om*/
        fsManager = VFS.getManager();

        UserAuthenticator auth = new StaticUserAuthenticator("", config.getConnection().getUsername(),
                config.getConnection().getPassword());
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
        FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);

        resolvedAbsPath = fsManager.resolveFile(config.getFolder() + config.getConnection().getPathtomonitor(),
                opts);

        log.info("Connection successfully established to " + resolvedAbsPath.getPublicURIString());
        log.debug("Exists: " + resolvedAbsPath.exists());
        log.debug("Type  : " + resolvedAbsPath.getType());
    } catch (FileSystemException e) {
        log.error("File system exception for " + config.getFolder(), e);
        //throw here?
    }
}