From 9fb77322208f5ad7af8d4c82437870348f4a32c3 Mon Sep 17 00:00:00 2001 From: Andreas Schmitz Date: Fri, 17 May 2024 11:07:09 +0200 Subject: [PATCH] fix: prevent exception when keycloak group does not exist --- .../provider/keycloak/KeycloakGroupProviderService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shogun-lib/src/main/java/de/terrestris/shogun/lib/service/security/provider/keycloak/KeycloakGroupProviderService.java b/shogun-lib/src/main/java/de/terrestris/shogun/lib/service/security/provider/keycloak/KeycloakGroupProviderService.java index 47de6ec39..140742ee8 100644 --- a/shogun-lib/src/main/java/de/terrestris/shogun/lib/service/security/provider/keycloak/KeycloakGroupProviderService.java +++ b/shogun-lib/src/main/java/de/terrestris/shogun/lib/service/security/provider/keycloak/KeycloakGroupProviderService.java @@ -114,8 +114,9 @@ public List> getGroupsForUser() { List groupRepresentations = keycloakUtil.getKeycloakUserGroups(user.get()); return (List) groupRepresentations.stream(). - map(groupRepresentation -> repository.findByAuthProviderId(groupRepresentation.getId()).orElseThrow()). - collect(Collectors.toList()); + map(groupRepresentation -> repository.findByAuthProviderId(groupRepresentation.getId()).orElse(null)) + .filter(group -> group != null) + .collect(Collectors.toList()); } public void setTransientRepresentations(Group group) {