Merge pull request #3551 from vramik/KEYCLOAK-3983
KEYCLOAK-3983 update protocol mappers of clients and client templates for backward compatibility import
This commit is contained in:
commit
a8de125e26
3 changed files with 22 additions and 21 deletions
|
@ -17,15 +17,11 @@
|
||||||
|
|
||||||
package org.keycloak.migration.migrators;
|
package org.keycloak.migration.migrators;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.keycloak.migration.ModelVersion;
|
import org.keycloak.migration.ModelVersion;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.ClientTemplateModel;
|
import org.keycloak.models.ClientTemplateModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.ProtocolMapperContainerModel;
|
|
||||||
import org.keycloak.models.ProtocolMapperModel;
|
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,29 +35,15 @@ public class MigrateTo2_3_0 implements Migration {
|
||||||
public void migrate(KeycloakSession session) {
|
public void migrate(KeycloakSession session) {
|
||||||
for (RealmModel realm : session.realms().getRealms()) {
|
for (RealmModel realm : session.realms().getRealms()) {
|
||||||
for (ClientModel client : realm.getClients()) {
|
for (ClientModel client : realm.getClients()) {
|
||||||
updateProtocolMappers(client);
|
MigrationUtils.updateProtocolMappers(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ClientTemplateModel clientTemplate : realm.getClientTemplates()) {
|
for (ClientTemplateModel clientTemplate : realm.getClientTemplates()) {
|
||||||
updateProtocolMappers(clientTemplate);
|
MigrationUtils.updateProtocolMappers(clientTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProtocolMappers(ProtocolMapperContainerModel client) {
|
|
||||||
List<ProtocolMapperModel> toUpdate = new LinkedList<>();
|
|
||||||
for (ProtocolMapperModel mapper : client.getProtocolMappers()) {
|
|
||||||
if (!mapper.getConfig().containsKey("userinfo.token.claim") && mapper.getConfig().containsKey("id.token.claim")) {
|
|
||||||
mapper.getConfig().put("userinfo.token.claim", mapper.getConfig().get("id.token.claim"));
|
|
||||||
toUpdate.add(mapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ProtocolMapperModel mapper : toUpdate) {
|
|
||||||
client.updateProtocolMapper(mapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelVersion getVersion() {
|
public ModelVersion getVersion() {
|
||||||
return VERSION;
|
return VERSION;
|
||||||
|
|
|
@ -17,10 +17,14 @@
|
||||||
|
|
||||||
package org.keycloak.migration.migrators;
|
package org.keycloak.migration.migrators;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import org.keycloak.Config;
|
import org.keycloak.Config;
|
||||||
import org.keycloak.models.AdminRoles;
|
import org.keycloak.models.AdminRoles;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
|
import org.keycloak.models.ProtocolMapperContainerModel;
|
||||||
|
import org.keycloak.models.ProtocolMapperModel;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RequiredActionProviderModel;
|
import org.keycloak.models.RequiredActionProviderModel;
|
||||||
import org.keycloak.models.RoleModel;
|
import org.keycloak.models.RoleModel;
|
||||||
|
@ -60,5 +64,19 @@ public class MigrationUtils {
|
||||||
|
|
||||||
otpAction.setName("Configure OTP");
|
otpAction.setName("Configure OTP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateProtocolMappers(ProtocolMapperContainerModel client) {
|
||||||
|
List<ProtocolMapperModel> toUpdate = new LinkedList<>();
|
||||||
|
for (ProtocolMapperModel mapper : client.getProtocolMappers()) {
|
||||||
|
if (!mapper.getConfig().containsKey("userinfo.token.claim") && mapper.getConfig().containsKey("id.token.claim")) {
|
||||||
|
mapper.getConfig().put("userinfo.token.claim", mapper.getConfig().get("id.token.claim"));
|
||||||
|
toUpdate.add(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ProtocolMapperModel mapper : toUpdate) {
|
||||||
|
client.updateProtocolMapper(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1059,7 +1059,7 @@ public class RepresentationToModel {
|
||||||
client.addProtocolMapper(toModel(mapper));
|
client.addProtocolMapper(toModel(mapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MigrationUtils.updateProtocolMappers(client);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1069,6 +1069,7 @@ public class RepresentationToModel {
|
||||||
client.setClientTemplate(template);
|
client.setClientTemplate(template);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
MigrationUtils.updateProtocolMappers(template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue