From 9d04ae1f7e13d9c29c0df503b28e9a4e5fd62cb3 Mon Sep 17 00:00:00 2001 From: Motouom Victoire Date: Fri, 6 Dec 2024 11:29:47 +0100 Subject: [PATCH 1/3] fix: Deleting protocol mappers in the config --- .../config/util/ProtocolMapperUtil.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/adorsys/keycloak/config/util/ProtocolMapperUtil.java b/src/main/java/de/adorsys/keycloak/config/util/ProtocolMapperUtil.java index 96b9bfebe..d6c328ea2 100644 --- a/src/main/java/de/adorsys/keycloak/config/util/ProtocolMapperUtil.java +++ b/src/main/java/de/adorsys/keycloak/config/util/ProtocolMapperUtil.java @@ -22,10 +22,8 @@ import org.keycloak.representations.idm.ProtocolMapperRepresentation; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; +import java.util.stream.Collectors; public class ProtocolMapperUtil { private ProtocolMapperUtil() { @@ -35,23 +33,19 @@ public static List estimateProtocolMappersToRemove List protocolMappers, List existingProtocolMappers ) { - List protocolMappersToRemove = new ArrayList<>(); - - if (existingProtocolMappers == null) { - return protocolMappersToRemove; + if (existingProtocolMappers == null || existingProtocolMappers.isEmpty()) { + return List.of(); // Return an immutable empty list } - for (ProtocolMapperRepresentation existingProtocolMapper : existingProtocolMappers) { - boolean shouldRemove = protocolMappers.stream().noneMatch( - m -> Objects.equals(m.getName(), existingProtocolMapper.getName()) - ); - - if (shouldRemove) { - protocolMappersToRemove.add(existingProtocolMapper); - } - } + Set protocolMapperNames = Optional.ofNullable(protocolMappers) + .stream() + .flatMap(List::stream) + .map(ProtocolMapperRepresentation::getName) + .collect(Collectors.toSet()); - return protocolMappersToRemove; + return existingProtocolMappers.stream() + .filter(existingMapper -> !protocolMapperNames.contains(existingMapper.getName())) + .collect(Collectors.toCollection(ArrayList::new)); } public static List estimateProtocolMappersToAdd( From 6ad9d76cce5308fc08c2578b8a97c41200e430a2 Mon Sep 17 00:00:00 2001 From: Motouom Victoire Date: Fri, 6 Dec 2024 11:33:02 +0100 Subject: [PATCH 2/3] Edit change log --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db1f3af3f..98ad69fb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - Fix to manage Remote state import for clientscopes and scopeMappings [#1012](https://github.com/adorsys/keycloak-config-cli/issues/1012) +### Fixed +- Fixed to delete protocol mappers if not in the import + ### Fixed - Allow environment variables from existing secrets [#822](https://github.com/adorsys/keycloak-config-cli/issues/822) From e56fdc64bdae573a36a8b89e45dea3773269f56e Mon Sep 17 00:00:00 2001 From: Motouom Victoire Date: Fri, 6 Dec 2024 11:34:48 +0100 Subject: [PATCH 3/3] Edit change log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ad69fb5..71b724a65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix to manage Remote state import for clientscopes and scopeMappings [#1012](https://github.com/adorsys/keycloak-config-cli/issues/1012) ### Fixed -- Fixed to delete protocol mappers if not in the import +- Fixed to delete protocol mappers if not in the import[#746](https://github.com/orgs/adorsys/projects/5/views/1?pane=issue&itemId=80856370&issue=adorsys%7Ckeycloak-config-cli%7C746) ### Fixed - Allow environment variables from existing secrets [#822](https://github.com/adorsys/keycloak-config-cli/issues/822)