Search in sources :

Example 1 with UserAuthenticationData

use of org.apache.commons.vfs2.UserAuthenticationData in project pentaho-kettle by pentaho.

the class SftpFileSystemWindows method ensureSession.

/**
 * {@link  org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() }
 */
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;
    }
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) GenericFileName(org.apache.commons.vfs2.provider.GenericFileName) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException) Session(com.jcraft.jsch.Session)

Example 2 with UserAuthenticationData

use of org.apache.commons.vfs2.UserAuthenticationData in project artisynth_core by artisynth.

the class ConsoleUserAuthenticator method requestAuthentication.

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;
                }
            }
            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;
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 3 with UserAuthenticationData

use of org.apache.commons.vfs2.UserAuthenticationData in project artisynth_core by artisynth.

the class EncryptedUserAuthenticator method requestAuthentication.

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();
            }
        }
    }
    return data;
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) Type(org.apache.commons.vfs2.UserAuthenticationData.Type)

Example 4 with UserAuthenticationData

use of org.apache.commons.vfs2.UserAuthenticationData 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;
}
Also used : UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData)

Aggregations

UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)4 IOException (java.io.IOException)2 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 Type (org.apache.commons.vfs2.UserAuthenticationData.Type)1 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)1