Java Code Examples for org.apache.commons.vfs2.UserAuthenticationData

The following examples show how to use org.apache.commons.vfs2.UserAuthenticationData. These examples are extracted from open source projects. 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
protected UserAuthenticationData getStaticWorkingUserAuthForSmb(AuthStore authStore, String url) {
  LOGGER.debug("Checking if have credentials for {}", url);
  VFSURIParser parser = new VFSURIParser(url);
  if (parser.getHostname() != null) {
    Collection<UserAuthenticationDataWrapper> userAuthenticationDatas = authStore.getUserAuthenticationDatas(parser.getProtocol().toString(),
        parser.getHostname());
    LOGGER.debug("Credentials count: {}", userAuthenticationDatas.size());
    if (userAuthenticationDatas.size() > 0) {
      UserAuthenticationData authenticationDataFromStore = userAuthenticationDatas.iterator().next();
      LOGGER.debug("Returning static authenticator for {}", url);
      return authenticationDataFromStore;
    }
  }
  LOGGER.debug("Do not have credentials for {}", url);
  return null;
}
 
Example 2
Source Project: otroslogviewer   Source File: AuthStoreUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLoad() throws Exception {
  //given
  MemoryAuthStore memoryAuthStore = new MemoryAuthStore();
  InputStream resourceAsStream = this.getClass().getResourceAsStream("credentials.xml");

  //when
  authStoreUtils.load(memoryAuthStore, resourceAsStream);

  //then
  assertEquals(memoryAuthStore.getAll().size(), 3);
  UserAuthenticationDataWrapper userAuthenticationData1 = memoryAuthStore.getUserAuthenticationData(new UserAuthenticationInfo("ftp", "host1", "stefan"));
  assertEquals(userAuthenticationData1.getData(UserAuthenticationData.USERNAME), "Stefan".toCharArray());
  LOGGER.info("Password for stefan:" + new String(userAuthenticationData1.getData(UserAuthenticationData.PASSWORD)));
  assertEquals(userAuthenticationData1.getData(UserAuthenticationData.PASSWORD), "Password".toCharArray());
  assertEquals(userAuthenticationData1.getData(new UserAuthenticationData.Type("path")), "c:\\file".toCharArray());

}
 
Example 3
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 4
Source Project: commons-vfs   Source File: WebdavFileProvider.java    License: 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 5
Source Project: commons-vfs   Source File: StaticUserAuthenticator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public UserAuthenticationData requestAuthentication(final UserAuthenticationData.Type[] types) {
    final UserAuthenticationData data = new UserAuthenticationData();
    for (final UserAuthenticationData.Type type : types) {
        if (type == UserAuthenticationData.DOMAIN) {
            data.setData(UserAuthenticationData.DOMAIN, UserAuthenticatorUtils.toChar(domain));
        } else if (type == UserAuthenticationData.USERNAME) {
            data.setData(UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(username));
        } else if (type == UserAuthenticationData.PASSWORD) {
            data.setData(UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(password));
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug(StaticUserAuthenticator.class.getSimpleName()
                        + " does not support authentication data type '" + type
                        + "'; authentication request for this type ignored.");
            }
        }
    }
    return data;
}
 
Example 6
Source Project: commons-vfs   Source File: Http5FileProvider.java    License: 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 7
Source Project: commons-vfs   Source File: SftpFileProvider.java    License: 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 8
Source Project: commons-vfs   Source File: Http4FileProvider.java    License: 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 9
Source Project: commons-vfs   Source File: Webdav4sFileProvider.java    License: 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 10
Source Project: commons-vfs   Source File: Webdav4FileProvider.java    License: 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 11
Source Project: hop   Source File: S3NFileSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetS3Service() throws Exception {
  assertNotNull( fileSystem.getS3Client() );

  FileSystemOptions options = new FileSystemOptions();
  UserAuthenticator authenticator = mock( UserAuthenticator.class );
  UserAuthenticationData authData = mock( UserAuthenticationData.class );
  when( authenticator.requestAuthentication( S3FileProvider.AUTHENTICATOR_TYPES ) ).thenReturn( authData );
  when( authData.getData( UserAuthenticationData.USERNAME ) ).thenReturn( "username".toCharArray() );
  when( authData.getData( UserAuthenticationData.PASSWORD ) ).thenReturn( "password".toCharArray() );
  DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( options, authenticator );

  fileSystem = new S3NFileSystem( fileName, options );
  assertNotNull( fileSystem.getS3Client() );
}
 
Example 12
Source Project: hop   Source File: S3FileSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetS3Service() throws Exception {
  assertNotNull( fileSystem.getS3Client() );

  FileSystemOptions options = new FileSystemOptions();
  UserAuthenticator authenticator = mock( UserAuthenticator.class );
  UserAuthenticationData authData = mock( UserAuthenticationData.class );
  when( authenticator.requestAuthentication( S3FileProvider.AUTHENTICATOR_TYPES ) ).thenReturn( authData );
  when( authData.getData( UserAuthenticationData.USERNAME ) ).thenReturn( "username".toCharArray() );
  when( authData.getData( UserAuthenticationData.PASSWORD ) ).thenReturn( "password".toCharArray() );
  DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( options, authenticator );

  fileSystem = new S3FileSystem( fileName, options );
  assertNotNull( fileSystem.getS3Client() );
}
 
Example 13
Source Project: otroslogviewer   Source File: SmbUserAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {
  LOGGER.debug("Requested for authentication");
  for (UserAuthenticationData.Type type : types) {
    LOGGER.debug("Requested for authentication: %s",type);
  }
  if (data == null) {
    return super.requestAuthentication(types);
  } else {
    return data;
  }
}
 
Example 14
Source Project: otroslogviewer   Source File: SmbUserAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void userSelectedHook(UserAuthenticationData userAuthenticationData) {
  char[] domain = new char[0];
  if (userAuthenticationData != null) {
    domain = userAuthenticationData.getData(UserAuthenticationData.DOMAIN);
  }
  fieldTf.setText(new String(domain));

}
 
Example 15
@Override
public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {
  UserAuthenticationData userAuthenticationData = getStaticWorkingUserAuthForSmb(sessionAuthStore, getUrl());
  if (userAuthenticationData ==null){
    userAuthenticationData = otrosUserAuthenticator.requestAuthentication(types);
  }
  return userAuthenticationData;
}
 
Example 16
@Override
public UserAuthenticationData requestAuthentication(Type[] types) {
  try {
    Runnable doRun = new Runnable() {
      @Override
      public void run() {
        if (saveCredentialsCheckBox == null) {
          saveCredentialsCheckBox = new JCheckBox(Messages.getMessage("authenticator.savePassword"), true);
        }
        JPanel authOptionPanel = getOptionsPanel();

        JPanel panel = new JPanel(new BorderLayout());
        panel.add(authOptionPanel);
        panel.add(saveCredentialsCheckBox, BorderLayout.SOUTH);

        String[] options = {Messages.getMessage("general.okButtonText"), Messages.getMessage("general.cancelButtonText")};
        int showConfirmDialog = JOptionPane.showOptionDialog(null, panel, Messages.getMessage("authenticator.enterCredentials"),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        if (showConfirmDialog != JOptionPane.OK_OPTION) {
          throw new AuthorisationCancelledException("Authorization cancelled by user");
        }

        data = new UserAuthenticationDataWrapper();
        getAuthenticationData(data);
      }
    };
    if (SwingUtilities.isEventDispatchThread()) {
      doRun.run();
    } else {
      SwingUtilities.invokeAndWait(doRun);
    }
  } catch (Exception e) {
    if (Throwables.getRootCause(e) instanceof AuthorisationCancelledException) {
      throw (AuthorisationCancelledException) Throwables.getRootCause(e);
    }
  }


  return data;
}
 
Example 17
Source Project: otroslogviewer   Source File: SftpUserAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void getAuthenticationData(UserAuthenticationData authenticationData) {
  super.getAuthenticationData(authenticationData);
  authenticationData.setData(UserAuthenticationDataWrapper.SSH_KEY, sshKeyFileField.getText().trim().toCharArray());

  if (StringUtils.isNotBlank(sshKeyFileField.getText())) {
    try {
      SftpFileSystemConfigBuilder.getInstance().setIdentities(getFileSystemOptions(), new File[]{new File(sshKeyFileField.getText())});
      //TODO set user auth data file path
    } catch (FileSystemException e) {
      e.printStackTrace();
    }
  }

}
 
Example 18
Source Project: otroslogviewer   Source File: SftpUserAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void userSelectedHook(UserAuthenticationData userAuthenticationData) {
  if (userAuthenticationData != null) {
    char[] sshKeyPath = userAuthenticationData.getData(UserAuthenticationDataWrapper.SSH_KEY);
    String path = "";
    if (sshKeyPath != null && sshKeyPath.length > 0) {
      path = new String(sshKeyPath);
    }
    sshKeyFileField.setText(path);
  }
}
 
Example 19
@Override
public UserAuthenticationData requestAuthentication(Type[] arg0) {
  LOGGER.info("Received request for authentication");
  UserAuthenticationDataWrapper data = new UserAuthenticationDataWrapper();
  for (Type type : arg0) {
    data.setData(type, userAuthenticationData.getData(type));
    userAuthenticationDataWrapper.setData(type, userAuthenticationData.getData(type));
  }
  return data;
}
 
Example 20
Source Project: otroslogviewer   Source File: UserPassUserAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
private void userSelected(String user) {
  UserAuthenticationData userAuthenticationData = getAuthStore().getUserAuthenticationData(new UserAuthenticationInfo(getVfsUriParser().getProtocol().getName(), getVfsUriParser().getHostname(), user));
  char[] passChars = new char[0];

  if (userAuthenticationData != null && userAuthenticationData.getData(UserAuthenticationData.PASSWORD) != null) {
    passChars = userAuthenticationData.getData(UserAuthenticationData.PASSWORD);
  }
  passTx.setText(new String(passChars));

  userSelectedHook(userAuthenticationData);
}
 
Example 21
Source Project: otroslogviewer   Source File: AuthStoreUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
      if (ENTRY.equals(localName)) {
        authStore.add(info, userAuthenticationData);
      } else if (USER_AUTHENTICATION_DATA.equals(localName)) {
//        if (UserAuthenticationData.PASSWORD.equals(new UserAuthenticationData.Type(type))) {
//          if (password == null){
//            password = passwordProvider.getPassword("Enter password for password store");
//          }
//          if (password == null || password.length==0){
//               throw new SAXException("Password for password store not entered");
//          }
//          Hex hex = new Hex();
//          try {
//            byte[] decode = (byte[]) hex.decode(data.trim());
//            byte[] decrypted = decrypt(decode, password);
//            char[] passwordWithSalt = bytesToChars(decrypted);
//            char[] password = removeSalt(passwordWithSalt);
//            data = new String(password);
//          } catch (Exception e) {
//            password=null;
//            throw new SAXException("Can't decrypt password", e);
//          }
//        }
        userAuthenticationData.setData(new UserAuthenticationData.Type(type), data.toCharArray());
      } else if (DATA.equals(localName)) {
        data = sb.toString();
      } else if (TYPE.equals(localName)) {
        type = sb.toString();
      }

      sb.setLength(0);
    }
 
Example 22
Source Project: otroslogviewer   Source File: AuthStoreUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(enabled = false)
public void testSave() throws Exception {
  //given
  AuthStore authStore = new MemoryAuthStore();
  UserAuthenticationDataWrapper authenticationData1 = new UserAuthenticationDataWrapper();
  authenticationData1.setData(UserAuthenticationData.USERNAME, "Stefan".toCharArray());
  authenticationData1.setData(UserAuthenticationData.PASSWORD, "Password".toCharArray());
  authenticationData1.setData(new UserAuthenticationData.Type("path"), "c:\\file".toCharArray());

  UserAuthenticationDataWrapper authenticationData2 = new UserAuthenticationDataWrapper();
  authenticationData2.setData(UserAuthenticationData.USERNAME, "Stefaan".toCharArray());
  authenticationData2.setData(UserAuthenticationData.PASSWORD, "Passwodrd".toCharArray());
  authenticationData2.setData(UserAuthenticationData.DOMAIN, "MS".toCharArray());

  UserAuthenticationDataWrapper authenticationData3 = new UserAuthenticationDataWrapper();
  authenticationData3.setData(UserAuthenticationData.USERNAME, "Stefan".toCharArray());
  authenticationData3.setData(UserAuthenticationData.PASSWORD, "[email protected]".toCharArray());
  authenticationData3.setData(UserAuthenticationData.DOMAIN, "MSzx!X%a".toCharArray());

  authStore.add(new UserAuthenticationInfo("ftp", "host1", "stefan"), authenticationData1);
  authStore.add(new UserAuthenticationInfo("ftp", "host1", "stefan9"), authenticationData1);
  authStore.add(new UserAuthenticationInfo("sftp", "host1a", "astefan"), authenticationData1);

  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  String expected = IOUtils.toString(this.getClass().getResourceAsStream("credentials.xml"));
  expected = expected.replaceAll(">\\s+", ">").replaceAll("\\s+<", "<").replaceAll("<Type>password</Type><Data>.*?<", "<Type>password</Type><Data><").trim();

  //when
  authStoreUtils.save(authStore, bout);

  //then
  System.out.println(new String(bout.toByteArray()));
  String result = new String(bout.toByteArray()).replaceAll(">\\s+", ">").replaceAll("\\s+<", "<").replaceAll("<Type>password</Type><Data>.*?<", "<Type>password</Type><Data><").trim();
  assertEquals(result, expected);

}
 
Example 23
Source Project: commons-vfs   Source File: FTPClientWrapper.java    License: 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 24
Source Project: commons-vfs   Source File: FTPClientWrapper.java    License: 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 25
Source Project: commons-vfs   Source File: HttpFileProvider.java    License: 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 26
Source Project: commons-vfs   Source File: FtpsClientWrapper.java    License: 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 27
Source Project: commons-vfs   Source File: UserAuthenticatorUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets data of given type from the UserAuthenticationData or null if there is no data or data of this type
 * available.
 *
 * @param data The UserAuthenticationData.
 * @param type The type of the element to retrieve.
 * @param overriddenValue The default value.
 * @return The data of the given type as a character array or null if the data is not available.
 */
public static char[] getData(final UserAuthenticationData data, final UserAuthenticationData.Type type,
        final char[] overriddenValue) {
    if (overriddenValue != null) {
        return overriddenValue;
    }

    if (data == null) {
        return null;
    }

    return data.getData(type);
}
 
Example 28
Source Project: commons-vfs   Source File: UserAuthenticatorUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Authenticates if there is an authenticator, else returns null.
 *
 * @param auth The UserAuthenticator.
 * @param authenticatorTypes An array of types describing the data to be retrieved.
 * @return A UserAuthenticationData object containing the data requested.
 */
public static UserAuthenticationData authenticate(final UserAuthenticator auth,
        final UserAuthenticationData.Type[] authenticatorTypes) {
    if (auth == null) {
        return null;
    }

    return auth.requestAuthentication(authenticatorTypes);
}
 
Example 29
@Test
public void testAuthenticationRequest() {
    final UserAuthenticator userAuthenticator = new StaticUserAuthenticator("DOMAIN", "USER", "PWD");
    UserAuthenticationData authenticationData = userAuthenticator
            .requestAuthentication(ArrayUtils.toArray(UserAuthenticationData.DOMAIN));
    assertArrayEquals("DOMAIN".toCharArray(), authenticationData.getData(UserAuthenticationData.DOMAIN));
    assertNull(authenticationData.getData(UserAuthenticationData.USERNAME));
    assertNull(authenticationData.getData(UserAuthenticationData.PASSWORD));
    authenticationData = userAuthenticator.requestAuthentication(
            ArrayUtils.toArray(UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD));
    assertNull(authenticationData.getData(UserAuthenticationData.DOMAIN));
    assertArrayEquals("USER".toCharArray(), authenticationData.getData(UserAuthenticationData.USERNAME));
    assertArrayEquals("PWD".toCharArray(), authenticationData.getData(UserAuthenticationData.PASSWORD));
}
 
Example 30
Source Project: otroslogviewer   Source File: SmbUserAuthenticator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void getAuthenticationData(UserAuthenticationData authenticationData) {
  super.getAuthenticationData(authenticationData);
  authenticationData.setData(UserAuthenticationData.DOMAIN, fieldTf.getText().toCharArray());
}