From 08fd12c96d6a2ccc241b5707c16a744f5c4bcd50 Mon Sep 17 00:00:00 2001 From: UdeshAthukorala Date: Wed, 21 Feb 2024 13:08:36 +0530 Subject: [PATCH] Use the updated mobile number to send otp in verify mobile number on update scenario --- .../notification/DefaultNotificationHandler.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/DefaultNotificationHandler.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/DefaultNotificationHandler.java index 792565d5..7a4fa5f3 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/DefaultNotificationHandler.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/DefaultNotificationHandler.java @@ -58,6 +58,9 @@ public class DefaultNotificationHandler extends AbstractEventHandler { private static final String STREAM_DEFINITION_ID = "stream" ; private static final String NOTIFICATION_TEMPLATE_TYPE = "notification_template" ; private static final String DEFAULT_STREAM_ID = "id_gov_notify_stream:1.0.0"; + private static final String NOTIFICATION_TYPE_VERIFY_MOBILE_ON_UPDATE = "verifyMobileOnUpdate"; + private static final String SEND_TO = "send-to"; + private static final String MOBILE = "mobile"; @Override public void handleEvent(Event event) throws IdentityEventException { @@ -185,6 +188,14 @@ protected Map buildNotificationData(Event event) throws Identity } Map arbitraryDataFromProperties = getArbitraryDataFromProperties(event); arbitraryDataMap.putAll(arbitraryDataFromProperties); + + /* During the verify mobile number on update scenario, the otp needs to send to the 'send-to' number. + (new mobile number). So use the 'send-to' attribute value as 'mobile' number. */ + if (StringUtils.equalsIgnoreCase(NOTIFICATION_TYPE_VERIFY_MOBILE_ON_UPDATE, notificationTemplateName)) { + if (arbitraryDataMap.containsKey(SEND_TO) && StringUtils.isNotBlank(arbitraryDataMap.get(SEND_TO))) { + arbitraryDataMap.put(MOBILE, arbitraryDataMap.get(SEND_TO)); + } + } return arbitraryDataMap ; }