Search in sources :

Example 6 with StaticUserAuthenticator

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

the class Http4GetContentInfoTest method getOptionsWithProxyAuthentication.

private FileSystemOptions getOptionsWithProxyAuthentication() throws MalformedURLException {
    // get proxy host and port from env var "https_proxy"
    String proxyHost = null;
    int proxyPort = -1;
    String[] user = null;
    final String proxyUrl = System.getenv("https_proxy");
    if (proxyUrl != null) {
        final URL url = new URL(proxyUrl);
        proxyHost = url.getHost();
        proxyPort = url.getPort();
        final String userInfo = url.getUserInfo();
        if (userInfo != null) {
            user = userInfo.split(":");
        }
    }
    // return null if proxy host or port invalid
    if (proxyHost == null || proxyPort == -1) {
        return null;
    }
    // return options with proxy
    final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
    final FileSystemOptions opts = new FileSystemOptions();
    builder.setProxyHost(opts, proxyHost);
    builder.setProxyPort(opts, proxyPort);
    if (user != null) {
        builder.setProxyAuthenticator(opts, new StaticUserAuthenticator(null, user[0], user[1]));
    }
    return opts;
}
Also used : StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) URL(java.net.URL) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 7 with StaticUserAuthenticator

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

the class Http5GetContentInfoTest method getOptionsWithProxyAuthentication.

private FileSystemOptions getOptionsWithProxyAuthentication() throws MalformedURLException {
    // get proxy host and port from env var "https_proxy"
    String proxyHost = null;
    int proxyPort = -1;
    String[] user = null;
    final String proxyUrl = System.getenv("https_proxy");
    if (proxyUrl != null) {
        final URL url = new URL(proxyUrl);
        proxyHost = url.getHost();
        proxyPort = url.getPort();
        final String userInfo = url.getUserInfo();
        if (userInfo != null) {
            user = userInfo.split(":");
        }
    }
    // return null if proxy host or port invalid
    if (proxyHost == null || proxyPort == -1) {
        return null;
    }
    // return options with proxy
    final Http5FileSystemConfigBuilder builder = Http5FileSystemConfigBuilder.getInstance();
    final FileSystemOptions opts = new FileSystemOptions();
    builder.setProxyHost(opts, proxyHost);
    builder.setProxyPort(opts, proxyPort);
    if (user != null) {
        builder.setProxyAuthenticator(opts, new StaticUserAuthenticator(null, user[0], user[1]));
    }
    return opts;
}
Also used : StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) URL(java.net.URL) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 8 with StaticUserAuthenticator

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

the class StaticUserAuthenticatorTest method testAuthenticationRequest.

@Test
public void testAuthenticationRequest() {
    final UserAuthenticator userAuthenticator = new StaticUserAuthenticator("DOMAIN", "USER", "PWD");
    UserAuthenticationData authenticationData = userAuthenticator.requestAuthentication(ArrayUtils.toArray(UserAuthenticationData.DOMAIN));
    assertArrayEquals("DOMAIN".toCharArray(), authenticationData.getData(UserAuthenticationData.DOMAIN));
    assertNull(authenticationData.getData(UserAuthenticationData.USERNAME));
    assertNull(authenticationData.getData(UserAuthenticationData.PASSWORD));
    authenticationData = userAuthenticator.requestAuthentication(ArrayUtils.toArray(UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD));
    assertNull(authenticationData.getData(UserAuthenticationData.DOMAIN));
    assertArrayEquals("USER".toCharArray(), authenticationData.getData(UserAuthenticationData.USERNAME));
    assertArrayEquals("PWD".toCharArray(), authenticationData.getData(UserAuthenticationData.PASSWORD));
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) UserAuthenticator(org.apache.commons.vfs2.UserAuthenticator) Test(org.junit.jupiter.api.Test)

Example 9 with StaticUserAuthenticator

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

the class S3FileOutputDialog method getFileSystemOptions.

protected FileSystemOptions getFileSystemOptions() throws FileSystemException {
    FileSystemOptions opts = new FileSystemOptions();
    S3Util.S3Keys keys = S3Util.getKeysFromURI(wFilename.getText());
    if (keys == null) {
        AWSCredentials credentials = S3CredentialsProvider.getAWSCredentials();
        if (credentials != null) {
            StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(null, credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey());
            DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator);
        }
    } else {
        StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator(null, keys.getAccessKey(), keys.getSecretKey());
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator);
    }
    return opts;
}
Also used : StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) AWSCredentials(com.amazonaws.auth.AWSCredentials) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 10 with StaticUserAuthenticator

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

the class AbstractAmazonJobExecutor method getS3FileObjectPath.

private String getS3FileObjectPath() throws FileSystemException, KettleFileException {
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, new StaticUserAuthenticator(null, getAWSAccessKeyId(), getAWSSecretKey()));
    FileObject stagingDirFileObject = KettleVFS.getFileObject(stagingDir, getVariables(), opts);
    return stagingDirFileObject.getName().getPath();
}
Also used : StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) FileObject(org.apache.commons.vfs2.FileObject) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Aggregations

StaticUserAuthenticator (org.apache.commons.vfs2.auth.StaticUserAuthenticator)10 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)9 FileObject (org.apache.commons.vfs2.FileObject)3 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 UserAuthenticator (org.apache.commons.vfs2.UserAuthenticator)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 URL (java.net.URL)2 Test (org.junit.jupiter.api.Test)2 SdkClientException (com.amazonaws.SdkClientException)1 File (java.io.File)1 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)1 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)1 FtpImportedFile (org.meveo.model.jobs.FtpImportedFile)1 VariableSpace (org.pentaho.di.core.variables.VariableSpace)1