Skip to content

Instantly share code, notes, and snippets.

@mcqueenorama
Created May 27, 2016 23:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcqueenorama/13275d42331fb1c5188d797b65eebfe9 to your computer and use it in GitHub Desktop.
Save mcqueenorama/13275d42331fb1c5188d797b65eebfe9 to your computer and use it in GitHub Desktop.
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