List of usage examples for org.apache.commons.vfs2.provider.sftp SftpFileSystemConfigBuilder setKnownHosts
public void setKnownHosts(final FileSystemOptions opts, final File sshdir) throws FileSystemException
From source file:net.sourceforge.fullsync.fs.filesystems.SFTPFileSystem.java
@Override public final void authSetup(final ConnectionDescription description, final FileSystemOptions options) throws org.apache.commons.vfs2.FileSystemException { StaticUserAuthenticator auth = new StaticUserAuthenticator(null, description.getParameter(ConnectionDescription.PARAMETER_USERNAME), description.getSecretParameter(ConnectionDescription.PARAMETER_PASSWORD)); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth); SftpFileSystemConfigBuilder cfg = SftpFileSystemConfigBuilder.getInstance(); if (null != sshDirName) { cfg.setKnownHosts(options, new File(sshDirName, "known_hosts")); }//from ww w . j av a 2s . c o m logger.debug("SFTP using knownHosts: ", cfg.getKnownHosts(options)); cfg.setUserInfo(options, this); cfg.setStrictHostKeyChecking(options, "ask"); if ("enabled".equals(description.getParameter("publicKeyAuth"))) { cfg.setPreferredAuthentications(options, "publickey,password,keyboard-interactive"); } else { cfg.setPreferredAuthentications(options, "password,keyboard-interactive"); } }
From source file:net.sourceforge.fullsync.fs.filesystems.SFTPAuthProvider.java
@Override public final void authSetup(final ConnectionDescription description, final FileSystemOptions options) throws FileSystemException { String username = description.getUsername().orElse(""); //$NON-NLS-1$ String password = description.getPassword().orElse(""); //$NON-NLS-1$ StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth); SftpFileSystemConfigBuilder cfg = SftpFileSystemConfigBuilder.getInstance(); cfg.setUserDirIsRoot(options, desc.isUserDirIsRoot()); if (null != SSH_DIR_NAME) { cfg.setKnownHosts(options, new File(SSH_DIR_NAME, "known_hosts")); //$NON-NLS-1$ }/*from ww w .j ava 2s .c o m*/ logger.debug("using knownHosts: ", cfg.getKnownHosts(options)); //$NON-NLS-1$ cfg.setUserInfo(options, this); cfg.setStrictHostKeyChecking(options, "ask"); //$NON-NLS-1$ if (description.getPublicKeyAuth().orElse(false).booleanValue()) { cfg.setPreferredAuthentications(options, "publickey,password,keyboard-interactive"); //$NON-NLS-1$ } else { cfg.setPreferredAuthentications(options, "password,keyboard-interactive"); //$NON-NLS-1$ } }
From source file:hadoopInstaller.installation.Installer.java
private void configureVFS2SFTP() throws InstallationFatalError { getLog().trace("HadoopInstaller.Configure.SFTP.Start"); //$NON-NLS-1$ FileSystemOptions options;//from www . j av a 2 s . c om options = new FileSystemOptions(); SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); try { builder.setUserDirIsRoot(options, false); /* * TODO-- ssh-ask * * In the case of ask, the UserInfo object should be passed with * builder.setUserInfo() */ builder.setStrictHostKeyChecking(options, this.configuration.getStrictHostKeyChecking() ? "yes" : "no"); //$NON-NLS-1$//$NON-NLS-2$ getLog().trace("HadoopInstaller.Configure.StrictHostKeyChecking", //$NON-NLS-1$ this.configuration.getStrictHostKeyChecking()); builder.setKnownHosts(options, new File(this.configuration.getSshKnownHosts())); getLog().trace("HadoopInstaller.Configure.KnownHosts", //$NON-NLS-1$ this.configuration.getSshKnownHosts()); File identities[] = { new File(getConfig().getSshKeyFile()) }; getLog().trace("HadoopInstaller.Configure.PrivateKeyFile", //$NON-NLS-1$ getConfig().getSshKeyFile()); builder.setIdentities(options, identities); /* * TODO-- ssh-ask * * what if the identities file is password protected? do we need to * use setUserInfo? */ } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.Configure.SFTP.Fail"); //$NON-NLS-1$ } this.sftpOptions = options; getLog().debug("HadoopInstaller.Configure.SFTP.Success"); //$NON-NLS-1$ }