/** * {@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; } }
/** * Create a FileName. * * @param absPath The absolute path. * @param type The FileType. * @return The created FileName. */ @Override public FileName createName(final String absPath, final FileType type) { return new GenericFileName(getScheme(), hostName, port, defaultPort, userName, password, absPath, type); }
protected GenericFileName(final String scheme, final String hostName, final int port, final int defaultPort, final String userName, final String password, final String path, final FileType type) { super(scheme, path, type); this.hostName = hostName; this.defaultPort = defaultPort; this.password = password; this.userName = userName; if (port > 0) { this.port = port; } else { this.port = getDefaultPort(); } }
assertEquals("ftp", name.getScheme()); assertNull(name.getUserName()); assertNull(name.getPassword()); assertEquals("hostname", name.getHostName()); assertEquals(21, name.getPort()); assertEquals(name.getDefaultPort(), name.getPort()); assertEquals("/file", name.getPath()); assertEquals("ftp://hostname/", name.getRootURI()); assertEquals("ftp://hostname/file", name.getURI()); assertEquals("ftp", name.getScheme()); assertNull(name.getUserName()); assertNull(name.getPassword()); assertEquals("hostname", name.getHostName()); assertEquals(9090, name.getPort()); assertEquals("/file", name.getPath()); assertEquals("ftp://hostname:9090/", name.getRootURI()); assertEquals("ftp://hostname:9090/file", name.getURI()); assertEquals("ftp", name.getScheme()); assertNull(name.getUserName()); assertNull(name.getPassword()); assertEquals("hostname", name.getHostName()); assertEquals(21, name.getPort()); assertEquals("/", name.getPath()); assertEquals("ftp://hostname/", name.getRootURI()); assertEquals("ftp://hostname/", name.getURI()); assertEquals("ftp", name.getScheme());
assertEquals("ftp", name.getScheme()); assertEquals("hostname", name.getHostName()); assertEquals(21, name.getPort()); assertEquals(name.getDefaultPort(), name.getPort()); assertEquals("/file", name.getPath()); assertEquals("ftp://hostname/", name.getRootURI()); assertEquals("ftp://hostname/file", name.getURI()); assertEquals("ftp", name.getScheme()); assertEquals("hostname", name.getHostName()); assertEquals(9090, name.getPort()); assertEquals("/file", name.getPath()); assertEquals("ftp://hostname:9090/", name.getRootURI()); assertEquals("ftp://hostname:9090/file", name.getURI()); assertEquals("ftp", name.getScheme()); assertEquals("hostname", name.getHostName()); assertEquals(21, name.getPort()); assertEquals("/", name.getPath()); assertEquals("ftp://hostname/", name.getRootURI()); assertEquals("ftp://hostname/", name.getURI());
protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData) throws FileSystemException { return FtpClientFactory.createConnection( rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.USERNAME, null), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.PASSWORD, null), rootName.getPath(), getFileSystemOptions()); }
@Override protected FileSystem doCreateFileSystem( final FileName name, final FileSystemOptions fileSystemOptions ) throws FileSystemException { GenericFileName genericFileName = (GenericFileName) name.getRoot(); String hostName = genericFileName.getHostName(); int port = genericFileName.getPort(); // TODO: load from metastore NamedCluster namedCluster = namedClusterService.getClusterTemplate(); namedCluster.setHdfsHost( hostName ); if ( port > 0 ) { namedCluster.setHdfsPort( String.valueOf( port ) ); } else { namedCluster.setHdfsPort( "" ); } namedCluster.setMapr( MAPRFS.equals( name.getScheme() ) ); try { return new HDFSFileSystem( name, fileSystemOptions, hadoopFileSystemLocator.getHadoopFilesystem( namedCluster, URI.create( name.getURI() == null ? "" : name.getURI() ) ) ); } catch ( ClusterInitializationException e ) { throw new FileSystemException( e ); } }
/** * Builds the root URI for this file name. */ @Override protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) { buffer.append(getScheme()); buffer.append("://"); appendCredentials(buffer, addPassword); buffer.append(hostName); if (port != getDefaultPort()) { buffer.append(':'); buffer.append(port); } }
UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))); final String password = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))); credsProvider.setCredentials(new AuthScope(rootName.getHostName(), AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password));
@Override protected FileSystem doCreateFileSystem( FileName name, FileSystemOptions fileSystemOptions ) throws FileSystemException { GenericFileName genericFileName = (GenericFileName) name.getRoot(); String clusterName = genericFileName.getHostName(); String path = genericFileName.getPath(); NamedCluster namedCluster = getNamedClusterByName( clusterName, fileSystemOptions ); try { if ( namedCluster == null ) { namedCluster = namedClusterService.getClusterTemplate(); } String generatedUrl = namedCluster .processURLsubstitution( path == null ? "" : path, getMetastore( clusterName, fileSystemOptions ), new Variables() ); URI uri = URI.create( generatedUrl ); return new NamedClusterFileSystem( name, uri, fileSystemOptions, hadoopFileSystemLocator.getHadoopFilesystem( namedCluster, uri ) ); } catch ( ClusterInitializationException e ) { throw new FileSystemException( e ); } }
private FileSystem createJCRFileSystem( final LayeredFileName genericRootName, final FileSystemOptions fileSystemOptions ) { UserAuthenticationData authData = null; try { authData = UserAuthenticatorUtils.authenticate( fileSystemOptions, AUTHENTICATOR_TYPES ); final GenericFileName outerName = (GenericFileName) genericRootName.getOuterName(); final String username = UserAuthenticatorUtils.toString( UserAuthenticatorUtils .getData( authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar( outerName.getUserName() ) ) ); final String password = UserAuthenticatorUtils.toString( UserAuthenticatorUtils .getData( authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar( outerName.getPassword() ) ) ); final PentahoSolutionsFileSystemConfigBuilder configBuilder = new PentahoSolutionsFileSystemConfigBuilder(); final int timeOut = configBuilder.getTimeOut( fileSystemOptions ); final JCRSolutionFileModel model = new JCRSolutionFileModel( outerName.getURI(), username, password, timeOut ); return new JCRSolutionFileSystem( genericRootName, fileSystemOptions, model ); } finally { UserAuthenticatorUtils.cleanup( authData ); } }
/** * Builds the root URI for this file name. */ @Override protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) { buffer.append(getScheme()); buffer.append("://"); buffer.append(hostName); if (port != getDefaultPort()) { buffer.append(':'); buffer.append(port); } } }
@Override public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename) throws FileSystemException { // FTP URI are generic URI (as per RFC 2396) final StringBuilder name = new StringBuilder(); // Extract the scheme and authority parts final Authority auth = extractToPath(filename, name); // Decode and normalise the file name UriParser.canonicalizePath(name, 0, name.length(), this); UriParser.fixSeparators(name); final FileType fileType = UriParser.normalisePath(name); final String path = name.toString(); return new GenericFileName(auth.scheme, auth.hostName, auth.port, defaultPort, auth.userName, auth.password, path, fileType); }
/** * Put {@code domain} before @{code username} if both are set. * <p> * Uses super method to add password or password placeholder. */ @Override protected void appendCredentials(final StringBuilder buffer, final boolean addPassword) { if (getDomain() != null && getDomain().length() != 0 && getUserName() != null && getUserName().length() != 0) { buffer.append(getDomain()); buffer.append("\\"); } super.appendCredentials(buffer, addPassword); }
assertEquals("ftp", name.getScheme()); assertNull(name.getUserName()); assertNull(name.getPassword()); assertEquals("hostname", name.getHostName()); assertEquals(21, name.getPort()); assertEquals(name.getDefaultPort(), name.getPort()); assertEquals("/file", name.getPath()); assertEquals("ftp://hostname/", name.getRootURI()); assertEquals("ftp://hostname/file", name.getURI()); assertEquals("ftp", name.getScheme()); assertNull(name.getUserName()); assertNull(name.getPassword()); assertEquals("hostname", name.getHostName()); assertEquals(9090, name.getPort()); assertEquals("/file", name.getPath()); assertEquals("ftp://hostname:9090/", name.getRootURI()); assertEquals("ftp://hostname:9090/file", name.getURI()); assertEquals("ftp", name.getScheme()); assertNull(name.getUserName()); assertNull(name.getPassword()); assertEquals("hostname", name.getHostName()); assertEquals(21, name.getPort()); assertEquals("/", name.getPath()); assertEquals("ftp://hostname/", name.getRootURI()); assertEquals("ftp://hostname/", name.getURI()); assertEquals("ftp", name.getScheme());
@Override protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData) throws FileSystemException { return FtpsClientFactory.createConnection( rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.USERNAME, null), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.PASSWORD, null), rootName.getPath(), getFileSystemOptions()); } }
rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null),
/** * Builds the root URI for this file name. */ @Override protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) { buffer.append(getScheme()); buffer.append("://"); appendCredentials(buffer, addPassword); buffer.append(hostName); if (port != getDefaultPort()) { buffer.append(':'); buffer.append(port); } }
@Override public FileName parseChildUri(final VfsComponentContext context, final FileName base, final String filename) throws FileSystemException { // FTP URI are generic URI (as per RFC 2396) final StringBuilder name = new StringBuilder(); // Extract the scheme and authority parts final Authority auth = extractToPath(filename, name); // Decode and normalise the file name UriParser.canonicalizePath(name, 0, name.length(), this); //UriParser.fixSeparators(name); final FileType fileType = UriParser.normalisePath(name); final String path = name.toString(); return new GenericFileName( auth.scheme, auth.hostName, auth.port, defaultPort, path, fileType); } //[IntelliJ] / in WI-2449 Invalid descendent file name "ssh:" or directory a\b (on Linux) -----
/** * put domain before username if both are set */ @Override protected void appendCredentials(StringBuilder buffer, boolean addPassword) { if (getDomain() != null && getDomain().length() != 0 && getUserName() != null && getUserName().length() != 0) { buffer.append(getDomain()); buffer.append("\\"); } super.appendCredentials(buffer, addPassword); }