Example usage for org.apache.commons.vfs2 UserAuthenticationData USERNAME

List of usage examples for org.apache.commons.vfs2 UserAuthenticationData USERNAME

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 UserAuthenticationData USERNAME.

Prototype

Type USERNAME

To view the source code for org.apache.commons.vfs2 UserAuthenticationData USERNAME.

Click Source Link

Document

The user name.

Usage

From source file:maspack.fileutil.vfs.ConsoleUserAuthenticator.java

public UserAuthenticationData requestAuthentication(Type[] types) {

    UserAuthenticationData data = new UserAuthenticationData();
    System.out.println("Authentication requested...");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    for (int i = 0; i < types.length; i++) {

        if (types[i] == UserAuthenticationData.DOMAIN) {
            System.out.print("Domain: ");
            String domain = storage.get(UserAuthenticationData.DOMAIN);
            if (domain == null) {
                try {
                    domain = in.readLine();
                    //      storage.put(UserAuthenticationData.DOMAIN, domain);
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }/*from w ww  . j av a  2 s .  c o m*/
            }
            data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
        } else if (types[i] == UserAuthenticationData.USERNAME) {
            System.out.print("Username: ");
            String user = storage.get(UserAuthenticationData.DOMAIN);
            if (user == null) {
                try {
                    user = in.readLine();
                    // storage.put(UserAuthenticationData.USERNAME, user);
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
            }
            data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(user));
        } else if (types[i] == UserAuthenticationData.PASSWORD) {
            System.out.print("Password: ");
            String pass = storage.get(UserAuthenticationData.PASSWORD);
            if (pass == null) {
                try {
                    pass = in.readLine();
                    //       storage.put(UserAuthenticationData.PASSWORD, pass);
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
            }
            data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(pass));
        }

    }

    return data;
}

From source file:maspack.fileutil.vfs.SimpleUserAuthenticator.java

public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {

    UserAuthenticationData data = new UserAuthenticationData();
    for (Type type : types) {
        if (type == UserAuthenticationData.DOMAIN) {
            data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
        } else if (type == UserAuthenticationData.USERNAME) {
            data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(username));
        } else if (type == UserAuthenticationData.PASSWORD) {
            try {
                // unfortunately, we seem to have to pass it in plaintext
                data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(password));
            } catch (Exception e) {
                e.printStackTrace();//from  w ww  .ja v  a  2s.  c  o m
            }
        }
    }
    return data;
}

From source file:maspack.fileutil.vfs.EncryptedUserAuthenticator.java

public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {

    UserAuthenticationData data = new UserAuthenticationData();
    for (Type type : types) {
        if (type == UserAuthenticationData.DOMAIN) {
            data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
        } else if (type == UserAuthenticationData.USERNAME) {
            data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(username));
        } else if (type == UserAuthenticationData.PASSWORD) {
            try {
                // unfortunately, we have to pass it in plaintext, but the original password
                // could be encrypted from the get-go using the global Cryptor
                String passwd = getCryptor().decrypt(encryptedPassword);
                char[] chars = UserAuthenticatorUtils.toChar(passwd);
                data.setData(UserAuthenticationData.PASSWORD, chars);
            } catch (Exception e) {
                e.printStackTrace();// ww  w.  ja  v  a 2s.  c  o m
            }
        }
    }
    return data;
}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GridFTPClientWrapper.java

/**
 * Creates the client./*from www .  j  a v  a  2  s.  com*/
 * 
 * @return the grid ftp client
 * 
 * @throws FileSystemException the file system exception
 */
protected GridFTPClient createClient() throws FileSystemException {
    final GenericFileName rootName = getRoot();

    UserAuthenticationData authData = null;
    try {
        authData = UserAuthenticatorUtils.authenticate(fileSystemOptions,
                GsiFtpFileProvider.AUTHENTICATOR_TYPES);

        String username = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                UserAuthenticatorUtils.toChar(rootName.getUserName())).toString();
        String password = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                UserAuthenticatorUtils.toChar(rootName.getPassword())).toString();
        return GsiFtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), username,
                password, getFileSystemOptions());
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }
}

From source file:maspack.fileutil.vfs.SimpleUserAuthenticator.java

public boolean equals(UserAuthenticator obj) {

    UserAuthenticationData data = obj.requestAuthentication(ALL_AUTH_DATA);

    try {/*from   ww  w.  j av  a  2s . c om*/
        String str = new String(data.getData(UserAuthenticationData.DOMAIN));
        if (!equals(str, domain)) {
            return false;
        }
    } catch (NullPointerException e) {
        // no domain
        if (domain != null) {
            return false;
        }
    }

    try {
        String str = new String(data.getData(UserAuthenticationData.USERNAME));
        if (!equals(str, username)) {
            return false;
        }
    } catch (NullPointerException e) {
        // no username
        if (username != null) {
            return false;
        }
    }

    try {
        String str = new String(data.getData(UserAuthenticationData.PASSWORD));

        if (!equals(str, password)) {
            return false;
        }
    } catch (Exception e) {
        // no password
        if (password != null) {
            return false;
        }
    }

    return true;
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProvider.java

/**
 * Create FileSystem event hook// ww w .  j a v  a  2s .c  om
 * 
 * @param rootName
 * @param fileSystemOptions
 * @return
 * @throws FileSystemException 
 */
@Override
protected FileSystem doCreateFileSystem(FileName rootName, FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    SS3FileSystem fileSystem = null;
    GenericFileName genRootName = (GenericFileName) rootName;

    AWSCredentials storageCreds;
    AmazonS3Client client;

    FileSystemOptions currFSO;
    UserAuthenticator ua;

    if (fileSystemOptions == null) {
        currFSO = getDefaultFileSystemOptions();
        ua = SS3FileSystemConfigBuilder.getInstance().getUserAuthenticator(currFSO);
    } else {
        currFSO = fileSystemOptions;
        ua = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(currFSO);
    }

    UserAuthenticationData authData = null;
    try {
        authData = ua.requestAuthentication(AUTHENTICATOR_TYPES);

        String currAcct = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(genRootName.getUserName())));

        String currKey = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(genRootName.getPassword())));

        storageCreds = new BasicAWSCredentials(currAcct, currKey);

        client = new AmazonS3Client(storageCreds);

        if (StringUtils.isNoneBlank(endpoint)) {
            client.setEndpoint(endpoint);
        }

        if (region != null) {
            client.setRegion(region);
        }

        fileSystem = new SS3FileSystem(genRootName, client, fileSystemOptions);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return fileSystem;
}

From source file:maspack.fileutil.vfs.EncryptedUserAuthenticator.java

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;
    }// ww  w  .j  a  va 2  s.co m

    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;
}

From source file:com.sludev.commons.vfs2.provider.azure.AzFileProvider.java

/**
 * Callback for handling the create File-System event
 * /*from  w ww .j  a  v  a2 s  .  c  o m*/
 * @param rootName
 * @param fileSystemOptions
 * @return
 * @throws FileSystemException 
 */
@Override
protected FileSystem doCreateFileSystem(FileName rootName, FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    AzFileSystem fileSystem = null;
    GenericFileName genRootName = (GenericFileName) rootName;

    StorageCredentials storageCreds;
    CloudStorageAccount storageAccount;
    CloudBlobClient client;

    FileSystemOptions currFSO = (fileSystemOptions != null) ? fileSystemOptions : getDefaultFileSystemOptions();
    UserAuthenticator ua = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(currFSO);

    UserAuthenticationData authData = null;
    try {
        authData = ua.requestAuthentication(AUTHENTICATOR_TYPES);

        String currAcct = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(genRootName.getUserName())));

        String currKey = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(genRootName.getPassword())));

        storageCreds = new StorageCredentialsAccountAndKey(currAcct, currKey);
        storageAccount = new CloudStorageAccount(storageCreds);

        client = storageAccount.createCloudBlobClient();

        fileSystem = new AzFileSystem(genRootName, client, fileSystemOptions);
    } catch (URISyntaxException ex) {
        throw new FileSystemException(ex);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return fileSystem;
}

From source file:org.esupportail.portlet.filemanager.services.vfs.auth.DynamicUserAuthenticator.java

public UserAuthenticationData requestAuthentication(Type[] types) {
    UserPassword userPassword = null;/*from  w  ww  .j  a v  a  2s  .  c  o m*/
    if (authenticatorService != null) {
        userPassword = authenticatorService.getUserPassword(userParameters);
    }
    if (userPassword == null)
        return null;
    UserAuthenticationData data = new UserAuthenticationData();
    data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(userPassword.getDomain()));
    data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(userPassword.getUsername()));
    data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(userPassword.getPassword()));
    return data;
}

From source file:org.pentaho.di.core.vfs.SftpFileSystemWindows.java

/**
 * {@link  org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() }
 *
 */// w ww  .  j  a  v  a  2s . c o  m
private void ensureSession() throws FileSystemException {
    if (this.session == null || !this.session.isConnected()) {
        this.doCloseCommunicationLink();
        UserAuthenticationData authData = null;

        Session session;
        try {
            GenericFileName e = (GenericFileName) this.getRootName();
            authData = UserAuthenticatorUtils.authenticate(this.getFileSystemOptions(),
                    SftpFileProvider.AUTHENTICATOR_TYPES);
            session = SftpClientFactory.createConnection(e.getHostName(), e.getPort(),
                    UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                            UserAuthenticatorUtils.toChar(e.getUserName())),
                    UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                            UserAuthenticatorUtils.toChar(e.getPassword())),
                    this.getFileSystemOptions());
        } catch (Exception var7) {
            throw new FileSystemException("vfs.provider.sftp/connect.error", this.getRootName(), var7);
        } finally {
            UserAuthenticatorUtils.cleanup(authData);
        }

        this.session = session;
    }

}