org.apache.commons.vfs2.auth.StaticUserAuthenticator Java Examples

The following examples show how to use org.apache.commons.vfs2.auth.StaticUserAuthenticator. 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: SimpleJsonExtractor.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException {
  this.workUnitState = workUnitState;

  // Resolve the file to pull
  if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) {
    // Add authentication credential if authentication is needed
    UserAuthenticator auth =
        new StaticUserAuthenticator(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""),
            workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME), PasswordManager.getInstance(workUnitState)
                .readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD)));
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
    this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts);
  } else {
    this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY));
  }

  // Open the file for reading
  LOGGER.info("Opening file " + this.fileObject.getURL().toString());
  this.bufferedReader =
      this.closer.register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(),
          ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
}
 
Example #2
Source File: PublishUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static FileObject createVFSConnection( final FileSystemManager fileSystemManager,
    final AuthenticationData loginData ) throws FileSystemException {
  if ( fileSystemManager == null ) {
    throw new NullPointerException();
  }
  if ( loginData == null ) {
    throw new NullPointerException();
  }

  final String versionText = loginData.getOption( SERVER_VERSION );
  final int version = ParserUtil.parseInt( versionText, SERVER_VERSION_SUGAR );

  final String normalizedUrl = normalizeURL( loginData.getUrl(), version );
  final FileSystemOptions fileSystemOptions = new FileSystemOptions();
  final PentahoSolutionsFileSystemConfigBuilder configBuilder = new PentahoSolutionsFileSystemConfigBuilder();
  configBuilder.setTimeOut( fileSystemOptions, getTimeout( loginData ) * 1000 );
  configBuilder.setUserAuthenticator( fileSystemOptions, new StaticUserAuthenticator( normalizedUrl, loginData
      .getUsername(), loginData.getPassword() ) );
  return fileSystemManager.resolveFile( normalizedUrl, fileSystemOptions );
}
 
Example #3
Source File: NestedTarTestCase.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 {
    // We test with non-empty FS options to make sure they are propagated
    final FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts,
            new StaticUserAuthenticator("domain", null, null));

    // Locate the base Tar file
    final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tar").getAbsolutePath();

    // Now build the nested file system
    final String uri = "tar:file:" + tarFilePath + "!/test.tar";
    final FileObject tarFile = manager.resolveFile(uri, opts);
    final FileObject nestedFS = manager.createFileSystem(tarFile);
    return nestedFS.resolveFile("/");
}
 
Example #4
Source File: OtherConnectionDetailsProvider.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override public FileSystemOptions getOpts( OtherConnectionDetails otherConnectionDetails ) {
  if ( otherConnectionDetails == null ) {
    return null;
  }
  StaticUserAuthenticator auth =
          new StaticUserAuthenticator( otherConnectionDetails.getHost(), otherConnectionDetails.getUsername(),
                  otherConnectionDetails.getPassword() );
  FileSystemOptions opts = new FileSystemOptions();
  try {
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( opts, auth );
  } catch ( FileSystemException fse ) {
    // Ignore and return default options
  }
  return opts;
}