KEYCLOAK-1882 Add locale mapper to admin console clients during migration
This commit is contained in:
1 parent
ed54ba9064
commit
a53aebcddf
3 files changed
+31
-7
No files matched your search
@@ -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<ProtocolMapperRepresentation> getMappersForClaimMask(Long claimMask);
|
||||
|
||||
List<ProtocolMapperModel> getBuiltinMappers(String protocol);
|
||||
|
||||
}
|
||||
@@ -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<ProtocolMapperModel> 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<RealmModel> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user