org.apache.commons.vfs2.provider.GenericFileName Java Examples

The following examples show how to use org.apache.commons.vfs2.provider.GenericFileName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PentahoSolutionFileProvider.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private FileSystem createWebFileSystem( final LayeredFileName genericRootName,
                                        final FileSystemOptions fileSystemOptions ) throws FileSystemException {
  final GenericFileName outerName = (GenericFileName) genericRootName.getOuterName();
  String scheme = outerName.getScheme();
  String hostName = outerName.getHostName();
  int port = outerName.getPort();
  String userName = outerName.getUserName();
  String password = outerName.getPassword();

  HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder();
  if ( !StringUtil.isEmpty( hostName ) ) {
    clientBuilder.setProxy( hostName, port, scheme );
  }
  if ( !StringUtil.isEmpty( userName ) ) {
    clientBuilder.setCredentials( userName, password );
  }
  final PentahoSolutionsFileSystemConfigBuilder configBuilder = new PentahoSolutionsFileSystemConfigBuilder();
  final int timeOut = configBuilder.getTimeOut( fileSystemOptions );
  clientBuilder.setSocketTimeout( Math.max( 0, timeOut ) );

  return new WebSolutionFileSystem( genericRootName, fileSystemOptions,
    new LocalFileModel( outerName.getURI(), clientBuilder, userName, password, hostName, port )
  );
}
 
Example #2
Source File: SftpFileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new Session.
 *
 * @return A Session, never null.
 */
static Session createSession(final GenericFileName rootName, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    UserAuthenticationData authData = null;
    try {
        authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);

        return SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
                UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                        UserAuthenticatorUtils.toChar(rootName.getUserName())),
                UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                        UserAuthenticatorUtils.toChar(rootName.getPassword())),
                fileSystemOptions);
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.sftp/connect.error", rootName, e);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }
}
 
Example #3
Source File: Http4FileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    final GenericFileName rootName = (GenericFileName) name;

    UserAuthenticationData authData = null;
    HttpClient httpClient = null;
    HttpClientContext httpClientContext = null;

    try {
        final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
        authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
        httpClientContext = createHttpClientContext(builder, rootName, fileSystemOptions, authData);
        httpClient = createHttpClient(builder, rootName, fileSystemOptions);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new Http4FileSystem(rootName, fileSystemOptions, httpClient, httpClientContext);
}
 
Example #4
Source File: Webdav4sFileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link FileSystem}.
 * <p>
 * If you're looking at this method and wondering how to get a FileSystemOptions object bearing the proxy host and
 * credentials configuration through to this method so it's used for resolving a
 * {@link org.apache.commons.vfs2.FileObject FileObject} in the FileSystem, then be sure to use correct signature of
 * the {@link org.apache.commons.vfs2.FileSystemManager FileSystemManager} resolveFile method.
 *
 * @see org.apache.commons.vfs2.impl.DefaultFileSystemManager#resolveFile(FileObject, String, FileSystemOptions)
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;
    // TODO: need to check null to create a non-null here???
    final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;

    UserAuthenticationData authData = null;
    HttpClient httpClient = null;
    HttpClientContext httpClientContext = null;

    try {
        final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
        authData = UserAuthenticatorUtils.authenticate(fsOpts, Webdav4FileProvider.AUTHENTICATOR_TYPES);
        httpClientContext = createHttpClientContext(builder, rootName, fsOpts, authData);
        httpClient = createHttpClient(builder, rootName, fsOpts);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new Webdav4FileSystem(rootName, fsOpts, httpClient, httpClientContext) {
    };
}
 
Example #5
Source File: Webdav4FileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link FileSystem}.
 * <p>
 * If you're looking at this method and wondering how to get a FileSystemOptions object bearing the proxy host and
 * credentials configuration through to this method so it's used for resolving a
 * {@link org.apache.commons.vfs2.FileObject FileObject} in the FileSystem, then be sure to use correct signature of
 * the {@link org.apache.commons.vfs2.FileSystemManager FileSystemManager} resolveFile method.
 *
 * @see org.apache.commons.vfs2.impl.DefaultFileSystemManager#resolveFile(FileObject, String, FileSystemOptions)
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;
    // TODO: need to check null to create a non-null here???
    final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;

    UserAuthenticationData authData = null;
    HttpClient httpClient = null;
    HttpClientContext httpClientContext = null;

    try {
        final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
        authData = UserAuthenticatorUtils.authenticate(fsOpts, AUTHENTICATOR_TYPES);
        httpClientContext = createHttpClientContext(builder, rootName, fsOpts, authData);
        httpClient = createHttpClient(builder, rootName, fsOpts);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new Webdav4FileSystem(rootName, fsOpts, httpClient, httpClientContext);
}
 
Example #6
Source File: Http5FileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Create an {@link HttpClientBuilder} object. Invoked by {@link #createHttpClient(Http5FileSystemConfigBuilder, GenericFileName, FileSystemOptions)}.
 *
 * @param builder Configuration options builder for HTTP4 provider
 * @param rootName The root path
 * @param fileSystemOptions The FileSystem options
 * @return an {@link HttpClientBuilder} object
 * @throws FileSystemException if an error occurs
 */
protected HttpClientBuilder createHttpClientBuilder(final Http5FileSystemConfigBuilder builder, final GenericFileName rootName,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final List<Header> defaultHeaders = new ArrayList<>();
    defaultHeaders.add(new BasicHeader(HttpHeaders.USER_AGENT, builder.getUserAgent(fileSystemOptions)));

    final ConnectionReuseStrategy connectionReuseStrategy = builder.isKeepAlive(fileSystemOptions)
            ? DefaultConnectionReuseStrategy.INSTANCE
            : (request, response, context) -> false;

    final HttpClientBuilder httpClientBuilder =
            HttpClients.custom()
            .setRoutePlanner(createHttpRoutePlanner(builder, fileSystemOptions))
            .setConnectionManager(createConnectionManager(builder, fileSystemOptions))
            .setConnectionReuseStrategy(connectionReuseStrategy)
            .setDefaultRequestConfig(createDefaultRequestConfig(builder, fileSystemOptions))
            .setDefaultHeaders(defaultHeaders)
            .setDefaultCookieStore(createDefaultCookieStore(builder, fileSystemOptions));

    if (!builder.getFollowRedirect(fileSystemOptions)) {
        httpClientBuilder.disableRedirectHandling();
    }

    return httpClientBuilder;
}
 
Example #7
Source File: SftpFileObjectWithWindowsSupportTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private static FileObject getLinuxFileObject( boolean posixReadable, boolean posixWritable ) throws Exception {
  GenericFileName fileName = mock( GenericFileName.class );
  doReturn( PATH ).when( fileName ).getPath();
  SftpFileSystemWindows sftpFileSystem = spy( new SftpFileSystemWindows( fileName, null, 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;
    }
  };
}
 
Example #8
Source File: Http5FileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    final GenericFileName rootName = (GenericFileName) name;

    UserAuthenticationData authData = null;
    HttpClient httpClient = null;
    HttpClientContext httpClientContext = null;

    try {
        final Http5FileSystemConfigBuilder builder = Http5FileSystemConfigBuilder.getInstance();
        authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
        httpClientContext = createHttpClientContext(builder, rootName, fileSystemOptions, authData);
        httpClient = createHttpClient(builder, rootName, fileSystemOptions);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new Http5FileSystem(rootName, fileSystemOptions, httpClient, httpClientContext);
}
 
Example #9
Source File: WebdavFileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link FileSystem}.
 * <p>
 * If you're looking at this method and wondering how to get a FileSystemOptions object bearing the proxy host and
 * credentials configuration through to this method so it's used for resolving a
 * {@link org.apache.commons.vfs2.FileObject FileObject} in the FileSystem, then be sure to use correct signature of
 * the {@link org.apache.commons.vfs2.FileSystemManager FileSystemManager} resolveFile method.
 * </p>
 *
 * @see org.apache.commons.vfs2.impl.DefaultFileSystemManager#resolveFile(FileObject, String, FileSystemOptions)
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;
    final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;

    UserAuthenticationData authData = null;
    HttpClient httpClient;
    try {
        authData = UserAuthenticatorUtils.authenticate(fsOpts, AUTHENTICATOR_TYPES);

        httpClient = HttpClientFactory.createConnection(WebdavFileSystemConfigBuilder.getInstance(), "http",
                rootName.getHostName(), rootName.getPort(),
                UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                        UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))),
                UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                        UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))),
                fsOpts);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new WebdavFileSystem(rootName, httpClient, fsOpts);
}
 
Example #10
Source File: PentahoSolutionFileProvider.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 );
  }
}
 
Example #11
Source File: FtpsFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the file system.
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;

    final FtpsClientWrapper ftpClient = new FtpsClientWrapper(rootName, fileSystemOptions);

    return new FtpsFileSystem(rootName, ftpClient, fileSystemOptions);
}
 
Example #12
Source File: FtpsClientWrapper.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData)
        throws FileSystemException {
    return FtpsClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
            UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                    UserAuthenticatorUtils.toChar(rootName.getUserName())),
            UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                    UserAuthenticatorUtils.toChar(rootName.getPassword())),
            rootName.getPath(), getFileSystemOptions());
}
 
Example #13
Source File: Http4FileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Create an {@link HttpClientBuilder} object. Invoked by {@link #createHttpClient(Http4FileSystemConfigBuilder, GenericFileName, FileSystemOptions)}.
 *
 * @param builder Configuration options builder for HTTP4 provider
 * @param rootName The root path
 * @param fileSystemOptions The FileSystem options
 * @return an {@link HttpClientBuilder} object
 * @throws FileSystemException if an error occurs
 */
protected HttpClientBuilder createHttpClientBuilder(final Http4FileSystemConfigBuilder builder, final GenericFileName rootName,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final List<Header> defaultHeaders = new ArrayList<>();
    defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT, builder.getUserAgent(fileSystemOptions)));

    final ConnectionReuseStrategy connectionReuseStrategy = builder.isKeepAlive(fileSystemOptions)
            ? DefaultConnectionReuseStrategy.INSTANCE
            : NoConnectionReuseStrategy.INSTANCE;

    final HttpClientBuilder httpClientBuilder =
            HttpClients.custom()
            .setRoutePlanner(createHttpRoutePlanner(builder, fileSystemOptions))
            .setConnectionManager(createConnectionManager(builder, fileSystemOptions))
            .setSSLContext(createSSLContext(builder, fileSystemOptions))
            .setSSLHostnameVerifier(createHostnameVerifier(builder, fileSystemOptions))
            .setConnectionReuseStrategy(connectionReuseStrategy)
            .setDefaultRequestConfig(createDefaultRequestConfig(builder, fileSystemOptions))
            .setDefaultHeaders(defaultHeaders)
            .setDefaultCookieStore(createDefaultCookieStore(builder, fileSystemOptions));

    if (!builder.getFollowRedirect(fileSystemOptions)) {
        httpClientBuilder.disableRedirectHandling();
    }

    return httpClientBuilder;
}
 
Example #14
Source File: HttpFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link FileSystem}.
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;

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

        final String fileScheme = rootName.getScheme();
        final char lastChar = fileScheme.charAt(fileScheme.length() - 1);
        final String internalScheme = (lastChar == 's' || lastChar == 'S') ? "https" : "http";

        httpClient = HttpClientFactory.createConnection(internalScheme, rootName.getHostName(),
                rootName.getPort(),
                UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                        UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))),
                UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                        UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))),
                fileSystemOptions);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new HttpFileSystem(rootName, httpClient, fileSystemOptions);
}
 
Example #15
Source File: SftpFileSystem.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the session link is established.
 *
 * @throws FileSystemException if a session cannot be created.
 */
private Session getSession() throws FileSystemException {
    if (!this.session.isConnected()) {
        synchronized (this) {
            if (!this.session.isConnected()) {
                doCloseCommunicationLink();
                this.session = SftpFileProvider.createSession((GenericFileName) getRootName(),
                        getFileSystemOptions());
            }
        }
    }
    return this.session;
}
 
Example #16
Source File: SftpFileObjectWithWindowsSupportTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static FileObject getWindowsFileObject( boolean windowsReadable, boolean windowsWritable )
    throws Exception {
  GenericFileName fileName = mock( GenericFileName.class );
  doReturn( PATH ).when( fileName ).getPath();
  SftpFileSystemWindows sftpFileSystem = spy( new SftpFileSystemWindows( fileName, null, 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;
    }
  };
}
 
Example #17
Source File: SftpFileSystem.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected SftpFileSystem(final GenericFileName rootName, final Session session,
        final FileSystemOptions fileSystemOptions) {
    super(rootName, null, fileSystemOptions);
    this.session = Objects.requireNonNull(session, "session");
    this.connectTimeoutMillis = SftpFileSystemConfigBuilder.getInstance()
            .getConnectTimeoutMillis(fileSystemOptions);

    if (SftpFileSystemConfigBuilder.getInstance().isDisableDetectExecChannel(fileSystemOptions)) {
        this.execDisabled = true;
    } else {
        this.execDisabled = detectExecDisabled();
    }
}
 
Example #18
Source File: FtpFileSystem.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * @param rootName The root of the file system.
 * @param ftpClient The FtpClient.
 * @param fileSystemOptions The FileSystemOptions.
 * @since 2.0 (was protected)
 */
public FtpFileSystem(final GenericFileName rootName, final FtpClient ftpClient,
        final FileSystemOptions fileSystemOptions) {
    super(rootName, null, fileSystemOptions);
    // hostname = rootName.getHostName();
    // port = rootName.getPort();

    idleClient.set(ftpClient);
}
 
Example #19
Source File: FTPClientWrapper.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData)
        throws FileSystemException {
    return FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
            UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
                    UserAuthenticatorUtils.toChar(rootName.getUserName())),
            UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
                    UserAuthenticatorUtils.toChar(rootName.getPassword())),
            rootName.getPath(), getFileSystemOptions());
}
 
Example #20
Source File: FtpFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the file system.
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;

    final FTPClientWrapper ftpClient = new FTPClientWrapper(rootName, fileSystemOptions);
    /*
     * FTPClient ftpClient = FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
     * rootName.getUserName(), rootName.getPassword(), rootName.getPath(), fileSystemOptions);
     */

    return new FtpFileSystem(rootName, ftpClient, fileSystemOptions);
}
 
Example #21
Source File: SftpFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link FileSystem}.
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    return new SftpFileSystem((GenericFileName) name, createSession((GenericFileName) name, fileSystemOptions),
            fileSystemOptions);
}
 
Example #22
Source File: FTPClientWrapper.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private FTPClient createClient() throws FileSystemException {
    final GenericFileName rootName = getRoot();

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

        return createClient(rootName, authData);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }
}
 
Example #23
Source File: FtpsFileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
@Override
protected FtpsClientWrapper createWrapper() throws FileSystemException {
    return new FtpsClientWrapper((GenericFileName) getRoot().getName(), getFileSystemOptions());
}
 
Example #24
Source File: WebdavFileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected WebdavFileSystem(final GenericFileName rootName, final HttpClient client,
        final FileSystemOptions fileSystemOptions) {
    super(rootName, client, fileSystemOptions);
}
 
Example #25
Source File: SftpFileSystemWindows.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
SftpFileSystemWindows( GenericFileName rootName, Session session, FileSystemOptions fileSystemOptions ) {
  super( rootName, session, fileSystemOptions );
  this.session = session;
  detectExecDisabled();
}
 
Example #26
Source File: SftpFileSystemWindowsProvider.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
protected FileSystem doCreateFileSystem( FileName name, FileSystemOptions fileSystemOptions ) {
  return new SftpFileSystemWindows( (GenericFileName) name, null, fileSystemOptions );
}
 
Example #27
Source File: Http5FileProvider.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Create an {@link HttpClientContext} object for an http4 file system.
 *
 * @param builder Configuration options builder for http4 provider
 * @param rootName The root path
 * @param fileSystemOptions The FileSystem options
 * @param authData The {@code UserAuthentiationData} object
 * @return an {@link HttpClientContext} object
 * @throws FileSystemException if an error occurs
 */
protected HttpClientContext createHttpClientContext(final Http5FileSystemConfigBuilder builder,
        final GenericFileName rootName, final FileSystemOptions fileSystemOptions,
        final UserAuthenticationData authData) throws FileSystemException {

    final HttpClientContext clientContext = HttpClientContext.create();
    final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    clientContext.setCredentialsProvider(credsProvider);

    final String username = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
            UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())));
    final char[] password = UserAuthenticatorUtils.getData(authData,
            UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()));

    if (username != null && !username.isEmpty()) {
        // -1 for any port
        credsProvider.setCredentials(new AuthScope(rootName.getHostName(), -1),
                new UsernamePasswordCredentials(username, password));
    }

    final HttpHost proxyHost = getProxyHttpHost(builder, fileSystemOptions);

    if (proxyHost != null) {
        final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions);

        if (proxyAuth != null) {
            final UserAuthenticationData proxyAuthData = UserAuthenticatorUtils.authenticate(proxyAuth,
                    new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME,
                            UserAuthenticationData.PASSWORD });

            if (proxyAuthData != null) {
                final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(
                        UserAuthenticatorUtils.toString(
                                UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)),
                        UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null));

                // -1 for any port
                credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), -1),
                        proxyCreds);
            }

            if (builder.isPreemptiveAuth(fileSystemOptions)) {
                final AuthCache authCache = new BasicAuthCache();
                final BasicScheme basicAuth = new BasicScheme();
                authCache.put(proxyHost, basicAuth);
                clientContext.setAuthCache(authCache);
            }
        }
    }

    return clientContext;
}
 
Example #28
Source File: FTPClientWrapper.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected FTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    this.root = root;
    this.fileSystemOptions = fileSystemOptions;
    getFtpClient(); // fail-fast
}
 
Example #29
Source File: FtpsClientWrapper.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
FtpsClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    super(root, fileSystemOptions);
}
 
Example #30
Source File: Http4FileProvider.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Create an {@link HttpClientContext} object for an http4 file system.
 *
 * @param builder Configuration options builder for http4 provider
 * @param rootName The root path
 * @param fileSystemOptions The FileSystem options
 * @param authData The {@code UserAuthentiationData} object
 * @return an {@link HttpClientContext} object
 * @throws FileSystemException if an error occurs
 */
protected HttpClientContext createHttpClientContext(final Http4FileSystemConfigBuilder builder,
        final GenericFileName rootName, final FileSystemOptions fileSystemOptions,
        final UserAuthenticationData authData) throws FileSystemException {

    final HttpClientContext clientContext = HttpClientContext.create();
    final CredentialsProvider credsProvider = new BasicCredentialsProvider();
    clientContext.setCredentialsProvider(credsProvider);

    final String username = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
            UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())));
    final String password = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
            UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())));

    if (username != null && !username.isEmpty()) {
        credsProvider.setCredentials(new AuthScope(rootName.getHostName(), AuthScope.ANY_PORT),
                new UsernamePasswordCredentials(username, password));
    }

    final HttpHost proxyHost = getProxyHttpHost(builder, fileSystemOptions);

    if (proxyHost != null) {
        final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions);

        if (proxyAuth != null) {
            final UserAuthenticationData proxyAuthData = UserAuthenticatorUtils.authenticate(proxyAuth,
                    new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME,
                            UserAuthenticationData.PASSWORD });

            if (proxyAuthData != null) {
                final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(
                        UserAuthenticatorUtils.toString(
                                UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)),
                        UserAuthenticatorUtils.toString(
                                UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));

                credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), AuthScope.ANY_PORT),
                        proxyCreds);
            }

            if (builder.isPreemptiveAuth(fileSystemOptions)) {
                final AuthCache authCache = new BasicAuthCache();
                final BasicScheme basicAuth = new BasicScheme();
                authCache.put(proxyHost, basicAuth);
                clientContext.setAuthCache(authCache);
            }
        }
    }

    return clientContext;
}