Search in sources :

Example 1 with FtpsFileSystemConfigBuilder

use of org.apache.commons.vfs2.provider.ftps.FtpsFileSystemConfigBuilder in project wso2-synapse by wso2.

the class VFSUtils method attachFileSystemOptions.

public static FileSystemOptions attachFileSystemOptions(Map<String, String> options, FileSystemManager fsManager) throws FileSystemException {
    if (options == null) {
        return null;
    }
    FileSystemOptions opts = new FileSystemOptions();
    DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(fsManager);
    // sftp configs
    for (Map.Entry<String, String> entry : options.entrySet()) {
        for (VFSConstants.SFTP_FILE_OPTION option : VFSConstants.SFTP_FILE_OPTION.values()) {
            if (entry.getKey().equals(option.toString()) && entry.getValue() != null) {
                delegate.setConfigString(opts, VFSConstants.SCHEME_SFTP, entry.getKey().toLowerCase(), entry.getValue());
            }
        }
    }
    FtpsFileSystemConfigBuilder configBuilder = FtpsFileSystemConfigBuilder.getInstance();
    // ftp and ftps configs
    String passiveMode = options.get(PASSIVE_MODE);
    if (passiveMode != null) {
        configBuilder.setPassiveMode(opts, Boolean.parseBoolean(passiveMode));
    }
    // ftps configs
    String implicitMode = options.get(IMPLICIT_MODE);
    if (implicitMode != null) {
        if (Boolean.parseBoolean(implicitMode)) {
            configBuilder.setFtpsMode(opts, FtpsMode.IMPLICIT);
        } else {
            configBuilder.setFtpsMode(opts, FtpsMode.EXPLICIT);
        }
    }
    String protectionMode = options.get(PROTECTION_MODE);
    if ("P".equalsIgnoreCase(protectionMode)) {
        configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.P);
    } else if ("C".equalsIgnoreCase(protectionMode)) {
        configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.C);
    } else if ("S".equalsIgnoreCase(protectionMode)) {
        configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.S);
    } else if ("E".equalsIgnoreCase(protectionMode)) {
        configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.E);
    }
    String keyStore = options.get(KEY_STORE);
    if (keyStore != null) {
        configBuilder.setKeyStore(opts, keyStore);
    }
    String trustStore = options.get(TRUST_STORE);
    if (trustStore != null) {
        configBuilder.setTrustStore(opts, trustStore);
    }
    String keyStorePassword = options.get(KS_PASSWD);
    if (keyStorePassword != null) {
        configBuilder.setKeyStorePW(opts, keyStorePassword);
    }
    String trustStorePassword = options.get(TS_PASSWD);
    if (trustStorePassword != null) {
        configBuilder.setTrustStorePW(opts, trustStorePassword);
    }
    String keyPassword = options.get(KEY_PASSWD);
    if (keyPassword != null) {
        configBuilder.setKeyPW(opts, keyPassword);
    }
    if (options.get(VFSConstants.FILE_TYPE) != null) {
        delegate.setConfigString(opts, options.get(VFSConstants.SCHEME), VFSConstants.FILE_TYPE, options.get(VFSConstants.FILE_TYPE));
    }
    return opts;
}
Also used : FtpsFileSystemConfigBuilder(org.apache.commons.vfs2.provider.ftps.FtpsFileSystemConfigBuilder) DelegatingFileSystemOptionsBuilder(org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder) HashMap(java.util.HashMap) Map(java.util.Map) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)1 FtpsFileSystemConfigBuilder (org.apache.commons.vfs2.provider.ftps.FtpsFileSystemConfigBuilder)1 DelegatingFileSystemOptionsBuilder (org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder)1