From 70ce721d6b27890ab66ba2294b7e039522788aec Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 9 May 2022 11:44:33 +0200 Subject: [PATCH] check the user --- .../networking/ws/methods/v2/Notifications.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java index e7e092d..32b5035 100644 --- a/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java +++ b/src/main/java/org/gcube/portal/social/networking/ws/methods/v2/Notifications.java @@ -216,7 +216,8 @@ public class Notifications { try { logger.debug("catalogue notifications type is " + event.getType()); SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context); - GCubeUser senderUser = UserManagerWSBuilder.getInstance().getUserManager().getUserByUsername(username); + UserManager um = UserManagerWSBuilder.getInstance().getUserManager(); + GCubeUser senderUser = um.getUserByUsername(username); SocialNetworkingUser user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL()); NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user); @@ -224,6 +225,16 @@ public class Notifications { if (! event.idsAsGroup()) { for (int i = 0; i < idsToNotify.length; i++) { String userIdToNotify = idsToNotify[i]; + try { + um.getUserByUsername(userIdToNotify); + } + catch (Exception e) { + status = Status.NOT_ACCEPTABLE; + logger.error("Username not found", e); + responseBean.setSuccess(false); + responseBean.setMessage("Username not found " + userIdToNotify); + return Response.status(status).entity(responseBean).build(); + } deliveryResult = nm.notifyCatalogueEvent( CatalogueEventTypeMapper.getType(event.getType()),