Example usage for org.apache.commons.vfs UserAuthenticationData getData

List of usage examples for org.apache.commons.vfs UserAuthenticationData getData

Introduction

In this page you can find the example usage for org.apache.commons.vfs UserAuthenticationData getData.

Prototype

public char[] getData(Type type) 

Source Link

Document

get a data from the collection

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 {/* w ww. j a v  a  2 s . co  m*/
            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;
}