List of usage examples for org.apache.http.conn.ssl SSLContextBuilder loadKeyMaterial
public SSLContextBuilder loadKeyMaterial(final KeyStore keystore, final char[] keyPassword, final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException
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); }