Search in sources :

Example 6 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator in project big-data-plugin by pentaho.

the class S3VfsFileChooserBaseDialog method getFileSystemOptions.

private FileSystemOptions getFileSystemOptions() throws FileSystemException {
    FileSystemOptions opts = new FileSystemOptions();
    try {
        String accessKey = "";
        String secretKey = "";
        /* For legacy transformations containing AWS S3 access credentials, {@link Const#KETTLE_USE_AWS_DEFAULT_CREDENTIALS} can force Spoon to use
       * the Amazon Default Credentials Provider Chain instead of using the credentials embedded in the transformation metadata. */
        if (!ValueMetaBase.convertStringToBoolean(Const.NVL(EnvUtil.getSystemProperty(Const.KETTLE_USE_AWS_DEFAULT_CREDENTIALS), "N"))) {
            accessKey = System.getProperty(S3Util.ACCESS_KEY_SYSTEM_PROPERTY);
            secretKey = System.getProperty(S3Util.SECRET_KEY_SYSTEM_PROPERTY);
        } else {
            AWSCredentials credentials = S3CredentialsProvider.getAWSCredentials();
            if (credentials != null) {
                accessKey = credentials.getAWSAccessKeyId();
                secretKey = credentials.getAWSSecretKey();
            }
        }
        StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(null, secretKey, accessKey);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator);
    } catch (SdkClientException e) {
        throw new FileSystemException(e);
    }
    return opts;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) SdkClientException(com.amazonaws.SdkClientException) StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) AWSCredentials(com.amazonaws.auth.AWSCredentials) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 7 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator in project big-data-plugin by pentaho.

the class AbstractAmazonJobExecutorController method getFileSystemOptions.

protected FileSystemOptions getFileSystemOptions() throws FileSystemException {
    FileSystemOptions opts = new FileSystemOptions();
    if (!Const.isEmpty(getAccessKey()) || !Const.isEmpty(getSecretKey())) {
        // create a FileSystemOptions with user & password
        StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(null, getVariableSpace().environmentSubstitute(getAccessKey()), getVariableSpace().environmentSubstitute(getSecretKey()));
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator);
    }
    return opts;
}
Also used : StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 8 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator in project big-data-plugin by pentaho.

the class S3FileSystemTest method testGetS3Service.

@Test
public void testGetS3Service() throws Exception {
    assertNotNull(fileSystem.getS3Client());
    FileSystemOptions options = new FileSystemOptions();
    UserAuthenticator authenticator = mock(UserAuthenticator.class);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator);
    fileSystem = new S3FileSystem(fileName, options);
    assertNotNull(fileSystem.getS3Client());
}
Also used : UserAuthenticator(org.apache.commons.vfs2.UserAuthenticator) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 9 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator in project big-data-plugin by pentaho.

the class S3NFileSystemTest method testGetS3Service.

@Test
public void testGetS3Service() throws Exception {
    assertNotNull(fileSystem.getS3Client());
    FileSystemOptions options = new FileSystemOptions();
    UserAuthenticator authenticator = mock(UserAuthenticator.class);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator);
    fileSystem = new S3NFileSystem(fileName, options);
    assertNotNull(fileSystem.getS3Client());
}
Also used : UserAuthenticator(org.apache.commons.vfs2.UserAuthenticator) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test) S3FileNameTest(org.pentaho.s3.vfs.S3FileNameTest)

Example 10 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator in project commons-vfs by apache.

the class Http5FileProvider method createHttpClientContext.

/**
 * Create an {@link HttpClientContext} object for an http4 file system.
 *
 * @param builder Configuration options builder for http4 provider
 * @param rootName The root path
 * @param fileSystemOptions The FileSystem options
 * @param authData The {@code UserAuthentiationData} object
 * @return an {@link HttpClientContext} object
 */
protected HttpClientContext createHttpClientContext(final Http5FileSystemConfigBuilder builder, final GenericFileName rootName, final FileSystemOptions fileSystemOptions, final UserAuthenticationData authData) {
    final HttpClientContext clientContext = HttpClientContext.create();
    final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    clientContext.setCredentialsProvider(credsProvider);
    final String username = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())));
    final char[] password = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()));
    if (!StringUtils.isEmpty(username)) {
        // set root port
        credsProvider.setCredentials(new AuthScope(rootName.getHostName(), rootName.getPort()), new UsernamePasswordCredentials(username, password));
    }
    final HttpHost proxyHost = getProxyHttpHost(builder, fileSystemOptions);
    if (proxyHost != null) {
        final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions);
        if (proxyAuth != null) {
            final UserAuthenticationData proxyAuthData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD });
            if (proxyAuthData != null) {
                final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.USERNAME, null)), UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.PASSWORD, null));
                // set proxy host port
                credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), proxyCreds);
            }
            if (builder.isPreemptiveAuth(fileSystemOptions)) {
                final AuthCache authCache = new BasicAuthCache();
                final BasicScheme basicAuth = new BasicScheme();
                authCache.put(proxyHost, basicAuth);
                clientContext.setAuthCache(authCache);
            }
        }
    }
    return clientContext;
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) BasicScheme(org.apache.hc.client5.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) HttpHost(org.apache.hc.core5.http.HttpHost) UserAuthenticator(org.apache.commons.vfs2.UserAuthenticator) AuthScope(org.apache.hc.client5.http.auth.AuthScope) AuthCache(org.apache.hc.client5.http.auth.AuthCache) BasicAuthCache(org.apache.hc.client5.http.impl.auth.BasicAuthCache) HttpClientContext(org.apache.hc.client5.http.protocol.HttpClientContext) BasicAuthCache(org.apache.hc.client5.http.impl.auth.BasicAuthCache) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials)

Aggregations

UserAuthenticator (org.apache.commons.vfs2.UserAuthenticator)9 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)6 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)6 StaticUserAuthenticator (org.apache.commons.vfs2.auth.StaticUserAuthenticator)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 Test (org.junit.jupiter.api.Test)2 SdkClientException (com.amazonaws.SdkClientException)1 File (java.io.File)1 Cookie (org.apache.commons.httpclient.Cookie)1 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 HttpConnectionManager (org.apache.commons.httpclient.HttpConnectionManager)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 AuthScope (org.apache.commons.httpclient.auth.AuthScope)1 HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)1 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)1 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)1