Search in sources :

Example 1 with GenericFileName

use of org.apache.commons.vfs2.provider.GenericFileName 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 GenericFileName

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

the class SftpFileObjectWithWindowsSupportTest method getLinuxFileObject.

private static FileObject getLinuxFileObject(boolean posixReadable, boolean posixWritable) throws Exception {
    GenericFileName fileName = mock(GenericFileName.class);
    doReturn(PATH).when(fileName).getPath();
    Session session = mock(Session.class);
    SftpFileSystemWindows sftpFileSystem = spy(new SftpFileSystemWindows(fileName, session, null));
    doReturn(false).when(sftpFileSystem).isRemoteHostWindows();
    int permissions = 0;
    if (posixReadable) {
        permissions += 256;
    }
    if (posixWritable) {
        permissions += 128;
    }
    PosixPermissions posixPermissions = new PosixPermissions(permissions, true, true);
    return new SftpFileObjectWithWindowsSupport(fileName, sftpFileSystem) {

        @Override
        public PosixPermissions getPermissions(boolean checkIds) {
            return posixPermissions;
        }

        @Override
        public FileType getType() {
            return FileType.FILE;
        }
    };
}
Also used : GenericFileName(org.apache.commons.vfs2.provider.GenericFileName) PosixPermissions(org.apache.commons.vfs2.util.PosixPermissions) Session(com.jcraft.jsch.Session)

Example 3 with GenericFileName

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

the class SftpFileObjectWithWindowsSupportTest method getWindowsFileObject.

private static FileObject getWindowsFileObject(boolean windowsReadable, boolean windowsWritable) throws Exception {
    GenericFileName fileName = mock(GenericFileName.class);
    Session session = mock(Session.class);
    doReturn(PATH).when(fileName).getPath();
    SftpFileSystemWindows sftpFileSystem = spy(new SftpFileSystemWindows(fileName, session, null));
    doReturn(true).when(sftpFileSystem).isRemoteHostWindows();
    List<String> groups = new ArrayList<>();
    groups.add(USERS);
    doReturn(groups).when(sftpFileSystem).getUserGroups();
    HashMap<String, String> permissions = new HashMap<>();
    doReturn(permissions).when(sftpFileSystem).getFilePermission(PATH);
    if (windowsReadable) {
        permissions.put(USERS, PERMISSION_READ);
    }
    if (windowsWritable) {
        permissions.put(USERS, PERMISSION_WRITE);
    }
    PosixPermissions posixPermissions = new PosixPermissions(0, true, true);
    return new SftpFileObjectWithWindowsSupport(fileName, sftpFileSystem) {

        @Override
        public PosixPermissions getPermissions(boolean checkIds) {
            return posixPermissions;
        }

        @Override
        public FileType getType() {
            return FileType.FILE;
        }
    };
}
Also used : GenericFileName(org.apache.commons.vfs2.provider.GenericFileName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PosixPermissions(org.apache.commons.vfs2.util.PosixPermissions) Session(com.jcraft.jsch.Session)

Aggregations

Session (com.jcraft.jsch.Session)3 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)3 PosixPermissions (org.apache.commons.vfs2.util.PosixPermissions)2 JSchException (com.jcraft.jsch.JSchException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)1