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