Search in sources :

Example 11 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator 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 12 with UserAuthenticator

use of org.apache.commons.vfs2.UserAuthenticator 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 13 with UserAuthenticator

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

the class FtpAdapterJobBean method initialize.

/**
 * Creates the download directory localDir if it does not exist and makes a connection to the remote SFTP server.
 *
 * @param localDir the local dir
 * @param userName the user name
 * @param password the password
 * @param filePatternString the file pattern string
 * @param isSftp the is sftp
 * @throws FileSystemException the file system exception
 */
private void initialize(String localDir, String userName, String password, String filePatternString, boolean isSftp) throws FileSystemException {
    localDirFile = new File(localDir);
    if (!localDirFile.exists()) {
        localDirFile.mkdirs();
    }
    try {
        fsManager = VFS.getManager();
    } catch (FileSystemException ex) {
        throw new RuntimeException("failed to get fsManager from VFS", ex);
    }
    UserAuthenticator auth = new StaticUserAuthenticator(null, userName, password);
    opts = getSftpOptions(isSftp);
    try {
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
    } catch (FileSystemException ex) {
        throw new RuntimeException("setUserAuthenticator failed", ex);
    }
    if ("false".equals(paramBeanFactory.getInstance().getProperty("ftpAdapter.useExtentionAsRegex", "false"))) {
        filePattern = Pattern.compile(".*" + filePatternString);
    } else {
        filePattern = Pattern.compile(filePatternString);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) UserAuthenticator(org.apache.commons.vfs2.UserAuthenticator) StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) StaticUserAuthenticator(org.apache.commons.vfs2.auth.StaticUserAuthenticator) FtpImportedFile(org.meveo.model.jobs.FtpImportedFile) LocalFile(org.apache.commons.vfs2.provider.local.LocalFile) File(java.io.File)

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