List of usage examples for org.apache.commons.vfs2.provider.ftps FtpsFileSystemConfigBuilder getInstance
public static FtpsFileSystemConfigBuilder getInstance()
From source file:com.ewcms.publication.deploy.provider.FtpsDeployOperator.java
@Override protected FileObject getRootFileObject(FileSystemOptions opts, BuilderBase builder, FileSystemManager manager) throws FileSystemException { FtpsFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); String port = StringUtils.isBlank(builder.getPort()) ? DEFAULT_PORT : builder.getPort(); StringBuilder connBuilder = new StringBuilder(); connBuilder.append("ftps://"); connBuilder.append(builder.getHostname()).append(":").append(port); connBuilder.append(builder.getPath()); String conn = connBuilder.toString(); logger.debug("uri is {}", conn); return manager.resolveFile(conn, opts); }
From source file:com.sonicle.webtop.vfs.sfs.FtpsSFS.java
@Override protected void configureOptions() throws FileSystemException { FtpsFileSystemConfigBuilder builder = FtpsFileSystemConfigBuilder.getInstance(); builder.setUserDirIsRoot(fso, false); }
From source file:com.streamsets.pipeline.lib.remote.FTPRemoteConnector.java
@Override protected void initAndConnect(List<Stage.ConfigIssue> issues, ConfigIssueContext context, URI remoteURI, Label remoteGroup, Label credGroup) { options = new FileSystemOptions(); this.remoteURI = remoteURI; if (remoteConfig.strictHostChecking) { issues.add(context.createConfigIssue(credGroup.getLabel(), CONF_PREFIX + "strictHostChecking", Errors.REMOTE_07));//from w ww .ja v a 2 s . c o m } switch (remoteConfig.auth) { case PRIVATE_KEY: issues.add( context.createConfigIssue(credGroup.getLabel(), CONF_PREFIX + "privateKey", Errors.REMOTE_06)); break; case PASSWORD: String username = resolveUsername(remoteURI, issues, context, credGroup); String password = resolvePassword(remoteURI, issues, context, credGroup); if (remoteURI.getUserInfo() != null) { remoteURI = UriBuilder.fromUri(remoteURI).userInfo(null).build(); } StaticUserAuthenticator authenticator = new StaticUserAuthenticator(remoteURI.getHost(), username, password); try { DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator); } catch (FileSystemException e) { // This method doesn't actually ever throw a FileSystemException, it simply declares that it does... // This shouldn't happen, but just in case, we'll log it LOG.error("Unexpected Exception", e); } break; case NONE: break; default: break; } FtpFileSystemConfigBuilder configBuilder = FtpFileSystemConfigBuilder.getInstance(); if (remoteURI.getScheme().equals(FTPS_SCHEME)) { configBuilder = FtpsFileSystemConfigBuilder.getInstance(); FtpsFileSystemConfigBuilder.getInstance().setFtpsMode(options, remoteConfig.ftpsMode.getMode()); FtpsFileSystemConfigBuilder.getInstance().setDataChannelProtectionLevel(options, remoteConfig.ftpsDataChannelProtectionLevel.getLevel()); if (remoteConfig.useFTPSClientCert) { setFtpsUserKeyManagerOrTrustManager(remoteConfig.ftpsClientCertKeystoreFile, CONF_PREFIX + "ftpsClientCertKeystoreFile", remoteConfig.ftpsClientCertKeystorePassword, CONF_PREFIX + "ftpsClientCertKeystorePassword", remoteConfig.ftpsClientCertKeystoreType, true, issues, context, credGroup); } switch (remoteConfig.ftpsTrustStoreProvider) { case FILE: setFtpsUserKeyManagerOrTrustManager(remoteConfig.ftpsTruststoreFile, CONF_PREFIX + "ftpsTruststoreFile", remoteConfig.ftpsTruststorePassword, CONF_PREFIX + "ftpsTruststorePassword", remoteConfig.ftpsTruststoreType, false, issues, context, credGroup); break; case JVM_DEFAULT: try { FtpsFileSystemConfigBuilder.getInstance().setTrustManager(options, TrustManagerUtils.getDefaultTrustManager(null)); } catch (GeneralSecurityException e) { issues.add(context.createConfigIssue(credGroup.getLabel(), CONF_PREFIX + "ftpsTruststoreFile", Errors.REMOTE_14, "trust", "JVM", e.getMessage(), e)); } break; case ALLOW_ALL: // fall through default: FtpsFileSystemConfigBuilder.getInstance().setTrustManager(options, TrustManagerUtils.getAcceptAllTrustManager()); break; } } configBuilder.setPassiveMode(options, true); configBuilder.setUserDirIsRoot(options, remoteConfig.userDirIsRoot); // Only actually try to connect and authenticate if there were no issues if (issues.isEmpty()) { LOG.info("Connecting to {}", remoteURI.toString()); try { remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options); remoteDir.refresh(); if (remoteConfig.createPathIfNotExists && !remoteDir.exists()) { remoteDir.createFolder(); } remoteDir.getChildren(); } catch (FileSystemException e) { LOG.error(Errors.REMOTE_11.getMessage(), remoteURI.toString(), e.getMessage(), e); issues.add(context.createConfigIssue(remoteGroup.getLabel(), CONF_PREFIX + "remoteAddress", Errors.REMOTE_11, remoteURI.toString(), e.getMessage(), e)); } } }
From source file:com.streamsets.pipeline.lib.remote.FTPRemoteConnector.java
private void setFtpsUserKeyManagerOrTrustManager(String file, String fileConfigName, CredentialValue password, String passwordConfigName, KeyStoreType keyStoreType, boolean isKeystore, // or truststore List<Stage.ConfigIssue> issues, ConfigIssueContext context, Label group) { if (file != null && !file.isEmpty()) { File keystoreFile = new File(file); String keystorePassword = resolveCredential(password, passwordConfigName, issues, context, group); try {//from w w w. j av a 2s . co m KeyStore keystore = loadKeystore(keystoreFile, keyStoreType.getJavaValue(), keystorePassword); try { if (isKeystore) { FtpsFileSystemConfigBuilder.getInstance().setKeyManager(options, KeyManagerUtils.createClientKeyManager(keystore, null, keystorePassword)); } else { FtpsFileSystemConfigBuilder.getInstance().setTrustManager(options, TrustManagerUtils.getDefaultTrustManager(keystore)); } } catch (GeneralSecurityException e) { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_15, isKeystore ? "key" : "trust", e.getMessage(), e)); } } catch (IOException | GeneralSecurityException e) { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_14, isKeystore ? "key" : "trust", keystoreFile.getAbsolutePath(), e.getMessage(), e)); } } else { if (isKeystore) { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_12)); } else { issues.add(context.createConfigIssue(group.getLabel(), fileConfigName, Errors.REMOTE_13)); } } }
From source file:org.wso2.carbon.connector.util.FileConnectorUtils.java
public static FileSystemOptions init(MessageContext messageContext) { String setTimeout = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.SET_TIME_OUT); String setPassiveMode = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.SET_PASSIVE_MODE); String setSoTimeout = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.SET_SO_TIMEOUT); String setStrictHostKeyChecking = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.SET_STRICT_HOST_KEY_CHECKING); String setUserDirIsRoot = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.SET_USER_DIRISROOT); if (log.isDebugEnabled()) { log.debug("File init starts with " + setTimeout + "," + setPassiveMode + "," + "" + setSoTimeout + "," + setStrictHostKeyChecking + "," + setUserDirIsRoot); }//from w ww. j a va 2 s . co m FileSystemOptions opts = new FileSystemOptions(); // SSH Key checking try { if (StringUtils.isEmpty(setStrictHostKeyChecking)) { SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); } else { setStrictHostKeyChecking = setStrictHostKeyChecking.trim(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, setStrictHostKeyChecking); } } catch (FileSystemException e) { throw new SynapseTaskException("Error while configuring a " + "setStrictHostKeyChecking", e); } // Root directory set to user home if (StringUtils.isEmpty(setUserDirIsRoot)) { SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); } else { setUserDirIsRoot = setUserDirIsRoot.trim(); try { SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, Boolean.valueOf(setUserDirIsRoot)); } catch (Exception e) { throw new SynapseTaskException("Error while configuring a " + "setUserDirIsRoot", e); } } // Timeout is count by Milliseconds if (StringUtils.isEmpty(setTimeout)) { SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, FileConstants.TIME_OUT); } else { setTimeout = setTimeout.trim(); try { SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, Integer.parseInt(setTimeout)); } catch (NumberFormatException e) { throw new SynapseTaskException("Error while configuring a " + "setTimeout", e); } } if (StringUtils.isEmpty(setPassiveMode)) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); } else { setPassiveMode = setPassiveMode.trim(); try { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, Boolean.valueOf(setPassiveMode)); FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, Boolean.valueOf(setPassiveMode)); } catch (Exception e) { throw new SynapseTaskException("Error while configuring a " + "setPassiveMode", e); } } if (StringUtils.isEmpty(setSoTimeout)) { FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, FileConstants.TIME_OUT); } else { setSoTimeout = setSoTimeout.trim(); try { FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, Integer.parseInt(setSoTimeout)); } catch (NumberFormatException e) { throw new SynapseTaskException("Error while configuring a " + "setSoTimeout", e); } } if (log.isDebugEnabled()) { log.debug("FileConnector configuration is completed."); } return opts; }
From source file:org.wso2.carbon.connector.util.FTPSiteUtils.java
/** * Get the default options for File system * //from w w w .ja v a2 s . c o m * @return * @throws FileSystemException */ public static FileSystemOptions createDefaultOptions() throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); // SSH Key checking SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); // Root directory set to user home SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); // Timeout is count by Milliseconds SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 100000); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, 100000); FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); return opts; }