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:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java

public static void uploadFile(String accntName, String acctHost, String accntKey, String containerName,
        Path localFile, Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider());
    currMan.addProvider("file", new DefaultLocalFileProvider());
    currMan.init();//from   www  . ja v  a  2s  .com

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, acctHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);
    FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile));

    currFile.copyFrom(currFile2, Selectors.SELECT_SELF);

    currFile.close();
    currMan.close();
}

From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java

public static void uploadFile(String accntName, String accntHost, String accntKey, String containerName,
        Path localFile, Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider());
    currMan.addProvider("file", new DefaultLocalFileProvider());
    currMan.init();//from ww w  .  j av a 2  s. c  o  m

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);
    FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile));

    currFile.copyFrom(currFile2, Selectors.SELECT_SELF);

    currFile.close();
    currMan.close();
}

From source file:net.sourceforge.fullsync.fs.filesystems.SmbAuthProvider.java

@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options)
        throws FileSystemException {
    String username = description.getUsername().orElse(""); //$NON-NLS-1$
    String password = description.getPassword().orElse(""); //$NON-NLS-1$
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}

From source file:net.sourceforge.fullsync.fs.filesystems.FTPFileSystem.java

@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options)
        throws FileSystemException {
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null,
            description.getParameter(ConnectionDescription.PARAMETER_USERNAME),
            description.getSecretParameter(ConnectionDescription.PARAMETER_PASSWORD));
    FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}

From source file:net.sourceforge.fullsync.fs.filesystems.FTPAuthenticationProvider.java

@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options)
        throws FileSystemException {
    String username = description.getUsername().orElse(""); //$NON-NLS-1$
    String password = description.getPassword().orElse(""); //$NON-NLS-1$
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
    FtpFileSystemConfigBuilder cfg = FtpFileSystemConfigBuilder.getInstance();
    cfg.setPassiveMode(options, true);/*from  w w  w.  j  a va 2  s.co m*/
    cfg.setUserDirIsRoot(options, description.isUserDirIsRoot());
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java

public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName,
        Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider());
    currMan.init();/*  w w  w. j  a  v a2s .co  m*/

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    Boolean delRes = currFile.delete();
    Assert.assertTrue(delRes);
}

From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java

public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName,
        Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider());
    currMan.init();/*from w  w w .  ja  v a 2  s.c  om*/

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    Boolean delRes = currFile.delete();
    Assert.assertTrue(delRes);
}

From source file:com.codehaus.mojo.vfs.FileSystemOptionsFactory.java

public FileSystemOptions getFileSystemOptions(String url, String username, String password)
        throws FileSystemException {

    FileSystemOptions opts = new FileSystemOptions();

    String[] tokens = StringUtils.split(url, ":");

    String protocol = tokens[0];//from  w w  w  .  jav a  2  s  .  c  o  m

    if ("ftp".equals(protocol)) {
        FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
        builder.setPassiveMode(opts, ftpSettings.isPassiveMode());
        builder.setUserDirIsRoot(opts, ftpSettings.isUserDirIsRoot());
    }
    if ("sftp".equals(protocol)) {
        SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
        builder.setUserDirIsRoot(opts, sftpSettings.isUserDirIsRoot());
    }

    String domain = null;
    tokens = StringUtils.split("\\");
    if (tokens.length == 2) {
        domain = tokens[0];
        username = tokens[1];
    }

    StaticUserAuthenticator auth = new StaticUserAuthenticator(domain, username, password);

    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    return opts;
}

From source file:gobblin.example.simplejson.SimpleJsonExtractor.java

public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException {
    this.workUnitState = workUnitState;

    // Resolve the file to pull
    if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) {
        // Add authentication credential if authentication is needed
        UserAuthenticator auth = new StaticUserAuthenticator(
                workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""),
                workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME),
                PasswordManager.getInstance(workUnitState)
                        .readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD)));
        FileSystemOptions opts = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts);
    } else {/*from  w w w  . j  ava 2s  .  co  m*/
        this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY));
    }

    // Open the file for reading
    LOGGER.info("Opening file " + this.fileObject.getURL().toString());
    this.bufferedReader = this.closer
            .register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(),
                    ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java

/**
 * ??//w  ww  .  java 2  s. c o m
 * 
 * @param opts 
 * @param username ??
 * @param password ?
 * @throws FileSystemException
 */
protected void setAuthenticator(FileSystemOptions opts, String username, String password)
        throws FileSystemException {
    if (username != null) {
        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
    }
}