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;
}
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;
}
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());
}
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());
}
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;
}
Aggregations