Example usage for org.apache.commons.net.util KeyManagerUtils createClientKeyManager

List of usage examples for org.apache.commons.net.util KeyManagerUtils createClientKeyManager

Introduction

In this page you can find the example usage for org.apache.commons.net.util KeyManagerUtils createClientKeyManager.

Prototype

public static KeyManager createClientKeyManager(File storePath, String storePass, String keyAlias)
        throws IOException, GeneralSecurityException 

Source Link

Document

Create a client key manager which returns a particular key.

Usage

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 {/*w  ww . j  a v  a  2  s . 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));
        }
    }
}