diff --git a/src/main/java/sh/libre/scim/core/GroupScimService.java b/src/main/java/sh/libre/scim/core/GroupScimService.java index 4245b247c5..e5b2315552 100644 --- a/src/main/java/sh/libre/scim/core/GroupScimService.java +++ b/src/main/java/sh/libre/scim/core/GroupScimService.java @@ -41,10 +41,14 @@ public class GroupScimService extends AbstractScimService { Set names = new TreeSet<>(); resource.getId().ifPresent(names::add); resource.getDisplayName().ifPresent(names::add); - Optional group = getKeycloakDao().getGroupsStream() - .filter(groupModel -> names.contains(groupModel.getName())) - .findFirst(); - return group.map(GroupModel::getId).map(KeycloakId::new); + try (Stream groupsStream = getKeycloakDao().getGroupsStream()) { + Optional group = groupsStream + .filter(groupModel -> names.contains(groupModel.getName())) + .findFirst(); + return group + .map(GroupModel::getId) + .map(KeycloakId::new); + } } @Override