use of org.apache.commons.vfs2.UserAuthenticator in project artisynth_core by artisynth.
the class EncryptedUserAuthenticator method equals.
public boolean equals(UserAuthenticator obj) {
UserAuthenticationData data = obj.requestAuthentication(ALL_AUTH_DATA);
String str = new String(data.getData(UserAuthenticationData.DOMAIN));
if (!equals(str, domain)) {
return false;
}
str = new String(data.getData(UserAuthenticationData.USERNAME));
if (!equals(str, username)) {
return false;
}
str = new String(data.getData(UserAuthenticationData.PASSWORD));
try {
// encrypt password
str = getCryptor().encrypt(str);
if (!equals(str, encryptedPassword)) {
return false;
}
} catch (Exception e) {
}
return true;
}
use of org.apache.commons.vfs2.UserAuthenticator in project hop by apache.
the class S3NFileSystemTest method testGetS3Service.
@Test
public void testGetS3Service() throws Exception {
assertNotNull(fileSystem.getS3Client());
FileSystemOptions options = new FileSystemOptions();
UserAuthenticator authenticator = mock(UserAuthenticator.class);
UserAuthenticationData authData = mock(UserAuthenticationData.class);
when(authenticator.requestAuthentication(S3FileProvider.AUTHENTICATOR_TYPES)).thenReturn(authData);
when(authData.getData(UserAuthenticationData.USERNAME)).thenReturn("username".toCharArray());
when(authData.getData(UserAuthenticationData.PASSWORD)).thenReturn("password".toCharArray());
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 StaticUserAuthenticatorTest method testEquality.
@Test
public void testEquality() {
final UserAuthenticator userAuthenticator = new StaticUserAuthenticator("DOMAIN", "USER", "PWD");
assertEquals(new StaticUserAuthenticator("DOMAIN", "USER", "PWD"), userAuthenticator);
assertNotEquals(new StaticUserAuthenticator("DOMAIN", "USER", null), userAuthenticator);
assertNotEquals(new StaticUserAuthenticator("DOMAIN", null, "PWD"), userAuthenticator);
assertNotEquals(new StaticUserAuthenticator(null, "USER", "PWD"), userAuthenticator);
assertEquals(new StaticUserAuthenticator("DOMAIN", "USER", "PWD").hashCode(), userAuthenticator.hashCode());
}
use of org.apache.commons.vfs2.UserAuthenticator in project commons-vfs by apache.
the class HttpClientFactory method createConnection.
/**
* Creates a new connection to the server.
*
* @param builder The HttpFileSystemConfigBuilder.
* @param scheme The protocol.
* @param hostname The hostname.
* @param port The port number.
* @param username The username.
* @param password The password
* @param fileSystemOptions The file system options.
* @return a new HttpClient connection.
* @throws FileSystemException if an error occurs.
* @since 2.0
*/
public static HttpClient createConnection(final HttpFileSystemConfigBuilder builder, final String scheme, final String hostname, final int port, final String username, final String password, final FileSystemOptions fileSystemOptions) throws FileSystemException {
final HttpClient client;
try {
final HttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
final HttpConnectionManagerParams connectionMgrParams = mgr.getParams();
client = new HttpClient(mgr);
final HostConfiguration config = new HostConfiguration();
config.setHost(hostname, port, scheme);
if (fileSystemOptions != null) {
final String proxyHost = builder.getProxyHost(fileSystemOptions);
final int proxyPort = builder.getProxyPort(fileSystemOptions);
if (!StringUtils.isEmpty(proxyHost) && proxyPort > 0) {
config.setProxy(proxyHost, proxyPort);
}
final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions);
if (proxyAuth != null) {
final UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD });
if (authData != null) {
final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)), UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));
final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT);
client.getState().setProxyCredentials(scope, proxyCreds);
}
if (builder.isPreemptiveAuth(fileSystemOptions)) {
final HttpClientParams httpClientParams = new HttpClientParams();
httpClientParams.setAuthenticationPreemptive(true);
client.setParams(httpClientParams);
}
}
final Cookie[] cookies = builder.getCookies(fileSystemOptions);
if (cookies != null) {
client.getState().addCookies(cookies);
}
}
/*
* ConnectionManager set methods must be called after the host & port and proxy host & port are set in the
* HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams tries to locate
* the host configuration.
*/
connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions));
connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions));
connectionMgrParams.setConnectionTimeout(DurationUtils.toMillisInt(builder.getConnectionTimeoutDuration(fileSystemOptions)));
connectionMgrParams.setSoTimeout(DurationUtils.toMillisInt(builder.getSoTimeoutDuration(fileSystemOptions)));
client.setHostConfiguration(config);
if (username != null) {
final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
final AuthScope scope = new AuthScope(hostname, AuthScope.ANY_PORT);
client.getState().setCredentials(scope, creds);
}
} catch (final Exception exc) {
throw new FileSystemException("vfs.provider.http/connect.error", exc, hostname);
}
return client;
}
use of org.apache.commons.vfs2.UserAuthenticator in project commons-vfs by apache.
the class Http4FileProvider 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 Http4FileSystemConfigBuilder builder, final GenericFileName rootName, final FileSystemOptions fileSystemOptions, final UserAuthenticationData authData) {
final HttpClientContext clientContext = HttpClientContext.create();
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
clientContext.setCredentialsProvider(credsProvider);
final String username = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())));
final String password = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())));
if (!StringUtils.isEmpty(username)) {
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.toString(UserAuthenticatorUtils.getData(proxyAuthData, UserAuthenticationData.PASSWORD, null)));
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