diff --git a/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/constant/Constants.java b/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/constant/Constants.java index b779924..173041c 100644 --- a/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/constant/Constants.java +++ b/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/constant/Constants.java @@ -25,6 +25,7 @@ public class Constants { public static final String EVENT_SCHEMA_TYPE_WSO2 = "WSO2"; public static final String LOGIN_EVENT_HOOK_NAME = "LoginEventHook"; + public static final String LOGIN_EVENT_HOOK_ENABLED = "LoginEventHook.enable"; public static final String ENABLE = "enable"; public static final String SP_TO_CARBON_CLAIM_MAPPING = "SP_TO_CARBON_CLAIM_MAPPING"; diff --git a/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/internal/EventHookHandlerServiceComponent.java b/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/internal/EventHookHandlerServiceComponent.java index 9651a59..ab72bd8 100644 --- a/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/internal/EventHookHandlerServiceComponent.java +++ b/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/internal/EventHookHandlerServiceComponent.java @@ -34,6 +34,8 @@ import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager; import org.wso2.carbon.identity.event.handler.AbstractEventHandler; import org.wso2.identity.event.common.publisher.EventPublisherService; +import org.wso2.identity.webhook.common.event.handler.constant.Constants; +import org.wso2.identity.webhook.common.event.handler.util.EventHookHandlerUtils; /** * WSO2 Event Handler service component class. @@ -50,11 +52,14 @@ protected void activate(ComponentContext context) { try { log.debug("Event Handler is activated."); + String isLoginEventHandlerEnabled = EventHookHandlerUtils + .getIdentityEventProperty(Constants.LOGIN_EVENT_HOOK_NAME, Constants.LOGIN_EVENT_HOOK_ENABLED); BundleContext bundleContext = context.getBundleContext(); - LoginEventHookHandler loginEventHookHandler = new LoginEventHookHandler(); - if (loginEventHookHandler.isLoginEventHandlerEnabled()) { + if (isLoginEventHandlerEnabled.equalsIgnoreCase(Boolean.TRUE.toString())) { bundleContext.registerService(AbstractEventHandler.class.getName(), - loginEventHookHandler, null); + new LoginEventHookHandler(), null); + } else { + log.error("Login Event Handler is not enabled."); } } catch (Exception e) { log.error("Error while activating event handler.", e); diff --git a/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/util/EventHookHandlerUtils.java b/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/util/EventHookHandlerUtils.java index c2f0656..dbf9bd2 100644 --- a/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/util/EventHookHandlerUtils.java +++ b/components/org.wso2.identity.webhook.common.event.handler/src/main/java/org/wso2/identity/webhook/common/event/handler/util/EventHookHandlerUtils.java @@ -33,8 +33,10 @@ import org.wso2.carbon.identity.application.common.model.User; import org.wso2.carbon.identity.core.ServiceURLBuilder; import org.wso2.carbon.identity.core.URLBuilderException; +import org.wso2.carbon.identity.event.IdentityEventConfigBuilder; import org.wso2.carbon.identity.event.IdentityEventException; import org.wso2.carbon.identity.event.IdentityEventServerException; +import org.wso2.carbon.identity.event.bean.ModuleConfiguration; import org.wso2.carbon.identity.event.event.Event; import org.wso2.identity.event.common.publisher.model.EventContext; import org.wso2.identity.event.common.publisher.model.EventPayload; @@ -59,6 +61,30 @@ public class EventHookHandlerUtils { private static final Log log = LogFactory.getLog(EventHookHandlerUtils.class); + /** + * Get the identity property specified in identity-event.properties + * + * @param moduleName The name of the module which the property belongs to + * @param propertyName The name of the property which should be fetched + * @return The required property + */ + public static String getIdentityEventProperty(String moduleName, String propertyName) { + + // Retrieving properties set in identity event properties + String propertyValue = null; + try { + ModuleConfiguration moduleConfiguration = IdentityEventConfigBuilder.getInstance() + .getModuleConfigurations(moduleName); + + if (moduleConfiguration != null) { + propertyValue = moduleConfiguration.getModuleProperties().getProperty(propertyName); + } + } catch (IdentityEventException e) { + log.error("An error occurred while retrieving module properties because " + e.getMessage(), e); + } + return propertyValue; + } + /** * Retrieve event uri. * @@ -124,8 +150,7 @@ public static EventData buildEventDataProvider(Event event) { * @param eventUri Event URI. * @return Audience string. */ - public static SecurityEventTokenPayload buildSecurityEventToken(EventPayload eventPayload, - AuthenticationContext context, String eventUri) + public static SecurityEventTokenPayload buildSecurityEventToken(EventPayload eventPayload, String eventUri) throws IdentityEventException { if (eventPayload == null) {