Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recognize quarkus.tls.trust-all property by keycloak-admin-client extension #37206

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.quarkus.keycloak.admin.client.common.KeycloakAdminClientInjectionEnabled;
import io.quarkus.keycloak.admin.client.reactive.runtime.ResteasyReactiveClientProvider;
import io.quarkus.keycloak.admin.client.reactive.runtime.ResteasyReactiveKeycloakAdminClientRecorder;
import io.quarkus.runtime.TlsConfig;

public class KeycloakAdminClientReactiveProcessor {

Expand Down Expand Up @@ -53,8 +54,8 @@ public void nativeImage(BuildProducer<ServiceProviderBuildItem> serviceProviderP
@Record(ExecutionTime.STATIC_INIT)
@Produce(ServiceStartBuildItem.class)
@BuildStep
public void integrate(ResteasyReactiveKeycloakAdminClientRecorder recorder) {
recorder.setClientProvider();
public void integrate(ResteasyReactiveKeycloakAdminClientRecorder recorder, TlsConfig tlsConfig) {
recorder.setClientProvider(tlsConfig.trustAll);
}

@Record(ExecutionTime.RUNTIME_INIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ public class ResteasyReactiveClientProvider implements ResteasyClientProvider {
private static final List<String> HANDLED_MEDIA_TYPES = List.of(MediaType.APPLICATION_JSON);
private static final int PROVIDER_PRIORITY = Priorities.USER + 100; // ensures that it will be used first

private final boolean tlsTrustAll;

public ResteasyReactiveClientProvider(boolean tlsTrustAll) {
this.tlsTrustAll = tlsTrustAll;
}

@Override
public Client newRestEasyClient(Object messageHandler, SSLContext sslContext, boolean disableTrustManager) {
ClientBuilderImpl clientBuilder = new ClientBuilderImpl().trustAll(disableTrustManager);
ClientBuilderImpl clientBuilder = new ClientBuilderImpl().trustAll(tlsTrustAll || disableTrustManager);
return registerJacksonProviders(clientBuilder).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public ResteasyReactiveKeycloakAdminClientRecorder(
this.keycloakAdminClientConfigRuntimeValue = keycloakAdminClientConfigRuntimeValue;
}

public void setClientProvider() {
Keycloak.setClientProvider(new ResteasyReactiveClientProvider());
public void setClientProvider(boolean tlsTrustAll) {
Keycloak.setClientProvider(new ResteasyReactiveClientProvider(tlsTrustAll));
}

public Supplier<Keycloak> createAdminClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.quarkus.keycloak.admin.client.common.AutoCloseableDestroyer;
import io.quarkus.keycloak.admin.client.common.KeycloakAdminClientInjectionEnabled;
import io.quarkus.keycloak.adminclient.ResteasyKeycloakAdminClientRecorder;
import io.quarkus.runtime.TlsConfig;

public class KeycloakAdminClientProcessor {

Expand All @@ -48,8 +49,8 @@ ReflectiveClassBuildItem reflect() {
@Record(ExecutionTime.STATIC_INIT)
@Produce(ServiceStartBuildItem.class)
@BuildStep
public void integrate(ResteasyKeycloakAdminClientRecorder recorder) {
recorder.setClientProvider();
public void integrate(ResteasyKeycloakAdminClientRecorder recorder, TlsConfig tlsConfig) {
recorder.setClientProvider(tlsConfig.trustAll);
}

@Record(ExecutionTime.RUNTIME_INIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public Keycloak get() {
};
}

public void setClientProvider() {
public void setClientProvider(boolean tlsTrustAll) {
Keycloak.setClientProvider(new ResteasyClientClassicProvider() {
@Override
public Client newRestEasyClient(Object customJacksonProvider, SSLContext sslContext, boolean disableTrustManager) {
// point here is to use default Quarkus providers rather than org.keycloak.admin.client.JacksonProvider
// as it doesn't work properly in native mode
return ClientBuilderWrapper.create(sslContext, disableTrustManager).build();
return ClientBuilderWrapper.create(sslContext, tlsTrustAll || disableTrustManager).build();
}
});
}
Expand Down
Loading