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