From 23d0afbfd8167bd3cc602394b7a5f0c4c2c0c0d5 Mon Sep 17 00:00:00 2001 From: Marko Strukelj Date: Thu, 21 Dec 2017 11:48:52 +0100 Subject: [PATCH] KEYCLOAK-6058 Partial import should ignore built-in clients --- .../partialimport/ClientsPartialImport.java | 33 ++++++++++++++++++- .../partialimport/PartialImportTest.java | 13 ++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/services/src/main/java/org/keycloak/partialimport/ClientsPartialImport.java b/services/src/main/java/org/keycloak/partialimport/ClientsPartialImport.java index 308d634cc3..954c29166b 100755 --- a/services/src/main/java/org/keycloak/partialimport/ClientsPartialImport.java +++ b/services/src/main/java/org/keycloak/partialimport/ClientsPartialImport.java @@ -17,7 +17,9 @@ package org.keycloak.partialimport; +import org.jboss.logging.Logger; import org.keycloak.models.ClientModel; +import org.keycloak.models.Constants; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; import org.keycloak.models.utils.KeycloakModelUtils; @@ -26,7 +28,11 @@ import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.PartialImportRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * PartialImport handler for Clients. @@ -35,9 +41,28 @@ import java.util.List; */ public class ClientsPartialImport extends AbstractPartialImport { + private static Set INTERNAL_CLIENTS = Collections.unmodifiableSet(new HashSet(Constants.defaultClients)); + + private static Logger logger = Logger.getLogger(ClientsPartialImport.class); + @Override public List getRepList(PartialImportRepresentation partialImportRep) { - return partialImportRep.getClients(); + List clients = partialImportRep.getClients(); + if (clients == null || clients.size() == 0) { + return clients; + } + + // filter out internal clients + List ret = new ArrayList(); + + for (ClientRepresentation c: clients) { + if (!isInternalClient(c.getClientId())) { + ret.add(c); + } else { + logger.debugv("Internal client {0} will not be processed", c.getClientId()); + } + } + return ret; } @Override @@ -85,4 +110,10 @@ public class ClientsPartialImport extends AbstractPartialImport