use of javax.ws.rs.client.ClientBuilder in project keycloak by keycloak.
the class HoKTest method getUserInfoByHoKAccessTokenWithClientCertificate.
// verify HoK Token - Get UserInfo
@Test
public void getUserInfoByHoKAccessTokenWithClientCertificate() throws Exception {
// get an access token
oauth.doLogin("test-user@localhost", "password");
EventRepresentation loginEvent = events.expectLogin().assertEvent();
String sessionId = loginEvent.getSessionId();
String codeId = loginEvent.getDetails().get(Details.CODE_ID);
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
AccessTokenResponse tokenResponse = null;
try (CloseableHttpClient client = MutualTLSUtils.newCloseableHttpClientWithDefaultKeyStoreAndTrustStore()) {
tokenResponse = oauth.doAccessTokenRequest(code, "password", client);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
verifyHoKTokenDefaultCertThumbPrint(tokenResponse);
events.expectCodeToToken(codeId, sessionId).assertEvent();
// execute the access token to get UserInfo with token binded client certificate in mutual authentication TLS
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
KeyStore keystore = null;
keystore = KeystoreUtil.loadKeyStore(MutualTLSUtils.DEFAULT_KEYSTOREPATH, MutualTLSUtils.DEFAULT_KEYSTOREPASSWORD);
clientBuilder.keyStore(keystore, MutualTLSUtils.DEFAULT_KEYSTOREPASSWORD);
Client client = clientBuilder.build();
WebTarget userInfoTarget = null;
Response response = null;
try {
userInfoTarget = UserInfoClientUtil.getUserInfoWebTarget(client);
response = userInfoTarget.request().header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenResponse.getAccessToken()).get();
testSuccessfulUserInfoResponse(response);
} finally {
response.close();
client.close();
}
}
use of javax.ws.rs.client.ClientBuilder in project nifi-registry by apache.
the class IntegrationTestBase method createClientFromConfig.
private static Client createClientFromConfig(NiFiRegistryClientConfig registryClientConfig) {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.register(jacksonJaxbJsonProvider());
final ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
final SSLContext sslContext = registryClientConfig.getSslContext();
if (sslContext != null) {
clientBuilder.sslContext(sslContext);
}
final HostnameVerifier hostnameVerifier = registryClientConfig.getHostnameVerifier();
if (hostnameVerifier != null) {
clientBuilder.hostnameVerifier(hostnameVerifier);
}
return clientBuilder.build();
}
use of javax.ws.rs.client.ClientBuilder in project cloudbreak by hortonworks.
the class RestClientUtil method createClient.
private static Client createClient(ConfigKey configKey) {
LOGGER.debug("Constructing jax rs client: {}", configKey);
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);
if (configKey.isDebug()) {
builder = builder.register(new LoggingFilter(java.util.logging.Logger.getLogger(RestClientUtil.class.getName()), true));
}
if (!configKey.isSecure()) {
builder.sslContext(CertificateTrustManager.sslContext());
builder.hostnameVerifier(CertificateTrustManager.hostnameVerifier());
}
Client client = builder.build();
client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, configKey.isIgnorePreValidation());
SSLContext sslContext = client.getSslContext();
LOGGER.warn("RestClient has been constructed: {}, client: {}, sslContext: {}", configKey, client, sslContext);
return client;
}
use of javax.ws.rs.client.ClientBuilder in project openstack4j by ContainX.
the class ClientFactory method buildClientFromConfig.
private static Client buildClientFromConfig(Config config) {
ClientConfig clientConfig = new ClientConfig();
if (config.getProxy() != null) {
addProxy(clientConfig, config);
}
ClientBuilder cb = ClientBuilder.newBuilder().withConfig(clientConfig).property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, "true").register(JacksonFeature.class).register(RESOLVER).register(new RequestFilter());
if (config.getSslContext() != null)
cb.sslContext(config.getSslContext());
else if (config.isIgnoreSSLVerification())
cb.sslContext(UntrustedSSL.getSSLContext());
if (config.getHostNameVerifier() != null)
cb.hostnameVerifier(config.getHostNameVerifier());
else if (config.isIgnoreSSLVerification())
cb.hostnameVerifier(UntrustedSSL.getHostnameVerifier());
if (config.getReadTimeout() > 0)
cb.property(ClientProperties.READ_TIMEOUT, config.getReadTimeout());
if (config.getConnectTimeout() > 0)
cb.property(ClientProperties.CONNECT_TIMEOUT, config.getConnectTimeout());
return cb.build();
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testOneWayElytronClientServerSupportsSSLv2Hello.
/**
* One way SSL - RESTEasy client sends SSLv2Hello message and server supports the protocol.
* Handshake should succeed.
*/
@Test
public void testOneWayElytronClientServerSupportsSSLv2Hello() throws Exception {
configureSSLContext(SSLV2HELLO_CONTEXT_ONE_WAY);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-one-way-sslv2hello.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder clientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = clientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
restoreConfiguration();
}
Aggregations