Example usage for org.apache.commons.vfs UserAuthenticator requestAuthentication

List of usage examples for org.apache.commons.vfs UserAuthenticator requestAuthentication

Introduction

In this page you can find the example usage for org.apache.commons.vfs UserAuthenticator requestAuthentication.

Prototype

public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types);

Source Link

Document

queries the given type from the user

Usage

From source file:org.pentaho.s3.vfs.S3FileSystem.java

public S3Service getS3Service() {
    if (service == null || service.getProviderCredentials() == null
            || service.getProviderCredentials().getAccessKey() == null) {

        UserAuthenticator userAuthenticator = DefaultFileSystemConfigBuilder.getInstance()
                .getUserAuthenticator(getFileSystemOptions());

        String awsAccessKey = null;
        String awsSecretKey = null;

        if (userAuthenticator != null) {
            UserAuthenticationData data = userAuthenticator
                    .requestAuthentication(S3FileProvider.AUTHENTICATOR_TYPES);
            awsAccessKey = String.valueOf(data.getData(UserAuthenticationData.USERNAME));
            awsSecretKey = String.valueOf(data.getData(UserAuthenticationData.PASSWORD));
        } else {/*from   w  w  w  . j  a v  a 2 s  . com*/
            awsAccessKey = ((URLFileName) getRootName()).getUserName();
            awsSecretKey = ((URLFileName) getRootName()).getPassword();
        }
        ProviderCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
        try {
            service = new RestS3Service(awsCredentials);
        } catch (Throwable t) {
            System.out.println("Could not getS3Service() for " + awsCredentials.getLogString());
            t.printStackTrace();
        }
    }
    return service;
}