Example usage for org.apache.commons.vfs2.impl DefaultFileSystemConfigBuilder setUserAuthenticator

List of usage examples for org.apache.commons.vfs2.impl DefaultFileSystemConfigBuilder setUserAuthenticator

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.impl DefaultFileSystemConfigBuilder setUserAuthenticator.

Prototype

public void setUserAuthenticator(final FileSystemOptions opts, final UserAuthenticator userAuthenticator)
        throws FileSystemException 

Source Link

Document

Sets the user authenticator to get authentication informations.

Usage

From source file:org.aludratest.service.file.impl.FileServiceConfiguration.java

/** Creates a new FileServiceConfiguration object which wraps the given Preferences object.
 * //from   w ww.j av  a 2s . c  o  m
 * @param configuration Preferences configuration object to wrap.
 * 
 * @throws FileSystemException If an exception occurs when applying the configuration to the VFS Config Builders. */
public FileServiceConfiguration(Preferences configuration) throws FileSystemException {
    this.configuration = new ValidatingPreferencesWrapper(configuration);

    // Configure secured access
    FileSystemOptions fileSystemOptions = new FileSystemOptions();
    String protocol = getProtocol();
    String baseUrl = getBaseUrl();
    String user = getUser();
    String password = getPassword();

    if (user != null || password != null) {
        UserAuthenticator authenticator = new StaticUserAuthenticator(protocol, user, password);
        DefaultFileSystemConfigBuilder builder = DefaultFileSystemConfigBuilder.getInstance();
        builder.setUserAuthenticator(fileSystemOptions, authenticator);
    }
    if ("ftp".equals(protocol)) {
        FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
        builder.setUserDirIsRoot(fileSystemOptions, false);
        builder.setDataTimeout(fileSystemOptions, getTimeout());
        builder.setSoTimeout(fileSystemOptions, getTimeout());
        builder.setPassiveMode(fileSystemOptions, true);
    }

    // configure FileObject for root folder
    this.manager = new StandardFileSystemManager();
    this.manager.init();
    this.rootFolder = manager.resolveFile(protocol + "://" + baseUrl, fileSystemOptions);

    // access all configuration element in order to verify a complete configuration
    getEncoding();
    getLinefeed();
    getPollingDelay();
    getWaitMaxRetries();
    getTimeout();
    getRootFolder();
    getFileObject("/");
    getHost();
    isWritingPermitted();

}