From ecfd91e46865b056fbebe4ffcd0ad779054d8df9 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Tue, 17 Aug 2021 18:36:02 +0200 Subject: [PATCH 1/4] Make roles unique when creating users in Keycloak dev services Signed-off-by:Phillip Kruger (cherry picked from commit 967449092c75d3df806af7298200fe2af4fe680e) --- .../keycloak/KeycloakDevServicesProcessor.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 828f5d1985c1e..a936adbbd9077 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -15,6 +15,7 @@ import java.util.Map; import java.util.Optional; import java.util.OptionalInt; +import java.util.stream.Collectors; import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.logging.Logger; @@ -44,6 +45,7 @@ import io.vertx.core.Vertx; import io.vertx.core.http.HttpHeaders; import io.vertx.mutiny.core.buffer.Buffer; +import io.vertx.mutiny.ext.web.client.HttpResponse; import io.vertx.mutiny.ext.web.client.WebClient; public class KeycloakDevServicesProcessor { @@ -342,11 +344,16 @@ private void createRealm(String keycloakUrl, Map users, String o keycloakUrl + "/realms/master/protocol/openid-connect/token", "admin-cli", null, "admin", "admin", capturedDevServicesConfiguration.webClienTimeout); - client.postAbs(keycloakUrl + "/admin/realms") + HttpResponse response = client.postAbs(keycloakUrl + "/admin/realms") .putHeader(HttpHeaders.CONTENT_TYPE.toString(), "application/json") .putHeader(HttpHeaders.AUTHORIZATION.toString(), "Bearer " + token) .sendBuffer(Buffer.buffer().appendString(JsonSerialization.writeValueAsString(realm))) .await().atMost(capturedDevServicesConfiguration.webClienTimeout); + + if (response.statusCode() > 299) { + LOG.errorf("Realm %s can not be created %d - %s ", realm.getRealm(), response.statusCode(), + response.statusMessage()); + } } catch (Throwable t) { LOG.errorf("Realm %s can not be created: %s", realm.getRealm(), t.getMessage()); } finally { @@ -389,7 +396,9 @@ private RealmRepresentation createRealmRep() { realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false)); } else { - for (String role : capturedDevServicesConfiguration.roles.values()) { + List distinctRoles = capturedDevServicesConfiguration.roles.values().stream().distinct() + .collect(Collectors.toList()); + for (String role : distinctRoles) { realm.getRoles().getRealm().add(new RoleRepresentation(role, null, false)); } } From a3567e6991b2a50844929d4562cfe2c546b5a60a Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Tue, 17 Aug 2021 17:09:06 +0100 Subject: [PATCH 2/4] Fix minor DevServices for Keycloak typos (cherry picked from commit 8480de25c8098bac1341e9fb4b26e2f9f96bd018) --- .../oidc/deployment/devservices/keycloak/DevServicesConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java index 6681b830b2d01..f4c37befb9b44 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/DevServicesConfig.java @@ -13,7 +13,7 @@ public class DevServicesConfig { /** - * If DevServices has been explicitly enabled or disabled.. + * If DevServices has been explicitly enabled or disabled. *

* When DevServices is enabled Quarkus will attempt to automatically configure and start * Keycloak when running in Dev or Test mode and when Docker is running. From 550fedd86ef416ba6e9fe3986182b6bde239428a Mon Sep 17 00:00:00 2001 From: Andrej Vano Date: Wed, 18 Aug 2021 14:41:59 +0200 Subject: [PATCH 3/4] [Docs] Fix typo in config reference (cherry picked from commit 17413e55f5a910bf81f95f89f764af5b9da1e202) --- docs/src/main/asciidoc/config-reference.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/config-reference.adoc b/docs/src/main/asciidoc/config-reference.adoc index 0ff88ef12e106..81cfd4f4bc615 100644 --- a/docs/src/main/asciidoc/config-reference.adoc +++ b/docs/src/main/asciidoc/config-reference.adoc @@ -453,7 +453,7 @@ It is also possible to generate an example `application.properties` with all kno This creates a `src/main/resources/application.properties.example` file that contains all the config options exposed via the extensions currently present in the application. These options are commented out, and have their value -set to default swhen applicable. For example this HTTP port config entry will appear as: +set to defaults when applicable. For example this HTTP port config entry will appear as: .application.properties [source,properties] From 90a3703184afc87d5d60323e46f3151685f83c0c Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Wed, 18 Aug 2021 21:44:40 +0200 Subject: [PATCH 4/4] Ability to configure the registry URL from an env var --- .../config/RegistriesConfigLocator.java | 13 ++++++- .../config/RegistriesConfigLocatorTest.java | 36 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java index 0f9f8ad0faab3..156166f6693a4 100644 --- a/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java +++ b/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/config/RegistriesConfigLocator.java @@ -270,7 +270,18 @@ static RegistriesConfig initFromEnvironmentOrNull(Map map) { if (isEnvVarOption(var.getKey(), envvarPrefix, "UPDATE_POLICY")) { registry.setUpdatePolicy(var.getValue()); - break; + } else if (isEnvVarOption(var.getKey(), envvarPrefix, "REPO_URL")) { + JsonRegistryMavenConfig maven = (JsonRegistryMavenConfig) registry.getMaven(); + if (maven == null) { + maven = new JsonRegistryMavenConfig(); + registry.setMaven(maven); + } + JsonRegistryMavenRepoConfig repository = (JsonRegistryMavenRepoConfig) maven.getRepository(); + if (repository == null) { + repository = new JsonRegistryMavenRepoConfig(); + maven.setRepository(repository); + } + repository.setUrl(var.getValue()); } } } diff --git a/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java b/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java index 7dd751539e147..d5e1bd2991280 100644 --- a/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java +++ b/independent-projects/tools/registry-client/src/test/java/io/quarkus/registry/config/RegistriesConfigLocatorTest.java @@ -6,6 +6,8 @@ import io.quarkus.registry.config.json.JsonRegistriesConfig; import io.quarkus.registry.config.json.JsonRegistryConfig; import io.quarkus.registry.config.json.JsonRegistryDescriptorConfig; +import io.quarkus.registry.config.json.JsonRegistryMavenConfig; +import io.quarkus.registry.config.json.JsonRegistryMavenRepoConfig; import io.quarkus.registry.config.json.RegistriesConfigMapperHelper; import java.io.StringReader; import java.io.StringWriter; @@ -85,6 +87,40 @@ void testRegistryUpdatePolicyFromEnvironment() { assertThat(actualConfig).isEqualTo(expectedConfig); } + @Test + void testRegistryRepositoryURLFromEnvironment() { + final Map env = new HashMap<>(); + env.put(RegistriesConfigLocator.QUARKUS_REGISTRIES, "registry.acme.org,registry.other.io"); + env.put(RegistriesConfigLocator.QUARKUS_REGISTRY_ENV_VAR_PREFIX + "REGISTRY_ACME_ORG_UPDATE_POLICY", "always"); + env.put(RegistriesConfigLocator.QUARKUS_REGISTRY_ENV_VAR_PREFIX + "REGISTRY_OTHER_IO_REPO_URL", + "https://custom.registry.net/mvn"); + final RegistriesConfig actualConfig = initFromEnvironment(env); + + final JsonRegistriesConfig expectedConfig = new JsonRegistriesConfig(); + + JsonRegistryConfig registry = new JsonRegistryConfig(); + registry.setId("registry.acme.org"); + JsonRegistryDescriptorConfig descriptor = new JsonRegistryDescriptorConfig(); + descriptor.setArtifact(ArtifactCoords.fromString("org.acme.registry:quarkus-registry-descriptor::json:1.0-SNAPSHOT")); + registry.setDescriptor(descriptor); + registry.setUpdatePolicy("always"); + expectedConfig.addRegistry(registry); + + registry = new JsonRegistryConfig(); + registry.setId("registry.other.io"); + descriptor = new JsonRegistryDescriptorConfig(); + descriptor.setArtifact(ArtifactCoords.fromString("io.other.registry:quarkus-registry-descriptor::json:1.0-SNAPSHOT")); + registry.setDescriptor(descriptor); + JsonRegistryMavenConfig maven = new JsonRegistryMavenConfig(); + registry.setMaven(maven); + JsonRegistryMavenRepoConfig repo = new JsonRegistryMavenRepoConfig(); + maven.setRepository(repo); + repo.setUrl("https://custom.registry.net/mvn"); + expectedConfig.addRegistry(registry); + + assertThat(actualConfig).isEqualTo(expectedConfig); + } + private static RegistriesConfig initFromEnvironment(Map env) { return RegistriesConfigLocator.initFromEnvironmentOrNull(env); }