diff --git a/extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesRequiredBuildItem.java b/extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesRequiredBuildItem.java index 49cd131711bb1..5093a9f369185 100644 --- a/extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesRequiredBuildItem.java +++ b/extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesRequiredBuildItem.java @@ -4,10 +4,11 @@ import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.jboss.logging.Logger; import org.keycloak.representations.idm.RealmRepresentation; @@ -24,6 +25,7 @@ public final class KeycloakDevServicesRequiredBuildItem extends MultiBuildItem { private static final Logger LOG = Logger.getLogger(KeycloakDevServicesProcessor.class); public static final String OIDC_AUTH_SERVER_URL_CONFIG_KEY = "quarkus.oidc.auth-server-url"; + private static final String OIDC_PROVIDER_CONFIG_KEY = "quarkus.oidc.provider"; private final KeycloakDevServicesConfigurator devServicesConfigurator; private final String authServerUrl; @@ -39,8 +41,17 @@ String getAuthServerUrl() { } public static KeycloakDevServicesRequiredBuildItem of(KeycloakDevServicesConfigurator devServicesConfigurator, - String authServerUrl, String... dontStartConfigProperties) { - if (shouldStartDevService(dontStartConfigProperties, authServerUrl)) { + String authServerUrl, String... additionalDontStartConfigProperties) { + final Set dontStartConfigProperties = new HashSet<>(Arrays.asList(additionalDontStartConfigProperties)); + dontStartConfigProperties.add(authServerUrl); + dontStartConfigProperties.add(OIDC_AUTH_SERVER_URL_CONFIG_KEY); + dontStartConfigProperties.add(OIDC_PROVIDER_CONFIG_KEY); + return of(devServicesConfigurator, authServerUrl, dontStartConfigProperties); + } + + private static KeycloakDevServicesRequiredBuildItem of(KeycloakDevServicesConfigurator devServicesConfigurator, + String authServerUrl, Set dontStartConfigProperties) { + if (shouldStartDevService(dontStartConfigProperties)) { return new KeycloakDevServicesRequiredBuildItem(devServicesConfigurator, authServerUrl); } return null; @@ -69,10 +80,8 @@ public void customizeDefaultRealm(RealmRepresentation realmRepresentation) { }; } - private static boolean shouldStartDevService(String[] dontStartConfigProperties, String authServerUrl) { - return Stream - .concat(Stream.of(authServerUrl), Arrays.stream(dontStartConfigProperties)) - .allMatch(KeycloakDevServicesRequiredBuildItem::shouldStartDevService); + private static boolean shouldStartDevService(Set dontStartConfigProperties) { + return dontStartConfigProperties.stream().allMatch(KeycloakDevServicesRequiredBuildItem::shouldStartDevService); } private static boolean shouldStartDevService(String dontStartConfigProperty) { diff --git a/extensions/oidc-client-registration/deployment/src/main/java/io/quarkus/oidc/client/registration/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java b/extensions/oidc-client-registration/deployment/src/main/java/io/quarkus/oidc/client/registration/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java index 5ba594617a5b6..bff9cd44584b0 100644 --- a/extensions/oidc-client-registration/deployment/src/main/java/io/quarkus/oidc/client/registration/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java +++ b/extensions/oidc-client-registration/deployment/src/main/java/io/quarkus/oidc/client/registration/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java @@ -1,7 +1,5 @@ package io.quarkus.oidc.client.registration.deployment.devservices.keycloak; -import static io.quarkus.devservices.keycloak.KeycloakDevServicesRequiredBuildItem.OIDC_AUTH_SERVER_URL_CONFIG_KEY; - import java.util.List; import java.util.Map; @@ -55,8 +53,7 @@ public void customizeDefaultRealm(RealmRepresentation realmRepresentation) { } }; - return KeycloakDevServicesRequiredBuildItem.of(devServicesConfigurator, - OIDC_CLIENT_REG_AUTH_SERVER_URL_CONFIG_KEY, OIDC_AUTH_SERVER_URL_CONFIG_KEY); + return KeycloakDevServicesRequiredBuildItem.of(devServicesConfigurator, OIDC_CLIENT_REG_AUTH_SERVER_URL_CONFIG_KEY); } @BuildStep(onlyIf = IsDevelopment.class) diff --git a/extensions/oidc-client/deployment/src/main/java/io/quarkus/oidc/client/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java b/extensions/oidc-client/deployment/src/main/java/io/quarkus/oidc/client/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java index 099afd16de833..5ca43f77ad4bd 100644 --- a/extensions/oidc-client/deployment/src/main/java/io/quarkus/oidc/client/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java +++ b/extensions/oidc-client/deployment/src/main/java/io/quarkus/oidc/client/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java @@ -1,7 +1,5 @@ package io.quarkus.oidc.client.deployment.devservices.keycloak; -import static io.quarkus.devservices.keycloak.KeycloakDevServicesRequiredBuildItem.OIDC_AUTH_SERVER_URL_CONFIG_KEY; - import java.util.HashMap; import io.quarkus.deployment.IsDevelopment; @@ -35,7 +33,7 @@ KeycloakDevServicesRequiredBuildItem requireKeycloakDevService(KeycloakDevServic configProperties.put(OIDC_CLIENT_SECRET_CONFIG_KEY, ctx.oidcClientSecret()); } return configProperties; - }, OIDC_CLIENT_AUTH_SERVER_URL_CONFIG_KEY, OIDC_CLIENT_TOKEN_PATH_CONFIG_KEY, OIDC_AUTH_SERVER_URL_CONFIG_KEY); + }, OIDC_CLIENT_AUTH_SERVER_URL_CONFIG_KEY, OIDC_CLIENT_TOKEN_PATH_CONFIG_KEY); } @BuildStep(onlyIf = IsDevelopment.class) diff --git a/extensions/oidc-client/deployment/src/test/java/io/quarkus/oidc/client/OidcClientKeycloakDevServiceStartupTest.java b/extensions/oidc-client/deployment/src/test/java/io/quarkus/oidc/client/OidcClientKeycloakDevServiceStartupTest.java new file mode 100644 index 0000000000000..bbb6243429eda --- /dev/null +++ b/extensions/oidc-client/deployment/src/test/java/io/quarkus/oidc/client/OidcClientKeycloakDevServiceStartupTest.java @@ -0,0 +1,33 @@ +package io.quarkus.oidc.client; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +/** + * Test Keycloak Dev Service is not started when known social provider is configured + * in Quarkus OIDC extension. + */ +public class OidcClientKeycloakDevServiceStartupTest { + + @RegisterExtension + static final QuarkusUnitTest test = new QuarkusUnitTest() + .withApplicationRoot(jar -> jar + .addAsResource(new StringAsset(""" + quarkus.oidc.provider=slack + quarkus.oidc.client-id=irrelevant-client-id + """), "application.properties")) + .setLogRecordPredicate(logRecord -> logRecord != null && logRecord.getMessage() != null + && logRecord.getMessage().contains("Dev Services for Keycloak started")) + .assertLogRecords(logRecords -> assertTrue(logRecords.isEmpty())); + + @Test + public void testDevServiceNotStarted() { + // needs to be here so that log asserter runs after all tests + } + +} diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java index a9ac5fa48a7cd..3087bdc421efd 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServiceRequiredBuildStep.java @@ -21,7 +21,6 @@ public class KeycloakDevServiceRequiredBuildStep { private static final Logger LOG = Logger.getLogger(KeycloakDevServiceRequiredBuildStep.class); private static final String CONFIG_PREFIX = "quarkus.oidc."; private static final String TENANT_ENABLED_CONFIG_KEY = CONFIG_PREFIX + "tenant-enabled"; - private static final String PROVIDER_CONFIG_KEY = CONFIG_PREFIX + "provider"; private static final String APPLICATION_TYPE_CONFIG_KEY = CONFIG_PREFIX + "application-type"; private static final String CLIENT_ID_CONFIG_KEY = CONFIG_PREFIX + "client-id"; private static final String CLIENT_SECRET_CONFIG_KEY = CONFIG_PREFIX + "credentials.secret"; @@ -42,7 +41,7 @@ KeycloakDevServicesRequiredBuildItem requireKeycloakDevService(KeycloakDevServic configProperties.put(CLIENT_SECRET_CONFIG_KEY, ctx.oidcClientSecret()); } return configProperties; - }, OIDC_AUTH_SERVER_URL_CONFIG_KEY, PROVIDER_CONFIG_KEY); + }, OIDC_AUTH_SERVER_URL_CONFIG_KEY); } private static boolean isOidcTenantEnabled() {