From a5cbe113fd5c19ed7e7d3143a5cca86db369d521 Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 1 Aug 2016 17:12:50 +0200 Subject: [PATCH] Migration fix --- .../org/keycloak/migration/migrators/MigrateTo2_1_0.java | 6 ++---- .../org/keycloak/migration/migrators/MigrationUtils.java | 8 ++++++++ .../org/keycloak/models/utils/RepresentationToModel.java | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo2_1_0.java b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo2_1_0.java index 8ff3664ad3..9e7b93130d 100644 --- a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo2_1_0.java +++ b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo2_1_0.java @@ -52,11 +52,9 @@ public class MigrateTo2_1_0 { private void migrateDefaultRequiredAction(RealmModel realm) { RequiredActionProviderModel otpAction = realm.getRequiredActionProviderByAlias(UserModel.RequiredAction.CONFIGURE_TOTP.name()); - if (otpAction == null) return; - if (!otpAction.getProviderId().equals(UserModel.RequiredAction.CONFIGURE_TOTP.name())) return; - if (!otpAction.getName().equals("Configure Totp")) return; + MigrationUtils.updateOTPRequiredAction(otpAction); - otpAction.setName("Configure OTP"); + realm.updateRequiredActionProvider(otpAction); } // KEYCLOAK-3338: Changes to how role policy config is stored" diff --git a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationUtils.java b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationUtils.java index 91f812e0bc..08da081b4e 100644 --- a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationUtils.java +++ b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrationUtils.java @@ -47,4 +47,12 @@ public class MigrationUtils { } } + public static void updateOTPRequiredAction(RequiredActionProviderModel otpAction) { + if (otpAction == null) return; + if (!otpAction.getProviderId().equals(UserModel.RequiredAction.CONFIGURE_TOTP.name())) return; + if (!otpAction.getName().equals("Configure Totp")) return; + + otpAction.setName("Configure OTP"); + } + } diff --git a/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index 3efca793af..2be6720e54 100755 --- a/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -21,6 +21,7 @@ import org.keycloak.authorization.AuthorizationProvider; import org.keycloak.authorization.model.ResourceServer; import org.keycloak.authorization.store.ResourceServerStore; import org.keycloak.hash.Pbkdf2PasswordHashProvider; +import org.keycloak.migration.migrators.MigrationUtils; import org.keycloak.models.ClientTemplateModel; import org.keycloak.models.Constants; import org.keycloak.common.util.Base64; @@ -204,6 +205,9 @@ public class RepresentationToModel { if (rep.getRequiredActions() != null) { for (RequiredActionProviderRepresentation action : rep.getRequiredActions()) { RequiredActionProviderModel model = toModel(action); + + MigrationUtils.updateOTPRequiredAction(model); + newRealm.addRequiredActionProvider(model); } } else {