From e3c76035b21a4f2c7ff5079b5067f775002d9627 Mon Sep 17 00:00:00 2001 From: vramik Date: Mon, 7 Jun 2021 22:30:54 +0200 Subject: [PATCH] KEYCLOAK-18359 Default role migration is not performed correctly when empty realm id --- .../custom/JpaUpdate13_0_0_MigrateDefaultRoles.java | 8 +------- .../java/org/keycloak/services/managers/RealmManager.java | 5 ++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/JpaUpdate13_0_0_MigrateDefaultRoles.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/JpaUpdate13_0_0_MigrateDefaultRoles.java index f0b187b036..81860723ec 100644 --- a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/JpaUpdate13_0_0_MigrateDefaultRoles.java +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/JpaUpdate13_0_0_MigrateDefaultRoles.java @@ -84,13 +84,7 @@ public class JpaUpdate13_0_0_MigrateDefaultRoles extends CustomKeycloakTask { ResultSet rs = statement.executeQuery()) { while (rs.next()) { - String realmId = rs.getString(1); - - if (realmId == null || realmId.trim().isEmpty()) { - continue; - } - - realmIds.add(realmId); + realmIds.add(rs.getString(1)); } } catch (Exception e) { diff --git a/services/src/main/java/org/keycloak/services/managers/RealmManager.java b/services/src/main/java/org/keycloak/services/managers/RealmManager.java index 66cdcb9bb3..5e4d17bce8 100755 --- a/services/src/main/java/org/keycloak/services/managers/RealmManager.java +++ b/services/src/main/java/org/keycloak/services/managers/RealmManager.java @@ -501,10 +501,9 @@ public class RealmManager { */ public RealmModel importRealm(RealmRepresentation rep, boolean skipUserDependent) { String id = rep.getId(); - if (id == null) { + if (id == null || id.trim().isEmpty()) { id = KeycloakModelUtils.generateId(); - } - else { + } else { ReservedCharValidator.validate(id); } RealmModel realm = model.createRealm(id, rep.getRealm());