Java Code Examples for org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder#setUserInfo()

The following examples show how to use org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder#setUserInfo() . 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: AbstractSftpProviderTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the base folder for tests.
 */
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
    String uri = getSystemTestUriOverride();
    if (uri == null) {
        uri = ConnectionUri;
    }

    final FileSystemOptions fileSystemOptions = new FileSystemOptions();
    final SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
    builder.setStrictHostKeyChecking(fileSystemOptions, "no");
    builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo());
    builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());
    final FileObject fileObject = manager.resolveFile(uri, fileSystemOptions);
    this.fileSystem = (SftpFileSystem) fileObject.getFileSystem();
    return fileObject;
}
 
Example 2
Source File: SftpProviderStreamProxyModeTestCase.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
    String uri = getSystemTestUriOverride();
    if (uri == null) {
        uri = ConnectionUri;
    }

    final FileSystemOptions fileSystemOptions = new FileSystemOptions();
    final SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
    builder.setStrictHostKeyChecking(fileSystemOptions, "no");
    builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo());
    builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());

    final FileSystemOptions proxyOptions = (FileSystemOptions) fileSystemOptions.clone();

    final URI parsedURI = new URI(uri);
    final String userInfo = parsedURI.getUserInfo();
    final String[] userFields = userInfo == null ? null : userInfo.split(":", 2);

    builder.setProxyType(fileSystemOptions, SftpFileSystemConfigBuilder.PROXY_STREAM);
    if (userFields != null) {
        if (userFields.length > 0) {
            builder.setProxyUser(fileSystemOptions, userFields[0]);
        }
        if (userFields.length > 1) {
            builder.setProxyPassword(fileSystemOptions, userFields[1]);
        }
    }
    builder.setProxyHost(fileSystemOptions, parsedURI.getHost());
    builder.setProxyPort(fileSystemOptions, parsedURI.getPort());
    builder.setProxyCommand(fileSystemOptions, SftpStreamProxy.NETCAT_COMMAND);
    builder.setProxyOptions(fileSystemOptions, proxyOptions);
    builder.setProxyPassword(fileSystemOptions, parsedURI.getAuthority());

    // Set up the new URI
    if (userInfo == null) {
        uri = String.format("sftp://localhost:%d", parsedURI.getPort());
    } else {
        uri = String.format("sftp://%s@localhost:%d", userInfo, parsedURI.getPort());
    }


    final FileObject fileObject = manager.resolveFile(uri, fileSystemOptions);
    this.fileSystem = (SftpFileSystem) fileObject.getFileSystem();
    return fileObject;
}