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)); } }