use of javax.ws.rs.client.ClientBuilder in project lithium by wireapp.
the class TrustedTlsClientBuilder method build.
public static Client build() {
TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
ClientConfig cfg = new ClientConfig(JacksonJsonProvider.class);
try {
SSLContext ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(null, certs, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
clientBuilder.sslContext(ctx);
clientBuilder.hostnameVerifier((hostname, session) -> true);
return clientBuilder.withConfig(cfg).build();
} catch (Exception e) {
Logger.error(e.toString());
return JerseyClientBuilder.createClient(cfg);
}
}
use of javax.ws.rs.client.ClientBuilder in project batfish by batfish.
the class CommonUtil method createHttpClientBuilder.
public static ClientBuilder createHttpClientBuilder(boolean noSsl, boolean trustAllSslCerts, Path keystoreFile, String keystorePassword, Path truststoreFile, String truststorePassword) {
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
try {
if (!noSsl) {
SSLContext sslcontext = SSLContext.getInstance("TLS");
TrustManager[] trustManagers;
if (trustAllSslCerts) {
trustManagers = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) {
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} };
clientBuilder.hostnameVerifier(new TrustAllHostNameVerifier());
} else if (truststoreFile != null) {
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
KeyStore ts = KeyStore.getInstance("JKS");
if (truststorePassword == null) {
throw new BatfishException("Truststore file supplied but truststore password missing");
}
char[] tsPass = truststorePassword.toCharArray();
try (FileInputStream trustInputStream = new FileInputStream(truststoreFile.toFile())) {
ts.load(trustInputStream, tsPass);
}
tmf.init(ts);
trustManagers = tmf.getTrustManagers();
} else {
trustManagers = null;
}
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
KeyStore ks = KeyStore.getInstance("JKS");
KeyManager[] keyManagers;
if (keystoreFile != null) {
if (keystorePassword == null) {
throw new BatfishException("Keystore file supplied but keystore password");
}
char[] ksPass = keystorePassword.toCharArray();
try (FileInputStream keystoreStream = new FileInputStream(keystoreFile.toFile())) {
ks.load(keystoreStream, ksPass);
}
kmf.init(ks, ksPass);
keyManagers = kmf.getKeyManagers();
} else {
keyManagers = null;
}
sslcontext.init(keyManagers, trustManagers, new java.security.SecureRandom());
clientBuilder.sslContext(sslcontext);
}
if (GlobalTracer.isRegistered()) {
clientBuilder.register(ClientTracingFeature.class);
}
} catch (Exception e) {
throw new BatfishException("Error creating HTTP client builder", e);
}
return clientBuilder;
}
use of javax.ws.rs.client.ClientBuilder in project cloudbreak by hortonworks.
the class RestClientUtil method createClient.
public static Client createClient(SSLContext sslContext, boolean debug, Class<?> debugClass) {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.FOLLOW_REDIRECTS, "false");
config.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT_MS);
config.register(MultiPartFeature.class);
ClientBuilder builder = ClientBuilder.newBuilder().withConfig(config);
builder.sslContext(sslContext);
builder.hostnameVerifier(CertificateTrustManager.hostnameVerifier());
if (debug) {
builder = builder.register(new LoggingFilter(java.util.logging.Logger.getLogger(debugClass.getName()), true));
}
Client client = builder.build();
LOGGER.debug("Jax rs client has been constructed: {}, sslContext: {}", client, sslContext);
return client;
}
use of javax.ws.rs.client.ClientBuilder in project oxAuth by GluuFederation.
the class JwtUtil method getJSONWebKeys.
public static JSONObject getJSONWebKeys(String jwksUri, ClientHttpEngine engine) {
log.debug("Retrieving jwks " + jwksUri + "...");
JSONObject jwks = null;
try {
if (!StringHelper.isEmpty(jwksUri)) {
ClientBuilder clientBuilder = ResteasyClientBuilder.newBuilder();
if (engine != null) {
((ResteasyClientBuilder) clientBuilder).httpEngine(engine);
}
javax.ws.rs.client.Client clientRequest = clientBuilder.build();
try {
Response clientResponse = clientRequest.target(jwksUri).request().buildGet().invoke();
int status = clientResponse.getStatus();
log.debug(String.format("Status: %n%d", status));
if (status == 200) {
jwks = fromJson(clientResponse.readEntity(String.class));
log.debug(String.format("JWK: %s", jwks));
}
} finally {
clientRequest.close();
}
}
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
return jwks;
}
use of javax.ws.rs.client.ClientBuilder in project muikku by otavanopisto.
the class ClientPool method buildClient.
private Client buildClient() {
// TODO: trust all only on development environment
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
if ("development".equals(System.getProperties().getProperty("system.environment"))) {
clientBuilder = trustSelfSignedCerts(clientBuilder);
}
ClientBuilder builder = clientBuilder.register(new JacksonConfigurator()).register(new BrowserCacheFeature());
return builder.build();
}
Aggregations