Created
May 27, 2016 23:36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class QJenkins extends JenkinsHttpClient { | |
AuthCache authCache = new BasicAuthCache(); | |
BasicScheme basicAuth = new BasicScheme(); | |
public QJenkins(URI uri, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { | |
super(uri, addAuthentication(HttpClients.custom().setSSLSocketFactory( | |
new SSLConnectionSocketFactory( | |
new SSLContextBuilder().loadTrustMaterial(null, | |
new TrustStrategy() { | |
@Override | |
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { | |
return true; | |
} | |
}).build(), | |
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)), | |
uri, username, password)); | |
if (isNotBlank(username)) { | |
authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); | |
HttpClientContext ctx = HttpClientContext.create(); | |
ctx.setAuthCache(authCache); | |
setLocalContext(ctx); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment