From 1b336c0d3454860f672a3c1f459fe8324a007c87 Mon Sep 17 00:00:00 2001 From: Sahan Dilshan Date: Wed, 9 Aug 2023 17:16:00 +0530 Subject: [PATCH] Fix the osgi bundle activation --- .../custom-identity-event-handler/README.md | 2 +- .../custom-identity-event-handler/pom.xml | 4 ++-- ...gistrationCustomEventHandlerComponent.java | 21 ++++++++++++------- ...istrationCustomEventHandlerDataHolder.java | 3 ++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/event-handler/custom-identity-event-handler/README.md b/event-handler/custom-identity-event-handler/README.md index f183c956d..a839d9d32 100644 --- a/event-handler/custom-identity-event-handler/README.md +++ b/event-handler/custom-identity-event-handler/README.md @@ -10,6 +10,6 @@ Steps [[event_handler]] name= "customUserRegistration" -subscriptions =["PRE_ADD_USER, POST_ADD_USER"] +subscriptions =["PRE_ADD_USER"] ``` diff --git a/event-handler/custom-identity-event-handler/pom.xml b/event-handler/custom-identity-event-handler/pom.xml index 408adfae8..ee13e4022 100644 --- a/event-handler/custom-identity-event-handler/pom.xml +++ b/event-handler/custom-identity-event-handler/pom.xml @@ -64,7 +64,7 @@ org.apache.felix maven-bundle-plugin - ${maven.bundle.plugin.version} + 2.4.0 true @@ -76,7 +76,7 @@ !org.wso2.carbon.identity.customhandler.internal, - org.wso2.carbon.identity.customhandler.*;version="1.0.0", + org.wso2.carbon.identity.customhandler.*;version="${project.version}", org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}", diff --git a/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerComponent.java b/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerComponent.java index f1d0566dd..17873345d 100644 --- a/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerComponent.java +++ b/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerComponent.java @@ -22,22 +22,22 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.*; import org.wso2.carbon.identity.event.handler.AbstractEventHandler; import org.wso2.carbon.identity.customhandler.handler.UserRegistrationCustomEventHandler; import org.wso2.carbon.user.core.service.RealmService; -/** - * @scr.component name="org.wso2.carbon.identity.customhandler.internal.UserRegistrationCustomEventHandlerComponent" immediate="true" - * @scr.reference name="realm.service" - * interface="org.wso2.carbon.user.core.service.RealmService" cardinality="1..1" - * policy="dynamic" bind="setRealmService" unbind="unsetRealmService" - */ +@Component( + name = "org.wso2.carbon.identity.customhandler.internal.UserRegistrationCustomEventHandlerComponent", + immediate = true +) public class UserRegistrationCustomEventHandlerComponent { private static Log log = LogFactory.getLog(UserRegistrationCustomEventHandlerComponent.class); - private UserRegistrationCustomEventHandlerDataHolder dataHolder = UserRegistrationCustomEventHandlerDataHolder + private final UserRegistrationCustomEventHandlerDataHolder dataHolder = UserRegistrationCustomEventHandlerDataHolder .getInstance(); + @Activate protected void activate(ComponentContext context) { try { BundleContext bundleContext = context.getBundleContext(); @@ -48,12 +48,19 @@ protected void activate(ComponentContext context) { } } + @Deactivate protected void deactivate(ComponentContext context) { if (log.isDebugEnabled()) { log.debug("custom self registration handler is de-activated"); } } + @Reference( + name = "RealmService", + service = org.wso2.carbon.user.core.service.RealmService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetRealmService") protected void setRealmService(RealmService realmService) { if (log.isDebugEnabled()) { log.debug("Setting the Realm Service"); diff --git a/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerDataHolder.java b/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerDataHolder.java index d9638241f..0ff7ec0bd 100644 --- a/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerDataHolder.java +++ b/event-handler/custom-identity-event-handler/src/main/java/org/wso2/carbon/identity/customhandler/internal/UserRegistrationCustomEventHandlerDataHolder.java @@ -22,7 +22,8 @@ public class UserRegistrationCustomEventHandlerDataHolder { - private static UserRegistrationCustomEventHandlerDataHolder instance = new UserRegistrationCustomEventHandlerDataHolder(); + private static final UserRegistrationCustomEventHandlerDataHolder instance = + new UserRegistrationCustomEventHandlerDataHolder(); private RealmService realmService; public static UserRegistrationCustomEventHandlerDataHolder getInstance() {