diff --git a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/user/KeycloakUserBackend.java b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/user/KeycloakUserBackend.java index 73064ff8c..1d32d21d5 100644 --- a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/user/KeycloakUserBackend.java +++ b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/user/KeycloakUserBackend.java @@ -62,13 +62,22 @@ private static boolean isTeam(String role) { @Override public List searchUsers(String query) { try { - Set machineIds = keycloak.realm(realm).roles().get(Roles.MACHINE).getUserMembers(0, Integer.MAX_VALUE).stream().map(UserRepresentation::getId).collect(Collectors.toSet()); + Set machineIds = safeMachineIds(); return keycloak.realm(realm).users().search(query, null, null).stream().filter(rep -> !machineIds.contains(rep.getId())).map(KeycloakUserBackend::toUserInfo).toList(); } catch (Throwable t) { throw ServiceException.serverError("Unable to search for users"); } } + private Set safeMachineIds() { + try { + return keycloak.realm(realm).roles().get(Roles.MACHINE).getUserMembers(0, Integer.MAX_VALUE).stream().map(UserRepresentation::getId).collect(Collectors.toSet()); + } catch (Exception e) { + // ignore exception + return Set.of(); + } + } + @Override public List info(List usernames) { List users = new ArrayList<>(); for (String username : usernames) {