diff --git a/src/main/java/de/adorsys/keycloak/config/service/GroupImportService.java b/src/main/java/de/adorsys/keycloak/config/service/GroupImportService.java index 6d3a3a23a..b99af1813 100644 --- a/src/main/java/de/adorsys/keycloak/config/service/GroupImportService.java +++ b/src/main/java/de/adorsys/keycloak/config/service/GroupImportService.java @@ -121,10 +121,10 @@ private void buildGroupPathLookupMap(Map map, Group private void createOrUpdateRealmGroup(String realmName, GroupRepresentation group) { String groupName = group.getName(); - Optional maybeGroup = groupRepository.searchByName(realmName, groupName); + GroupRepresentation existingGroup = groupRepository.getGroupByName(realmName, group.getName()); - if (maybeGroup.isPresent()) { - updateGroupIfNecessary(realmName, group); + if (existingGroup != null) { + updateGroupIfNecessary(realmName, group, existingGroup); } else { logger.debug("Create group '{}' in realm '{}'", groupName, realmName); createGroup(realmName, group); @@ -186,8 +186,7 @@ public void addSubGroup(String realmName, String parentGroupId, GroupRepresentat addSubGroups(realmName, patchedGroup); } - private void updateGroupIfNecessary(String realmName, GroupRepresentation group) { - GroupRepresentation existingGroup = groupRepository.getGroupByName(realmName, group.getName()); + private void updateGroupIfNecessary(String realmName, GroupRepresentation group, GroupRepresentation existingGroup) { GroupRepresentation patchedGroup = CloneUtil.patch(existingGroup, group); String groupName = existingGroup.getName();