Example usage for org.apache.http.conn.ssl PrivateKeyStrategy PrivateKeyStrategy

List of usage examples for org.apache.http.conn.ssl PrivateKeyStrategy PrivateKeyStrategy

Introduction

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

Prototype

PrivateKeyStrategy

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 {//  w w  w .j av a  2s  .c om
        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);
}