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