diff --git a/model/api/src/main/java/org/keycloak/migration/MigrationProvider.java b/model/api/src/main/java/org/keycloak/migration/MigrationProvider.java index 7ba3bb710c..9c8c67892e 100755 --- a/model/api/src/main/java/org/keycloak/migration/MigrationProvider.java +++ b/model/api/src/main/java/org/keycloak/migration/MigrationProvider.java @@ -1,5 +1,6 @@ package org.keycloak.migration; +import org.keycloak.models.ProtocolMapperModel; import org.keycloak.provider.Provider; import org.keycloak.representations.idm.ProtocolMapperRepresentation; @@ -18,4 +19,6 @@ public interface MigrationProvider extends Provider { */ List getMappersForClaimMask(Long claimMask); + List getBuiltinMappers(String protocol); + } diff --git a/model/api/src/main/java/org/keycloak/migration/migrators/MigrateTo1_6_0.java b/model/api/src/main/java/org/keycloak/migration/migrators/MigrateTo1_6_0.java index ecb5482e41..6712c081b5 100644 --- a/model/api/src/main/java/org/keycloak/migration/migrators/MigrateTo1_6_0.java +++ b/model/api/src/main/java/org/keycloak/migration/migrators/MigrateTo1_6_0.java @@ -2,13 +2,10 @@ package org.keycloak.migration.migrators; import java.util.List; +import org.keycloak.Config; +import org.keycloak.migration.MigrationProvider; import org.keycloak.migration.ModelVersion; -import org.keycloak.models.ClientModel; -import org.keycloak.models.Constants; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.RealmModel; -import org.keycloak.models.RoleModel; -import org.keycloak.models.UserModel; +import org.keycloak.models.*; import org.keycloak.models.utils.KeycloakModelUtils; /** @@ -19,6 +16,20 @@ public class MigrateTo1_6_0 { public static final ModelVersion VERSION = new ModelVersion("1.6.0"); public void migrate(KeycloakSession session) { + MigrationProvider provider = session.getProvider(MigrationProvider.class); + + List builtinMappers = provider.getBuiltinMappers("openid-connect"); + ProtocolMapperModel localeMapper = null; + for (ProtocolMapperModel m : builtinMappers) { + if (m.getName().equals("locale")) { + localeMapper = m; + } + } + + if (localeMapper == null) { + throw new RuntimeException("Can't find default locale mapper"); + } + List realms = session.realms().getRealms(); for (RealmModel realm : realms) { if (realm.getRole(Constants.OFFLINE_ACCESS_ROLE) == null) { @@ -39,8 +50,12 @@ public class MigrateTo1_6_0 { user.grantRole(role); } } - } + ClientModel adminConsoleClient = realm.getClientByClientId(Constants.ADMIN_CONSOLE_CLIENT_ID); + if (adminConsoleClient != null) { + adminConsoleClient.addProtocolMapper(localeMapper); + } + } } } diff --git a/services/src/main/java/org/keycloak/services/migration/DefaultMigrationProvider.java b/services/src/main/java/org/keycloak/services/migration/DefaultMigrationProvider.java index 22623f8976..ad46afe1dc 100644 --- a/services/src/main/java/org/keycloak/services/migration/DefaultMigrationProvider.java +++ b/services/src/main/java/org/keycloak/services/migration/DefaultMigrationProvider.java @@ -53,6 +53,12 @@ public class DefaultMigrationProvider implements MigrationProvider { return new ArrayList(allMappers.values()); } + @Override + public List getBuiltinMappers(String protocol) { + LoginProtocolFactory providerFactory = (LoginProtocolFactory) session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, protocol); + return providerFactory.getBuiltinMappers(); + } + @Override public void close() { }