Example usage for org.apache.http.conn.ssl SSLContextBuilder loadKeyMaterial

List of usage examples for org.apache.http.conn.ssl SSLContextBuilder loadKeyMaterial

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl SSLContextBuilder loadKeyMaterial.

Prototype

public SSLContextBuilder loadKeyMaterial(final KeyStore keystore, final char[] keyPassword,
            final PrivateKeyStrategy aliasStrategy)
            throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException 

Source Link

Usage

From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java

private SchemeSocketFactory getSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {
    SSLContextBuilder builder = SSLContexts.custom().useTLS();
    try {/*from   ww w  . ja  v  a  2 s . c o m*/
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    } catch (KeyStoreException e) {
        log.error("Unable to set SSL trust manager: {}", e.getMessage(), e);
    }

    if (keyStore != null) {
        try {
            builder.loadKeyMaterial(keyStore, credentials.getPassword().toCharArray(),
                    new PrivateKeyStrategy() {
                        @Override
                        public String chooseAlias(Map<String, PrivateKeyDetails> aliases, Socket socket) {
                            return credentials.getUserPrincipal().getName();
                        }
                    });
        } catch (KeyStoreException | UnrecoverableKeyException e) {
            log.error("Unable to set SSL key manager: {}", e.getMessage(), e);
        }
    }

    return new SSLSocketFactory(builder.build(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}