From b143dc05d5be212b0aedf42138966b4a9684517a Mon Sep 17 00:00:00 2001 From: Lakshan Banneheke <62496951+Lakshan-Banneheke@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:44:47 +0530 Subject: [PATCH] Fix for building identity-event properties related to sms publisher (#5485) --- .../event/IdentityEventConfigBuilder.java | 2 +- .../identity/event/IdentityEventUtils.java | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventConfigBuilder.java b/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventConfigBuilder.java index 05508cde8a4c..c6483b78dad8 100644 --- a/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventConfigBuilder.java +++ b/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventConfigBuilder.java @@ -143,7 +143,7 @@ private Properties loadProperties() throws IdentityEventException { * Build and store per module configuration objects */ private void build() { - Properties moduleNames = IdentityEventUtils.getSubProperties("module.name", notificationMgtConfigProperties); + Properties moduleNames = IdentityEventUtils.getModuleNames("module.name", notificationMgtConfigProperties); Enumeration propertyNames = moduleNames.propertyNames(); // Iterate through events and build event objects while (propertyNames.hasMoreElements()) { diff --git a/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventUtils.java b/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventUtils.java index 6d8a810aacf7..c4126318e34e 100644 --- a/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventUtils.java +++ b/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/IdentityEventUtils.java @@ -68,7 +68,7 @@ public static Properties getPropertiesWithPrefix(String prefix, Properties prope } /** - * Returns a sub set of properties which has the given prefix key. ie properties which has numbers at the end + * Returns a sub set of properties which has the given prefix key. * * @param prefix Prefix of the key * @param properties Set of properties which needs be filtered for the given prefix @@ -81,9 +81,33 @@ public static Properties getSubProperties(String prefix, Properties properties) throw new IllegalArgumentException("Prefix and Properties should not be null to get sub properties"); } + int i = 1; + Properties subProperties = new Properties(); + while (properties.getProperty(prefix + "." + i) != null) { + // Remove from original properties to hold property schema. ie need to get the set of properties which + // remains after consuming all required specific properties. + subProperties.put(prefix + "." + i, properties.remove(prefix + "." + i++)); + } + return subProperties; + } + + /** + * Returns the module names using a given prefix key. ie properties which has numbers at the end. + * + * @param prefix Prefix of the properties used to define module names. + * @param properties Set of properties which needs be filtered for the given prefix. + * @return Map of module names. + */ + public static Properties getModuleNames(String prefix, Properties properties) { + + // Stop proceeding if required arguments are not present. + if (StringUtils.isEmpty(prefix) || properties == null) { + throw new IllegalArgumentException("Prefix and Properties should not be null to get sub properties"); + } + Properties subProperties = new Properties(); // Remove from original properties to hold property schema. ie need to get the set of properties which - // remains after consuming all required specific properties + // remains after consuming all required specific properties. subProperties.putAll(getPropertiesWithPrefix(prefix, properties)); return subProperties; }