From 2c3f249271eb83c886220357001240368b254041 Mon Sep 17 00:00:00 2001 From: ZiyamSanthosh Date: Tue, 19 Nov 2024 12:24:13 +0530 Subject: [PATCH 1/2] Add push sender and push notification event handler related implementation --- .../pom.xml | 15 + .../notification/NotificationConstants.java | 73 +++++ .../notification/PushNotificationHandler.java | 299 ++++++++++++++++++ .../NotificationHandlerDataHolder.java | 59 ++++ .../NotificationHandlerServiceComponent.java | 44 +++ .../notification/util/NotificationUtil.java | 2 +- .../pom.xml | 10 +- ...NotificationSenderManagementConstants.java | 19 +- .../NotificationSenderManagementService.java | 57 ++++ ...tificationSenderManagementServiceImpl.java | 156 +++++++++ .../tenant/config/dto/PushSenderDTO.java | 55 ++++ .../handlers/ChannelConfigurationHandler.java | 28 ++ .../DefaultChannelConfigurationHandler.java | 14 + ...ificationSenderTenantConfigDataHolder.java | 34 ++ ...tificationSenderTenantConfigServiceDS.java | 21 ++ .../config/utils/NotificationSenderUtils.java | 133 ++++++++ pom.xml | 8 + 17 files changed, 1024 insertions(+), 3 deletions(-) create mode 100644 components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java create mode 100644 components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/dto/PushSenderDTO.java diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/pom.xml b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/pom.xml index 6fd8a757..2a5d1d9d 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/pom.xml +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/pom.xml @@ -94,6 +94,14 @@ org.wso2.carbon.identity.framework org.wso2.carbon.identity.central.log.mgt + + org.wso2.carbon.identity.event.handler.notification + org.wso2.carbon.identity.notification.sender.tenant.config + + + org.wso2.carbon.identity.notification.push + org.wso2.carbon.identity.notification.push.provider + com.fasterxml.jackson.core jackson-databind @@ -181,6 +189,7 @@ org.wso2.carbon.identity.base; version="${carbon.identity.framework.imp.pkg.version.range}", org.wso2.carbon.identity.event; version="${carbon.identity.framework.imp.pkg.version.range}", org.wso2.carbon.identity.event.event; version="${carbon.identity.framework.imp.pkg.version.range}", + org.wso2.carbon.identity.event.bean; version="${carbon.identity.framework.imp.pkg.version.range}", org.wso2.carbon.identity.event.handler; version="${carbon.identity.framework.imp.pkg.version.range}", org.wso2.carbon.identity.application.authentication.framework.config; version="${carbon.identity.framework.imp.pkg.version.range}", org.wso2.carbon.identity.application.mgt;version="${carbon.identity.framework.imp.pkg.version.range}", @@ -196,6 +205,12 @@ org.wso2.carbon.identity.organization.management.service;version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", org.wso2.carbon.identity.organization.management.service.constant;version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", org.wso2.carbon.identity.organization.management.service.exception;version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", + org.wso2.carbon.identity.notification.push.provider; version="${identity.notification.push.version.range}", + org.wso2.carbon.identity.notification.push.provider.exception; version="${identity.notification.push.version.range}", + org.wso2.carbon.identity.notification.push.provider.model; version="${identity.notification.push.version.range}", + org.wso2.carbon.identity.notification.sender.tenant.config; version="${identity.event.handler.notification.imp.pkg.version.range}", + org.wso2.carbon.identity.notification.sender.tenant.config.dto; version="${identity.event.handler.notification.imp.pkg.version.range}", + org.wso2.carbon.identity.notification.sender.tenant.config.exception; version="${identity.event.handler.notification.imp.pkg.version.range}", diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java index 747afead..1cb9de9b 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java @@ -120,6 +120,79 @@ public static class SMSNotification { public static final String DEFAULT_SMS_NOTIFICATION_LOCALE = "en_US"; } + public static class PushNotification { + + public static final String PUSH_NOTIFICATION_EVENT = "TRIGGER_PUSH_NOTIFICATION"; + public static final String PUSH_NOTIFICATION_HANDLER_NAME = "PushNotificationHandler"; + public static final String PUSH_PUBLISHER_NAME = "PushPublisher"; + public static final String PUSH_AUTHENTICATION_SCENARIO = "AUTHENTICATION"; + + public static final String NOTIFICATION_SCENARIO = "NOTIFICATION_SCENARIO"; + public static final String NOTIFICATION_PROVIDER = "notificationProvider"; + public static final String PUSH_ID = "pushId"; + public static final String DEVICE_TOKEN = "deviceToken"; + public static final String CHALLENGE = "challenge"; + public static final String NUMBER_CHALLENGE = "numberChallenge"; + public static final String HOST_NAME = "hostName"; + public static final String REQUEST_DEVICE_OS = "deviceOS"; + public static final String REQUEST_DEVICE_BROWSER = "browser"; + } + + public enum PushNotificationTemplate { + + AUTHENTICATION( + PushNotification.PUSH_AUTHENTICATION_SCENARIO, + "Authentication Request", + "{{user-name}} from {{organization-name}} is trying to login"); + + private String scenario; + private String title; + private String body; + + PushNotificationTemplate(String scenario, String title, String body) { + + this.scenario = scenario; + this.title = title; + this.body = body; + } + + public String getScenario() { + + return scenario; + } + + public String getTitle() { + + return title; + } + + public String getBody() { + + return body; + } + } + + public enum PushNotificationPlaceholder { + + USER_NAME("user-name"), + USER_GIVEN_NAME("user.claim.givenname"), + USER_STORE_DOMAIN("userstore-domain"), + ORGANIZATION_NAME("organization-name"), + TENANT_DOMAIN("tenant-domain"),; + + private String placeholder; + + PushNotificationPlaceholder(String placeholder) { + + this.placeholder = placeholder; + } + + public String getPlaceholder() { + + return placeholder; + } + } + /** * Define logging constants. */ diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java new file mode 100644 index 00000000..f64cd6e6 --- /dev/null +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java @@ -0,0 +1,299 @@ +package org.wso2.carbon.identity.event.handler.notification; + +import org.apache.commons.lang.StringUtils; +import org.wso2.carbon.identity.base.IdentityRuntimeException; +import org.wso2.carbon.identity.core.bean.context.MessageContext; +import org.wso2.carbon.identity.event.IdentityEventConstants; +import org.wso2.carbon.identity.event.IdentityEventException; +import org.wso2.carbon.identity.event.bean.IdentityEventMessageContext; +import org.wso2.carbon.identity.event.event.Event; +import org.wso2.carbon.identity.event.handler.notification.internal.NotificationHandlerDataHolder; +import org.wso2.carbon.identity.event.handler.notification.util.NotificationUtil; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; +import org.wso2.carbon.identity.notification.push.provider.exception.PushProviderException; +import org.wso2.carbon.identity.notification.push.provider.model.PushNotificationData; +import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants; +import org.wso2.carbon.identity.notification.sender.tenant.config.dto.PushSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementException; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.organization.management.service.OrganizationManager; +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; + +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.EmailNotification.ORGANIZATION_NAME_PLACEHOLDER; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.CHALLENGE; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.DEVICE_TOKEN; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.HOST_NAME; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.NOTIFICATION_PROVIDER; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.NOTIFICATION_SCENARIO; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.NUMBER_CHALLENGE; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.PUSH_ID; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.PUSH_NOTIFICATION_EVENT; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.PUSH_NOTIFICATION_HANDLER_NAME; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.REQUEST_DEVICE_BROWSER; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.REQUEST_DEVICE_OS; +import static org.wso2.carbon.identity.event.handler.notification.util.NotificationUtil.extractPlaceHolders; + +/** + * This class represents the push notification event handler. + */ +public class PushNotificationHandler extends DefaultNotificationHandler { + + private static final Log LOG = LogFactory.getLog(PushNotificationHandler.class); + + @Override + public boolean canHandle(MessageContext messageContext) throws IdentityRuntimeException { + + Event event = ((IdentityEventMessageContext) messageContext).getEvent(); + return event.getEventName().equals(PUSH_NOTIFICATION_EVENT); + } + + @Override + public String getName() { + + return PUSH_NOTIFICATION_HANDLER_NAME; + } + + @Override + public void handleEvent(Event event) throws IdentityEventException { + + String tenantDomain = (String) event.getEventProperties().get(NotificationConstants.TENANT_DOMAIN); + if (LOG.isDebugEnabled()) { + LOG.debug("Handling push notification event for " + tenantDomain); + } + + try { + if (StringUtils.isNotBlank(tenantDomain)) { + OrganizationManager organizationManager = + NotificationHandlerDataHolder.getInstance().getOrganizationManager(); + String organizationId = organizationManager.resolveOrganizationId(tenantDomain); + event.getEventProperties().put( + NotificationConstants.EmailNotification.ORGANIZATION_ID_PLACEHOLDER, organizationId); + } + } catch (OrganizationManagementException e) { + throw new IdentityEventException(e.getMessage(), e); + } + + if (!validatePushEventProperties(event)) { + throw new IdentityEventException("Event properties validation failed to proceed with the " + + "push notification sending through provider."); + } + + try { + /* + * Get the registered Push notification senders from the database. This is done to support multiple push + * senders in the future. However, in the current implementation, only one push notification sender is + * supported through the UI. + */ + List pushSenders = NotificationHandlerDataHolder.getInstance() + .getNotificationSenderManagementService().getPushSenders(true); + if (pushSenders != null) { + for (PushSenderDTO pushSenderDTO : pushSenders) { + // This is to get the supported push providers. We can include push providers through OSGi. + PushProvider provider = NotificationHandlerDataHolder.getInstance() + .getPushProvider(pushSenderDTO.getProvider()); + if (provider == null) { + throw new IdentityEventException("No Push notification provider found for the name: " + + pushSenderDTO.getName()); + } + String registeredProvider = (String) event.getEventProperties().get(NOTIFICATION_PROVIDER); + if (!registeredProvider.equalsIgnoreCase(pushSenderDTO.getProvider())) { + throw new IdentityEventException("User is not registered to the Push notification provider: " + + pushSenderDTO.getName()); + } + + PushNotificationData pushNotificationData = buildPushNotificationData(event); + provider.sendNotification(pushNotificationData, pushSenderDTO, tenantDomain); + } + } + } catch (NotificationSenderManagementException e) { + throw new IdentityEventException("Error while retrieving SMS Sender: " + + NotificationSenderManagementConstants.DEFAULT_PUSH_PUBLISHER, e); + } catch (PushProviderException e) { + // Error code and message thrown by the PushProviderException is thrown with an IdentityEventException. + // This error will be handled in the authenticator to display relevant error message according to the + // error scenario. + throw new IdentityEventException(e.getErrorCode(), e.getMessage(), e); + } + } + + /** + * Validate the event properties before sending the push notification. + * + * @param event Event object. + * @return True if the event properties are valid. + */ + private boolean validatePushEventProperties(Event event) { + + Map eventProperties = event.getEventProperties(); + if (eventProperties == null) { + return false; + } + String[] requiredProperties = {NOTIFICATION_SCENARIO, NOTIFICATION_PROVIDER, DEVICE_TOKEN}; + for (String property : requiredProperties) { + if (eventProperties.get(property) == null) { + return false; + } + } + return true; + } + + /** + * Build the push notification data object. + * + * @param event Event object. + * @return PushNotificationData object. + * @throws IdentityEventException If an error occurs while building the push notification data. + */ + private PushNotificationData buildPushNotificationData(Event event) throws IdentityEventException { + + Map eventProperties = event.getEventProperties(); + PushNotificationData pushNotificationData = new PushNotificationData(); + + // Build the notification popup content. + buildNotificationContent(eventProperties, pushNotificationData); + + // Add user related data. + pushNotificationData.setUsername( + (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_NAME)); + pushNotificationData.setTenantDomain( + (String) eventProperties.get(IdentityEventConstants.EventProperty.TENANT_DOMAIN)); + pushNotificationData.setUserStoreDomain( + (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN)); + pushNotificationData.setApplicationName( + (String) eventProperties.get(IdentityEventConstants.EventProperty.APPLICATION_NAME)); + + // Add push notification related data. + pushNotificationData.setNotificationScenario((String) eventProperties.get(NOTIFICATION_SCENARIO)); + pushNotificationData.setPushId((String) eventProperties.get(PUSH_ID)); + pushNotificationData.setDeviceToken((String) eventProperties.get(DEVICE_TOKEN)); + pushNotificationData.setChallenge((String) eventProperties.get(CHALLENGE)); + pushNotificationData.setNumberChallenge((String) eventProperties.get(NUMBER_CHALLENGE)); + + // Add system related data. + pushNotificationData.setHostName((String) eventProperties.get(HOST_NAME)); + pushNotificationData.setDeviceOS((String) eventProperties.get(REQUEST_DEVICE_OS)); + pushNotificationData.setBrowser((String) eventProperties.get(REQUEST_DEVICE_BROWSER)); + + return pushNotificationData; + } + + /** + * Build the content of the push notification. + * + * @param eventProperties Event properties. + * @param pushNotificationData Push notification data object. + * @throws IdentityEventException If an error occurs while building the notification content. + */ + private void buildNotificationContent(Map eventProperties, + PushNotificationData pushNotificationData) throws IdentityEventException { + + String scenario = (String) eventProperties.get(NOTIFICATION_SCENARIO); + + NotificationConstants.PushNotificationTemplate template = + Arrays.stream(NotificationConstants.PushNotificationTemplate.values()) + .filter(pushNotificationTemplate -> pushNotificationTemplate.getScenario().equals(scenario)) + .findFirst() + .orElseThrow(() -> new IdentityEventException( + "Push notification template not found for the scenario: " + scenario)); + + Set placeHolderSet = new HashSet<>(); + placeHolderSet.addAll(extractPlaceHolders(template.getTitle())); + placeHolderSet.addAll(extractPlaceHolders(template.getBody())); + + // Validate if there are invalid placeholders. + validatePlaceHolders(placeHolderSet); + + // Retrieve the placeholder values from the event properties. + Map placeholderValues = getPlaceHolderValues(eventProperties, placeHolderSet); + + // Resolve the organization name placeholder. + String tenantDomain = placeholderValues.get( + NotificationConstants.PushNotificationPlaceholder.TENANT_DOMAIN.name()); + if (StringUtils.isEmpty(tenantDomain)) { + tenantDomain = (String) eventProperties.get(IdentityEventConstants.EventProperty.TENANT_DOMAIN); + } + if (placeholderValues.containsKey(ORGANIZATION_NAME_PLACEHOLDER)) { + String organizationName = NotificationUtil.resolveHumanReadableOrganizationName(tenantDomain); + placeholderValues.put(ORGANIZATION_NAME_PLACEHOLDER, organizationName); + } + + // Replace the placeholders in the push notification template with the actual values. + String title = replacePlaceHolders(template.getTitle(), placeholderValues); + pushNotificationData.setNotificationTitle(title); + String body = replacePlaceHolders(template.getBody(), placeholderValues); + pushNotificationData.setNotificationBody(body); + } + + /** + * Validate the placeholders in the push notification template. + * + * @param placeHolderSet Set of placeholders. + * @throws IdentityEventException If an invalid placeholder is found. + */ + private void validatePlaceHolders(Set placeHolderSet) throws IdentityEventException { + + Set validPlaceHolders = Arrays.stream(NotificationConstants.PushNotificationPlaceholder.values()) + .map(NotificationConstants.PushNotificationPlaceholder::getPlaceholder).collect(Collectors.toSet()); + + for (String placeHolder : placeHolderSet) { + if (!validPlaceHolders.contains(placeHolder)) { + throw new IdentityEventException("Invalid placeholder found: " + placeHolder); + } + } + } + + /** + * Get the placeholder values from the event properties. + * + * @param eventProperties Event properties. + * @param placeholderSet Set of placeholders. + * @return Map of placeholder values. + */ + private Map getPlaceHolderValues(Map eventProperties, Set placeholderSet) { + + NotificationConstants.PushNotificationPlaceholder[] placeHolderKeys = + NotificationConstants.PushNotificationPlaceholder.values(); + Map placeholderValues = new HashMap<>(); + + for (String placeHolder : placeholderSet) { + NotificationConstants.PushNotificationPlaceholder matchedKey = Arrays.stream(placeHolderKeys) + .filter(key -> key.getPlaceholder().equalsIgnoreCase(placeHolder)) + .findFirst() + .orElse(null); + + // If a matching key is found, retrieve the corresponding value from event properties + if (matchedKey != null) { + String value = (String) eventProperties.get(matchedKey.getPlaceholder()); + placeholderValues.put(placeHolder, value); + } + } + + return placeholderValues; + } + + /** + * Replace the placeholders in the push notification template with the actual values. + * + * @param content Push notification template content. + * @param placeholderValues Map of placeholder values. + * @return Push notification content with placeholders replaced. + */ + private String replacePlaceHolders(String content, Map placeholderValues) { + + for (Map.Entry entry : placeholderValues.entrySet()) { + String placeholder = entry.getKey(); + String value = entry.getValue(); + content = content.replace("{{" + placeholder + "}}", value); + } + return content; + } +} diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerDataHolder.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerDataHolder.java index 82481eb2..32db2ff5 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerDataHolder.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerDataHolder.java @@ -18,10 +18,14 @@ package org.wso2.carbon.identity.event.handler.notification.internal; +import java.util.HashMap; +import java.util.Map; import org.wso2.carbon.event.publisher.core.EventPublisherService; import org.wso2.carbon.event.stream.core.EventStreamService; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; +import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; @@ -39,6 +43,8 @@ public class NotificationHandlerDataHolder { private NotificationTemplateManager notificationTemplateManager = null; private OrganizationManager organizationManager; private ApplicationManagementService applicationManagementService; + private NotificationSenderManagementService notificationSenderManagementService; + private final Map pushNotificationProviders = new HashMap<>(); public ApplicationManagementService getApplicationManagementService() { @@ -138,4 +144,57 @@ public void setOrganizationManager(OrganizationManager organizationManager) { this.organizationManager = organizationManager; } + + /** + * Set notification sender management service. + * + * @param notificationSenderManagementService + * {@link org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService} + */ + public void setNotificationSenderManagementService(NotificationSenderManagementService notificationSenderManagementService) { + + this.notificationSenderManagementService = notificationSenderManagementService; + } + + /** + * Get notification sender management service. + * + * @return {@link org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService} + */ + public NotificationSenderManagementService getNotificationSenderManagementService() { + + return notificationSenderManagementService; + } + + /** + * Add a push notification provider. + * + * @param providerName Name of the provider. + * @param provider {@link org.wso2.carbon.identity.notification.push.provider.PushProvider} instance. + */ + public void addPushProvider(String providerName, PushProvider provider) { + + pushNotificationProviders.put(providerName, provider); + } + + /** + * Remove a push notification provider. + * + * @param providerName Name of the provider. + */ + public void removePushProvider(String providerName) { + + pushNotificationProviders.remove(providerName); + } + + /** + * Get a push notification provider. + * + * @param providerName Name of the provider. + * @return {@link org.wso2.carbon.identity.notification.push.provider.PushProvider} instance. + */ + public PushProvider getPushProvider(String providerName) { + + return pushNotificationProviders.get(providerName); + } } diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerServiceComponent.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerServiceComponent.java index ff792547..2cd4ba9b 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerServiceComponent.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/internal/NotificationHandlerServiceComponent.java @@ -26,8 +26,11 @@ import org.wso2.carbon.identity.event.handler.AbstractEventHandler; import org.wso2.carbon.identity.event.handler.notification.DefaultNotificationHandler; import org.wso2.carbon.identity.event.handler.notification.NotificationHandler; +import org.wso2.carbon.identity.event.handler.notification.PushNotificationHandler; import org.wso2.carbon.identity.event.handler.notification.listener.NotificationEventTenantListener; import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; +import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.stratos.common.listeners.TenantMgtListener; @@ -52,6 +55,7 @@ protected void activate(ComponentContext context) { try { context.getBundleContext().registerService(AbstractEventHandler.class.getName(), new NotificationHandler(), null); context.getBundleContext().registerService(AbstractEventHandler.class.getName(), new DefaultNotificationHandler(), null); + context.getBundleContext().registerService(AbstractEventHandler.class.getName(), new PushNotificationHandler(), null); context.getBundleContext().registerService(TenantMgtListener.class.getName(), new NotificationEventTenantListener(), null); } catch (Throwable e) { log.error("Error occurred while activating Notification Handler Service Component", e); @@ -234,5 +238,45 @@ protected void unsetApplicationManagementService(ApplicationManagementService ap } NotificationHandlerDataHolder.getInstance().setApplicationManagementService(null); } + + @Reference( + name = "org.wso2.carbon.identity.notification.sender.tenant.config", + service = NotificationSenderManagementService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetNotificationSenderManagementService" + ) + protected void setNotificationSenderManagementService( + NotificationSenderManagementService notificationSenderManagementService) { + + NotificationHandlerDataHolder.getInstance() + .setNotificationSenderManagementService(notificationSenderManagementService); + } + + protected void unsetNotificationSenderManagementService( + NotificationSenderManagementService notificationSenderManagementService) { + + NotificationHandlerDataHolder.getInstance().setNotificationSenderManagementService(null); + } + + @Reference( + name = "org.wso2.carbon.identity.notification.push.provider", + service = PushProvider.class, + cardinality = ReferenceCardinality.MULTIPLE, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetPushProvider" + ) + protected void setPushProvider(PushProvider provider) { + + if (log.isDebugEnabled()) { + log.debug("PushProvider: " + provider.getName() + " is registered."); + } + NotificationHandlerDataHolder.getInstance().addPushProvider(provider.getName(), provider); + } + + protected void unsetPushProvider(PushProvider provider) { + + NotificationHandlerDataHolder.getInstance().removePushProvider(provider.getName()); + } } diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/util/NotificationUtil.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/util/NotificationUtil.java index 282b25bf..206e4454 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/util/NotificationUtil.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/util/NotificationUtil.java @@ -771,7 +771,7 @@ public static Notification buildNotification(Event event, Map pl * @return Human-readable name related to the represented organization space. * @throws IdentityEventException Error while resolving organization name. */ - private static String resolveHumanReadableOrganizationName(String tenantDomain) throws IdentityEventException { + public static String resolveHumanReadableOrganizationName(String tenantDomain) throws IdentityEventException { String organizationName = tenantDomain; try { diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/pom.xml b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/pom.xml index 55c79e99..5c86e098 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/pom.xml +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/pom.xml @@ -62,6 +62,10 @@ org.wso2.carbon.identity.framework org.wso2.carbon.identity.core + + org.wso2.carbon.identity.notification.push + org.wso2.carbon.identity.notification.push.provider + org.testng @@ -166,7 +170,11 @@ org.wso2.carbon.identity.organization.management.service.util; version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", org.wso2.carbon.identity.organization.management.service.exception; - version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}" + version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", + + org.wso2.carbon.identity.notification.push.provider; version="${identity.notification.push.version.range}", + org.wso2.carbon.identity.notification.push.provider.exception; version="${identity.notification.push.version.range}", + org.wso2.carbon.identity.notification.push.provider.model; version="${identity.notification.push.version.range}", diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementConstants.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementConstants.java index a9d8ca26..f4cce296 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementConstants.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementConstants.java @@ -37,6 +37,7 @@ private NotificationSenderManagementConstants() { public static final String PUBLISHER_TYPE_PROPERTY = "type"; public static final String DEFAULT_EMAIL_PUBLISHER = "EmailPublisher"; public static final String DEFAULT_SMS_PUBLISHER = "SMSPublisher"; + public static final String DEFAULT_PUSH_PUBLISHER = "PushPublisher"; public static final String PUBLISHER_FILE_EXTENSION = ".xml"; public static final String RESOURCE_NOT_EXISTS_ERROR_CODE = "CONFIGM_00017"; public static final String PLACEHOLDER_IDENTIFIER = "$"; @@ -66,6 +67,9 @@ private NotificationSenderManagementConstants() { public static final String MY_ACCOUNT_SMS_RESOURCE_TYPE = "myaccount"; public static final String MY_ACCOUNT_SMS_RESOURCE_NAME = "myaccount-2FA-config"; + // Push Sender's main properties. + public static final String PUSH_PUBLISHER_TYPE = "push"; + // Constant for eventPublisher file generation. public static final String ROOT_ELEMENT = "eventPublisher"; public static final String PUBLISHER_NAME = "name"; @@ -177,7 +181,20 @@ public enum ErrorMessage { " subscribers."), ERROR_CODE_VALIDATING_CONNECTED_APPS("65016", "Error while validating connected applications.", - "Error while validating connected applications: %s."); + "Error while validating connected applications: %s."), + ERROR_CODE_MATCHING_PUSH_PROVIDER_NOT_FOUND("65017", + "Matching push provider not found in the configured push sender.", + "Matching push provider not found the configured push sender: %s."), + ERROR_CODE_ERROR_PROCESSING_PUSH_SENDER_PROPERTIES("65018", + "Error while processing and storing push sender properties.", + "Error while processing and storing push sender properties: %s."), + ERROR_CODE_ERROR_UPDATING_PUSH_SENDER_PROPERTIES("65019", + "Error while updating push sender properties.", + "Error while updating push sender properties: %s."), + ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER_SECRETS("65020", "Unable to add notification sender.", + "Server encountered an error while adding the notification sender secrets to resource: %s"), + ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER_SECRETS("65021", "Unable to delete notification sender.", + "Server encountered an error while deleting the notification sender secrets from resource: %s"); private final String code; private final String message; diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementService.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementService.java index 99498dfe..10f5b91e 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementService.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.notification.sender.tenant.config; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.dto.PushSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.SMSSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementException; @@ -47,6 +48,18 @@ public interface NotificationSenderManagementService { */ SMSSenderDTO addSMSSender(SMSSenderDTO smsSender) throws NotificationSenderManagementException; + /** + * Create a push sender resource with a resource file. + * + * @param pushSender Push sender post request. + * @return Push sender. + * @throws NotificationSenderManagementException Notification sender management exception. + */ + default PushSenderDTO addPushSender(PushSenderDTO pushSender) throws NotificationSenderManagementException { + + return null; + } + /** * Delete a SMS/Email sender by name. * @@ -90,6 +103,23 @@ default SMSSenderDTO getSMSSender(String senderName, boolean inheritTenantSettin return getSMSSender(senderName); } + /** + * Retrieve the push sender details by name for the current organization with an option to exclude inherited + * tenant settings. + * When the 'inheritTenantSettings' flag is set to true, the method includes configurations from the parent tenant. + * When set to false, it retrieves only the configurations explicitly set for the current tenant. + * + * @param senderName Push sender's name. + * @param inheritTenantSettings Whether to retrieve inherit tenant settings. + * @return null. + * @throws NotificationSenderManagementException Notification sender management exception. + */ + default PushSenderDTO getPushSender(String senderName, boolean inheritTenantSettings) + throws NotificationSenderManagementException { + + return null; + } + /** * Retrieve all email senders of the tenant. * @@ -121,6 +151,21 @@ default List getSMSSenders(boolean inheritTenantSettings) return getSMSSenders(); } + /** + * Retrieves all push senders configured for the current tenant with an option to exclude inherited tenant settings. + * When the 'inheritTenantSettings' flag is set to true, the method includes configurations from the parent tenant. + * When set to false, it retrieves only the configurations explicitly set for the current tenant. + * + * @param inheritTenantSettings Whether to retrieve inherit tenant settings. + * @return Null. + * @throws NotificationSenderManagementException Notification sender management exception. + */ + default List getPushSenders(boolean inheritTenantSettings) + throws NotificationSenderManagementException { + + return null; + } + /** * Update email sender details. * @@ -138,4 +183,16 @@ default List getSMSSenders(boolean inheritTenantSettings) * @throws NotificationSenderManagementException Notification sender management exception. */ SMSSenderDTO updateSMSSender(SMSSenderDTO smsSender) throws NotificationSenderManagementException; + + /** + * Update push sender details. + * + * @param pushSender Push sender's updated configurations. + * @return Updated Push sender. + * @throws NotificationSenderManagementException Notification sender management exception. + */ + default PushSenderDTO updatePushSender(PushSenderDTO pushSender) throws NotificationSenderManagementException { + + return null; + } } diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementServiceImpl.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementServiceImpl.java index 462b9c38..14cc2d4f 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementServiceImpl.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/NotificationSenderManagementServiceImpl.java @@ -38,9 +38,12 @@ import org.wso2.carbon.identity.configuration.mgt.core.model.Resource; import org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile; import org.wso2.carbon.identity.configuration.mgt.core.model.Resources; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; +import org.wso2.carbon.identity.notification.push.provider.exception.PushProviderException; import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage; import org.wso2.carbon.identity.notification.sender.tenant.config.clustering.EventPublisherClusterInvalidationMessage; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.dto.PushSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.SMSSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementClientException; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementException; @@ -72,12 +75,14 @@ import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.CHANNEL_TYPE_PROPERTY; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.DEFAULT_EMAIL_PUBLISHER; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.DEFAULT_HANDLER_NAME; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.DEFAULT_PUSH_PUBLISHER; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.EMAIL_PUBLISHER_TYPE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CHANNEL_TYPE_UPDATE_NOT_ALLOWED; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONFIGURATION_HANDLER_NOT_FOUND; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONFLICT_PUBLISHER; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONNECTED_APPLICATION_EXISTS; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER_SECRETS; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER; @@ -97,6 +102,7 @@ import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.PASSWORD; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.PUBLISHER_RESOURCE_TYPE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.PUBLISHER_TYPE_PROPERTY; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.PUSH_PUBLISHER_TYPE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.RESOURCE_NOT_EXISTS_ERROR_CODE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.SMS_PUBLISHER_TYPE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.SMTP_PORT; @@ -104,8 +110,13 @@ import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.STREAM_NAME; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.STREAM_VERSION; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.USERNAME; +import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.buildPushSenderFromResource; +import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.buildResourceFromPushSender; import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.buildSmsSenderFromResource; +import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.deletePushSenderSecretProperties; import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.generateEmailPublisher; +import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.getPushProvider; +import static org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils.updatePushSenderCredentials; /** * OSGi service of Notification Sender Management operations. @@ -115,9 +126,11 @@ public class NotificationSenderManagementServiceImpl implements NotificationSend private static final Log log = LogFactory.getLog(NotificationSenderManagementServiceImpl.class); public static final int MAX_RETRY_COUNT = 60; public static final String SMS_OTP_AUTHENTICATOR = "sms-otp-authenticator"; + public static final String PUSH_NOTIFICATION_AUTHENTICATOR = "push-notification-authenticator"; static final Map SENDERS = new HashMap() { { put("SMSPublisher", SMS_OTP_AUTHENTICATOR); + put("PushPublisher", PUSH_NOTIFICATION_AUTHENTICATOR); } }; @Override @@ -175,6 +188,32 @@ public SMSSenderDTO addSMSSender(SMSSenderDTO smsSender) throws NotificationSend } } + @Override + public PushSenderDTO addPushSender(PushSenderDTO pushSender) throws NotificationSenderManagementException { + + // Set the default publisher name if name is not defined. + if (StringUtils.isEmpty(pushSender.getName())) { + pushSender.setName(DEFAULT_PUSH_PUBLISHER); + } + Optional resourceOptional = getPublisherResource(pushSender.getName()); + if (resourceOptional.isPresent()) { + throw new NotificationSenderManagementClientException(ERROR_CODE_CONFLICT_PUBLISHER, pushSender.getName()); + } + pushSender.getProperties().put(PUBLISHER_TYPE_PROPERTY, PUSH_PUBLISHER_TYPE); + PushProvider pushProvider = getPushProvider(pushSender); + Resource pushSenderResource = buildResourceFromPushSender(pushSender, pushProvider, true); + try { + Resource addedResource = NotificationSenderTenantConfigDataHolder.getInstance().getConfigurationManager() + .addResource(PUBLISHER_RESOURCE_TYPE, pushSenderResource); + updatePushSenderCredentials(pushSender, pushProvider); + PushSenderDTO addedPushSender = buildPushSenderFromResource(addedResource, false); + return encryptSecretProperties(addedPushSender, pushProvider); + } catch (ConfigurationManagementException e) { + throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER, + pushSender.getName()); + } + } + @Override public void deleteNotificationSender(String senderName) throws NotificationSenderManagementException { @@ -187,6 +226,17 @@ public void deleteNotificationSender(String senderName) throws NotificationSende String channel = getChannelTypeFromResource(resource); if (NotificationSenderTenantConfigDataHolder.getInstance().getConfigurationHandlerMap().containsKey(channel)) { + + // If pushSender, delete push provider secret properties from the secret store. + if (resource.isHasAttribute()) { + for (Attribute attribute : resource.getAttributes()) { + if (PUBLISHER_TYPE_PROPERTY.equals(attribute.getKey()) + && PUSH_PUBLISHER_TYPE.equals(attribute.getValue())) { + deletePushSenderSecretProperties(resource); + } + } + } + NotificationSenderTenantConfigDataHolder.getInstance().getConfigurationHandlerMap() .get(channel).deleteNotificationSender(senderName); } else { @@ -246,6 +296,35 @@ public SMSSenderDTO getSMSSender(String senderName) throws NotificationSenderMan } } + @Override + public PushSenderDTO getPushSender(String senderName, boolean inheritTenantSettings) + throws NotificationSenderManagementException { + + Optional resourceOptional = getPublisherResource(senderName); + if (resourceOptional.isPresent()) { + Resource resource = resourceOptional.get(); + return buildPushSenderFromResource(resource, true); + } + if (!inheritTenantSettings) { + throw new NotificationSenderManagementClientException(ERROR_CODE_PUBLISHER_NOT_EXISTS, senderName); + } + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + try { + if (OrganizationManagementUtil.isOrganization(tenantDomain)) { + resourceOptional = getPublisherResource( + NotificationSenderUtils.getPrimaryTenantId(tenantDomain), senderName); + if (resourceOptional.isPresent()) { + Resource resource = resourceOptional.get(); + return buildPushSenderFromResource(resource, true); + } + } + throw new NotificationSenderManagementClientException(ERROR_CODE_PUBLISHER_NOT_EXISTS, senderName); + } catch (OrganizationManagementException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, + e.getMessage(), e); + } + } + @Override public List getEmailSenders() throws NotificationSenderManagementException { @@ -321,6 +400,31 @@ private List extractSMSSenders(Resources publisherResources) { .collect(Collectors.toList()); } + @Override + public List getPushSenders(boolean inheritTenantSettings) + throws NotificationSenderManagementException { + + try { + Resources publisherResources = getPublisherResources(inheritTenantSettings); + List pushSenders = new ArrayList<>(); + + for (Resource resource : publisherResources.getResources()) { + if (resource.getAttributes().stream().anyMatch( + attribute -> PUBLISHER_TYPE_PROPERTY.equals(attribute.getKey()) + && PUSH_PUBLISHER_TYPE.equals(attribute.getValue()))) { + pushSenders.add(buildPushSenderFromResource(resource, true)); + } + } + return pushSenders; + } catch (ConfigurationManagementException e) { + throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE, + SMS_PUBLISHER_TYPE); + } catch (OrganizationManagementException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, + e.getMessage(), e); + } + } + @Override public EmailSenderDTO updateEmailSender(EmailSenderDTO emailSender) throws NotificationSenderManagementException { @@ -374,6 +478,30 @@ public SMSSenderDTO updateSMSSender(SMSSenderDTO smsSender) throws NotificationS } } + @Override + public PushSenderDTO updatePushSender(PushSenderDTO pushSender) throws NotificationSenderManagementException { + + // Check whether a publisher exists to replace. + Optional resourceOptional = getPublisherResource(pushSender.getName()); + if (!resourceOptional.isPresent()) { + throw new NotificationSenderManagementClientException(ERROR_CODE_NO_RESOURCE_EXISTS, pushSender.getName()); + } + pushSender.getProperties().put(PUBLISHER_TYPE_PROPERTY, PUSH_PUBLISHER_TYPE); + PushProvider pushProvider = getPushProvider(pushSender); + Resource pushSenderResource = buildResourceFromPushSender(pushSender, pushProvider, true); + try { + Resource updatedResource = NotificationSenderTenantConfigDataHolder.getInstance().getConfigurationManager() + .replaceResource(PUBLISHER_RESOURCE_TYPE, pushSenderResource); + updatePushSenderCredentials(pushSender, pushProvider); + PushSenderDTO updatedPushSender = buildPushSenderFromResource(updatedResource, false); + encryptSecretProperties(updatedPushSender, pushProvider); + return pushSender; + } catch (ConfigurationManagementException e) { + throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, + pushSender.getName()); + } + } + private Optional getPublisherResource(int tenantId, String resourceName) throws NotificationSenderManagementException { @@ -733,4 +861,32 @@ private boolean canSenderDelete(String senderName) throws NotificationSenderMana } return true; } + + /** + * Encrypt the secret properties of the push sender. + * + * @param pushSender Push sender object. + * @param pushProvider Push provider object. + * @return Encrypted push sender object. + * @throws NotificationSenderManagementException If an error occurred while encrypting the secret properties. + */ + private PushSenderDTO encryptSecretProperties(PushSenderDTO pushSender, PushProvider pushProvider) + throws NotificationSenderManagementException { + + try { + Map processedProperties = pushProvider.storePushProviderSecretProperties(pushSender); + processedProperties.put(PUBLISHER_TYPE_PROPERTY, PUSH_PUBLISHER_TYPE); + pushSender.setProperties(processedProperties); + Resource pushSenderResource = buildResourceFromPushSender(pushSender, pushProvider, false); + Resource updatedResource = NotificationSenderTenantConfigDataHolder.getInstance().getConfigurationManager() + .replaceResource(PUBLISHER_RESOURCE_TYPE, pushSenderResource); + return buildPushSenderFromResource(updatedResource, true); + } catch (ConfigurationManagementException e) { + throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER_SECRETS, + pushSender.getName()); + } catch (PushProviderException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER_SECRETS, + e.getMessage(), e); + } + } } diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/dto/PushSenderDTO.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/dto/PushSenderDTO.java new file mode 100644 index 00000000..0e805bb8 --- /dev/null +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/dto/PushSenderDTO.java @@ -0,0 +1,55 @@ +package org.wso2.carbon.identity.notification.sender.tenant.config.dto; + +import java.util.HashMap; +import java.util.Map; + +/** + * DTO for Push notification sender. + */ +public class PushSenderDTO { + + private String name; + private String provider; + private String providerId; + private Map properties = new HashMap<>(); + + public String getProviderId() { + + return providerId; + } + + public void setProviderId(String providerId) { + + this.providerId = providerId; + } + + public String getName() { + + return name; + } + + public void setName(String name) { + + this.name = name; + } + + public String getProvider() { + + return provider; + } + + public void setProvider(String provider) { + + this.provider = provider; + } + + public Map getProperties() { + + return properties; + } + + public void setProperties(Map properties) { + + this.properties = properties; + } +} diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/ChannelConfigurationHandler.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/ChannelConfigurationHandler.java index 46bdfc81..d4482a20 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/ChannelConfigurationHandler.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/ChannelConfigurationHandler.java @@ -24,6 +24,7 @@ import org.wso2.carbon.identity.configuration.mgt.core.model.Resource; import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.dto.PushSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.SMSSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementClientException; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementException; @@ -70,6 +71,19 @@ public abstract EmailSenderDTO addEmailSender(EmailSenderDTO emailSender) public abstract SMSSenderDTO addSMSSender(SMSSenderDTO smsSender) throws NotificationSenderManagementException; + /** + * Method holds the implementation of adding the Push sender configurations. + * + * @param pushSender contains the configurations of Push sender. + * @return persisted Push notification sender configuration. + * @throws NotificationSenderManagementException on errors when adding the Push notification sender configurations. + */ + public PushSenderDTO addPushSender(PushSenderDTO pushSender) throws + NotificationSenderManagementException { + + throw new UnsupportedOperationException("Push sender configurations are not supported."); + }; + /** * Method holds the implementation of updating the Email sender configurations. * TODO: Adding this since channel support will be added to email notification senders too. @@ -91,6 +105,20 @@ public abstract EmailSenderDTO updateEmailSender(EmailSenderDTO emailSender) */ public abstract SMSSenderDTO updateSMSSender(SMSSenderDTO smsSender) throws NotificationSenderManagementException; + /** + * Method holds the implementation of updating the Push sender configurations. + * + * @param pushSender contains the configurations of Push sender. + * @return persisted Push notification sender configuration. + * @throws NotificationSenderManagementException on errors when updating the Push notification + * sender configurations. + */ + public PushSenderDTO updatePushSender(PushSenderDTO pushSender) + throws NotificationSenderManagementException { + + throw new UnsupportedOperationException("Push sender configurations are not supported."); + } + /** * Method holds the common implementation of deleting the notification sender configurations. * diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/DefaultChannelConfigurationHandler.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/DefaultChannelConfigurationHandler.java index 06dd900d..f5aa5b7e 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/DefaultChannelConfigurationHandler.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/handlers/DefaultChannelConfigurationHandler.java @@ -37,6 +37,7 @@ import org.wso2.carbon.identity.notification.sender.tenant.config.clustering.EventPublisherClusterDeleteMessage; import org.wso2.carbon.identity.notification.sender.tenant.config.clustering.EventPublisherClusterInvalidationMessage; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.dto.PushSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.SMSSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementClientException; import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementException; @@ -145,6 +146,13 @@ public SMSSenderDTO addSMSSender(SMSSenderDTO smsSender) throws NotificationSend return buildSmsSenderFromResource(smsSenderResource); } + @Override + public PushSenderDTO addPushSender(PushSenderDTO pushSender) throws + NotificationSenderManagementException { + + throw new IllegalArgumentException("Channel support for the push notifications is not implemented."); + } + @Override public void deleteNotificationSender(String senderName) throws NotificationSenderManagementException { @@ -195,6 +203,12 @@ public SMSSenderDTO updateSMSSender(SMSSenderDTO smsSender) throws NotificationS return buildSmsSenderFromResource(smsSenderResource); } + @Override + public PushSenderDTO updatePushSender(PushSenderDTO pushSender) throws NotificationSenderManagementException { + + throw new IllegalArgumentException("Channel support for the push notifications is not implemented."); + } + private void validateSMSSender(SMSSenderDTO smsSender) throws NotificationSenderManagementClientException { SMSProviderPayloadTemplateManager smsProviderPayloadTemplateManager = diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigDataHolder.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigDataHolder.java index a9233f86..71efe174 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigDataHolder.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigDataHolder.java @@ -23,6 +23,7 @@ import org.wso2.carbon.event.publisher.core.EventPublisherService; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; import org.wso2.carbon.identity.notification.sender.tenant.config.handlers.ChannelConfigurationHandler; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.identity.tenant.resource.manager.core.ResourceManager; @@ -45,6 +46,7 @@ public class NotificationSenderTenantConfigDataHolder { Map configurationHandlerMap = new HashMap<>(); private ApplicationManagementService applicationManagementService = null; private OrganizationManager organizationManager = null; + private final Map pushNotificationProviders = new HashMap<>(); private NotificationSenderTenantConfigDataHolder() { } @@ -138,4 +140,36 @@ public OrganizationManager getOrganizationManager() { return organizationManager; } + + /** + * Add a push notification provider. + * + * @param providerName Name of the provider. + * @param provider {@link org.wso2.carbon.identity.notification.push.provider.PushProvider} instance. + */ + public void addPushProvider(String providerName, PushProvider provider) { + + pushNotificationProviders.put(providerName, provider); + } + + /** + * Remove a push notification provider. + * + * @param providerName Name of the provider. + */ + public void removePushProvider(String providerName) { + + pushNotificationProviders.remove(providerName); + } + + /** + * Get a push notification provider. + * + * @param providerName Name of the provider. + * @return {@link org.wso2.carbon.identity.notification.push.provider.PushProvider} instance. + */ + public PushProvider getPushProvider(String providerName) { + + return pushNotificationProviders.get(providerName); + } } diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigServiceDS.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigServiceDS.java index 8b21ed05..d8a89808 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigServiceDS.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/internal/NotificationSenderTenantConfigServiceDS.java @@ -31,6 +31,7 @@ import org.wso2.carbon.event.publisher.core.EventPublisherService; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService; import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementServiceImpl; import org.wso2.carbon.identity.notification.sender.tenant.config.handlers.ChannelConfigurationHandler; @@ -215,4 +216,24 @@ protected void unsetApplicationManagementService(ApplicationManagementService ap NotificationSenderTenantConfigDataHolder.getInstance().setApplicationManagementService(null); } + + @Reference( + name = "org.wso2.carbon.identity.notification.push.provider", + service = PushProvider.class, + cardinality = ReferenceCardinality.MULTIPLE, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetPushProvider" + ) + protected void setPushProvider(PushProvider provider) { + + if (log.isDebugEnabled()) { + log.debug("PushProvider: " + provider.getName() + " is registered."); + } + NotificationSenderTenantConfigDataHolder.getInstance().addPushProvider(provider.getName(), provider); + } + + protected void unsetPushProvider(PushProvider provider) { + + NotificationSenderTenantConfigDataHolder.getInstance().removePushProvider(provider.getName()); + } } diff --git a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/utils/NotificationSenderUtils.java b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/utils/NotificationSenderUtils.java index 6509451c..5ed0d3f4 100644 --- a/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/utils/NotificationSenderUtils.java +++ b/components/notification-sender-config/org.wso2.carbon.identity.notification.sender.tenant.config/src/main/java/org/wso2/carbon/identity/notification/sender/tenant/config/utils/NotificationSenderUtils.java @@ -25,8 +25,12 @@ import org.wso2.carbon.identity.configuration.mgt.core.model.Attribute; import org.wso2.carbon.identity.configuration.mgt.core.model.Resource; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.notification.push.provider.PushProvider; +import org.wso2.carbon.identity.notification.push.provider.exception.PushProviderException; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.dto.PushSenderDTO; import org.wso2.carbon.identity.notification.sender.tenant.config.dto.SMSSenderDTO; +import org.wso2.carbon.identity.notification.sender.tenant.config.exception.NotificationSenderManagementServerException; import org.wso2.carbon.identity.notification.sender.tenant.config.internal.NotificationSenderTenantConfigDataHolder; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; @@ -35,6 +39,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -67,6 +72,10 @@ import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.EMAIL_TYPE_PROPERTY; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.EMAIL_TYPE_VALUE; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ENABLE; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER_SECRETS; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_PROCESSING_PUSH_SENDER_PROPERTIES; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_PUSH_SENDER_PROPERTIES; +import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_MATCHING_PUSH_PROVIDER_NOT_FOUND; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.FROM; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.HTTP_URL_PROPERTY; import static org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.INLINE; @@ -421,6 +430,130 @@ public static SMSSenderDTO buildSmsSenderFromResource(Resource resource) { return smsSender; } + /** + * Build Resource by Push sender DTO. + * + * @param pushSender PushSender DTO. + * @return Resource object. + */ + public static Resource buildResourceFromPushSender(PushSenderDTO pushSender, PushProvider pushProvider, + boolean isProcessProperties) + throws NotificationSenderManagementServerException { + + Resource resource = new Resource(); + resource.setResourceName(pushSender.getName()); + try { + Map pushSenderAttributes; + if (isProcessProperties) { + pushSenderAttributes = pushProvider.preProcessProperties(pushSender); + } else { + pushSenderAttributes = pushSender.getProperties(); + } + pushSenderAttributes.put(PROVIDER, pushSender.getProvider()); + List resourceAttributes = + pushSenderAttributes.entrySet().stream() + .filter(attribute -> attribute.getValue() != null && !"null".equals(attribute.getValue())) + .map(attribute -> new Attribute(attribute.getKey(), attribute.getValue())) + .collect(Collectors.toList()); + resource.setAttributes(resourceAttributes); + return resource; + } catch (PushProviderException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_ERROR_PROCESSING_PUSH_SENDER_PROPERTIES, + pushSender.getName(), e); + } + } + + /** + * Build a push sender response from push sender's resource object. + * + * @param resource Push sender resource object. + * @return Push sender response. + */ + public static PushSenderDTO buildPushSenderFromResource(Resource resource, boolean isProcessProperties) + throws NotificationSenderManagementServerException { + + PushSenderDTO pushSender = new PushSenderDTO(); + pushSender.setName(resource.getResourceName()); + pushSender.setProviderId(resource.getResourceId()); + Map attributesMap = + resource.getAttributes().stream() + .filter(attribute -> !(INTERNAL_PROPERTIES.contains(attribute.getKey()))) + .collect(Collectors.toMap(Attribute::getKey, Attribute::getValue)); + attributesMap.forEach((key, value) -> { + if (key.equals(PROVIDER)) { + pushSender.setProvider(value); + } else { + pushSender.getProperties().put(key, value); + } + }); + + if (!isProcessProperties) { + return pushSender; + } + + try { + PushProvider provider = getPushProvider(pushSender); + pushSender.setProperties(provider.retrievePushProviderSecretProperties(pushSender)); + pushSender.setProperties(provider.postProcessProperties(pushSender)); + } catch (PushProviderException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_ERROR_PROCESSING_PUSH_SENDER_PROPERTIES, + pushSender.getName(), e); + } + return pushSender; + } + + /** + * Update push sender credentials. + * + * @param pushSender Push sender DTO. + */ + public static void updatePushSenderCredentials(PushSenderDTO pushSender, PushProvider pushProvider) + throws NotificationSenderManagementServerException { + + try { + pushProvider.updateCredentials(pushSender); + } catch (PushProviderException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_ERROR_UPDATING_PUSH_SENDER_PROPERTIES, + pushSender.getName(), e); + } + } + + /** + * Get the push provider for the given push sender. + * + * @param pushSender Push sender DTO. + * @return Push provider. + */ + public static PushProvider getPushProvider(PushSenderDTO pushSender) + throws NotificationSenderManagementServerException { + + PushProvider provider = NotificationSenderTenantConfigDataHolder.getInstance() + .getPushProvider(pushSender.getProvider()); + if (provider == null) { + throw new NotificationSenderManagementServerException(ERROR_CODE_MATCHING_PUSH_PROVIDER_NOT_FOUND, + pushSender.getName()); + } + return provider; + } + + /** + * Delete push sender secret properties. + * + * @param resource Push sender resource object. + */ + public static void deletePushSenderSecretProperties(Resource resource) + throws NotificationSenderManagementServerException { + + try { + PushSenderDTO pushSender = buildPushSenderFromResource(resource, false); + PushProvider pushProvider = getPushProvider(pushSender); + pushProvider.deletePushProviderSecretProperties(pushSender); + } catch (PushProviderException e) { + throw new NotificationSenderManagementServerException(ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER_SECRETS, + e.getMessage(), e); + } + } + /** * Get the primary tenant id of the given tenant domain. * diff --git a/pom.xml b/pom.xml index d599eb71..7eea69ed 100644 --- a/pom.xml +++ b/pom.xml @@ -252,6 +252,11 @@ org.wso2.carbon.identity.branding.preference.management.core ${identity.branding.preference.management.version} + + org.wso2.carbon.identity.notification.push + org.wso2.carbon.identity.notification.push.provider + ${identity.notification.push.version} + commons-lang.wso2 commons-lang @@ -490,6 +495,9 @@ 1.1.5 [1.0.1, 2.0.0) + 1.0.0-SNAPSHOT + [1.0.0, 2.0.0) + 1.6.1-wso2v38 [1.6.1-wso2v38, 2.0.0) From 5c34c97ea126c51e153693231cb60df6b7b583e0 Mon Sep 17 00:00:00 2001 From: ZiyamSanthosh Date: Thu, 28 Nov 2024 11:11:29 +0530 Subject: [PATCH 2/2] Facilitate push notification to include IP address of the device initiating push notifications --- .../event/handler/notification/NotificationConstants.java | 2 +- .../event/handler/notification/PushNotificationHandler.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java index 1cb9de9b..30f73908 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java @@ -133,7 +133,7 @@ public static class PushNotification { public static final String DEVICE_TOKEN = "deviceToken"; public static final String CHALLENGE = "challenge"; public static final String NUMBER_CHALLENGE = "numberChallenge"; - public static final String HOST_NAME = "hostName"; + public static final String IP_ADDRESS = "ipAddress"; public static final String REQUEST_DEVICE_OS = "deviceOS"; public static final String REQUEST_DEVICE_BROWSER = "browser"; } diff --git a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java index f64cd6e6..b62f05d0 100644 --- a/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java +++ b/components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java @@ -31,7 +31,7 @@ import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.EmailNotification.ORGANIZATION_NAME_PLACEHOLDER; import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.CHALLENGE; import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.DEVICE_TOKEN; -import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.HOST_NAME; +import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.IP_ADDRESS; import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.NOTIFICATION_PROVIDER; import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.NOTIFICATION_SCENARIO; import static org.wso2.carbon.identity.event.handler.notification.NotificationConstants.PushNotification.NUMBER_CHALLENGE; @@ -179,7 +179,7 @@ private PushNotificationData buildPushNotificationData(Event event) throws Ident pushNotificationData.setNumberChallenge((String) eventProperties.get(NUMBER_CHALLENGE)); // Add system related data. - pushNotificationData.setHostName((String) eventProperties.get(HOST_NAME)); + pushNotificationData.setHostName((String) eventProperties.get(IP_ADDRESS)); pushNotificationData.setDeviceOS((String) eventProperties.get(REQUEST_DEVICE_OS)); pushNotificationData.setBrowser((String) eventProperties.get(REQUEST_DEVICE_BROWSER));