From 7b1b1cd35fcfe7c24a64d1f40e35c30173e45a2e Mon Sep 17 00:00:00 2001 From: stianst Date: Wed, 26 Feb 2020 16:42:17 +0100 Subject: [PATCH] Fixes --- .../admin/client/ClientBuilderWrapper.java | 13 +++++++--- .../org/keycloak/admin/client/Keycloak.java | 25 +++++-------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/integration/admin-client/src/main/java/org/keycloak/admin/client/ClientBuilderWrapper.java b/integration/admin-client/src/main/java/org/keycloak/admin/client/ClientBuilderWrapper.java index 77497c4668..589bec338e 100644 --- a/integration/admin-client/src/main/java/org/keycloak/admin/client/ClientBuilderWrapper.java +++ b/integration/admin-client/src/main/java/org/keycloak/admin/client/ClientBuilderWrapper.java @@ -1,6 +1,7 @@ package org.keycloak.admin.client; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import javax.net.ssl.SSLContext; +import javax.ws.rs.client.ClientBuilder; public class ClientBuilderWrapper { @@ -17,9 +18,15 @@ public class ClientBuilderWrapper { } } - public static ResteasyClientBuilder create() { + public static ClientBuilder create(SSLContext sslContext, boolean disableTrustManager) { try { - return (ResteasyClientBuilder) clazz.newInstance(); + Object o = clazz.newInstance(); + clazz.getMethod("sslContext", SSLContext.class).invoke(o, sslContext); + clazz.getMethod("connectionPoolSize", int.class).invoke(o, 10); + if (disableTrustManager) { + clazz.getMethod("disableTrustManager").invoke(o); + } + return (ClientBuilder) o; } catch (Exception e) { throw new RuntimeException(e); } diff --git a/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java b/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java index 0a59ae3e72..db73ea631c 100755 --- a/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java +++ b/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java @@ -14,11 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.keycloak.admin.client; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider; import org.keycloak.admin.client.resource.BearerAuthFilter; @@ -27,19 +24,16 @@ import org.keycloak.admin.client.resource.RealmsResource; import org.keycloak.admin.client.resource.ServerInfoResource; import org.keycloak.admin.client.token.TokenManager; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; import javax.ws.rs.client.Client; - +import javax.ws.rs.client.ClientBuilder; import java.net.URI; import static org.keycloak.OAuth2Constants.PASSWORD; /** - * Provides a Keycloak client. By default, this implementation uses a {@link ResteasyClient RESTEasy client} with the - * default {@link ResteasyClientBuilder} settings. To customize the underling client, use a {@link KeycloakBuilder} to - * create a Keycloak client. + * Provides a Keycloak client. By default, this implementation uses a the default RestEasy client builder settings. + * To customize the underling client, use a {@link KeycloakBuilder} to create a Keycloak client. * * To read Responses, you can use {@link CreatedResponseUtil} for objects created * @@ -54,7 +48,7 @@ public class Keycloak implements AutoCloseable { private final Client client; private boolean closed = false; - Keycloak(String serverUrl, String realm, String username, String password, String clientId, String clientSecret, String grantType, ResteasyClient resteasyClient, String authtoken) { + Keycloak(String serverUrl, String realm, String username, String password, String clientId, String clientSecret, String grantType, Client resteasyClient, String authtoken) { config = new Config(serverUrl, realm, username, password, clientId, clientSecret, grantType); client = resteasyClient != null ? resteasyClient : newRestEasyClient(null, null, false); authToken = authtoken; @@ -68,15 +62,8 @@ public class Keycloak implements AutoCloseable { return authToken != null ? new BearerAuthFilter(authToken) : new BearerAuthFilter(tokenManager); } - private static ResteasyClient newRestEasyClient(ResteasyJackson2Provider customJacksonProvider, SSLContext sslContext, boolean disableTrustManager) { - ResteasyClientBuilder clientBuilder = ClientBuilderWrapper.create() - .sslContext(sslContext) - .connectionPoolSize(10); - - if (disableTrustManager) { - // Disable PKIX path validation errors when running tests using SSL - clientBuilder.disableTrustManager().hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY); - } + private static Client newRestEasyClient(ResteasyJackson2Provider customJacksonProvider, SSLContext sslContext, boolean disableTrustManager) { + ClientBuilder clientBuilder = ClientBuilderWrapper.create(sslContext, disableTrustManager); if (customJacksonProvider != null) { clientBuilder.register(customJacksonProvider, 100);