Search in sources :

Example 56 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project muikku by otavanopisto.

the class RestClient method createrRestClient.

/**
 * Creater rest client.
 *
 * @return the client
 * @throws KeyManagementException
 *             the key management exception
 * @throws NoSuchAlgorithmException
 *             the no such algorithm exception
 */
private Client createrRestClient() throws KeyManagementException, NoSuchAlgorithmException {
    ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    ClientBuilder builder = clientBuilder.register(new JacksonConfigurator());
    return builder.build();
}
Also used : ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 57 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project keycloak by keycloak.

the class MutualTLSUtils method executeUserInfoRequestInGetMethod.

public static Response executeUserInfoRequestInGetMethod(String accessToken, boolean isKeystoreUsed, String keystorePath, String keystorePassward) {
    ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    KeyStore keystore = null;
    // Load the keystore file
    if (isKeystoreUsed) {
        try {
            if (keystorePath != null) {
                keystore = KeystoreUtil.loadKeyStore(keystorePath, keystorePassward);
                clientBuilder.keyStore(keystore, keystorePassward);
            } else {
                keystore = KeystoreUtil.loadKeyStore(DEFAULT_KEYSTOREPATH, DEFAULT_KEYSTOREPASSWORD);
                clientBuilder.keyStore(keystore, DEFAULT_KEYSTOREPASSWORD);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    Client client = clientBuilder.build();
    WebTarget userInfoTarget = null;
    try {
        userInfoTarget = UserInfoClientUtil.getUserInfoWebTarget(client);
    } finally {
        client.close();
    }
    return userInfoTarget.request().header(HttpHeaders.AUTHORIZATION, "bearer " + accessToken).get();
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Client(javax.ws.rs.client.Client) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) CertificateEncodingException(java.security.cert.CertificateEncodingException) ClientBuilder(javax.ws.rs.client.ClientBuilder) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder)

Aggregations

ClientBuilder (javax.ws.rs.client.ClientBuilder)57 Client (javax.ws.rs.client.Client)41 Response (javax.ws.rs.core.Response)26 Test (org.junit.Test)26 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)24 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)24 URL (java.net.URL)20 SSLContext (javax.net.ssl.SSLContext)16 ClientConfig (org.glassfish.jersey.client.ClientConfig)15 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)13 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)11 InvalidAuthenticationConfigurationException (org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException)11 WebTarget (javax.ws.rs.client.WebTarget)10 IOException (java.io.IOException)9 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)9 KeyStore (java.security.KeyStore)7 HttpClient (org.apache.http.client.HttpClient)7 AuthenticationContextConfigurationClient (org.wildfly.security.auth.client.AuthenticationContextConfigurationClient)6 MalformedURLException (java.net.MalformedURLException)5 HostnameVerifier (javax.net.ssl.HostnameVerifier)5