Search in sources :

Example 1 with AbstractEventHandler

use of org.wso2.carbon.identity.event.handler.AbstractEventHandler in project carbon-identity-framework by wso2.

the class WorkflowMgtServiceComponent method activate.

@Activate
protected void activate(ComponentContext context) {
    try {
        BundleContext bundleContext = context.getBundleContext();
        WorkflowManagementService workflowService = new WorkflowManagementServiceImpl();
        bundleContext.registerService(WorkflowManagementService.class, workflowService, null);
        AbstractEventHandler workflowPendingUserAuthnHandler = new WorkflowPendingUserAuthnHandler();
        bundleContext.registerService(AbstractEventHandler.class, workflowPendingUserAuthnHandler, null);
        WorkflowServiceDataHolder.getInstance().setWorkflowService(workflowService);
        WorkflowServiceDataHolder.getInstance().setBundleContext(bundleContext);
        ServiceRegistration serviceRegistration = context.getBundleContext().registerService(WorkflowListener.class.getName(), new WorkflowAuditLogger(), null);
        context.getBundleContext().registerService(WorkflowExecutorManagerListener.class.getName(), new WorkflowExecutorAuditLogger(), null);
        context.getBundleContext().registerService(TenantMgtListener.class.getName(), new WorkflowTenantMgtListener(), null);
        if (serviceRegistration != null) {
            if (log.isDebugEnabled()) {
                log.debug("WorkflowAuditLogger registered.");
            }
        } else {
            log.error("Workflow Audit Logger could not be registered.");
        }
        if (System.getProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID) == null) {
            System.setProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance().getFirstProperty(WFConstant.KEYSTORE_CARBON_CONFIG_PATH));
        }
        if (System.getProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID) == null) {
            System.setProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance().getFirstProperty(WFConstant.KEYSTORE_PASSWORD_CARBON_CONFIG_PATH));
        }
    } catch (Throwable e) {
        log.error("Failed to start the WorkflowMgtServiceComponent", e);
    }
}
Also used : WorkflowAuditLogger(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowAuditLogger) WorkflowPendingUserAuthnHandler(org.wso2.carbon.identity.workflow.mgt.handler.WorkflowPendingUserAuthnHandler) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) WorkflowManagementService(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService) TenantMgtListener(org.wso2.carbon.stratos.common.listeners.TenantMgtListener) WorkflowTenantMgtListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowTenantMgtListener) WorkflowTenantMgtListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowTenantMgtListener) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) WorkflowExecutorManagerListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener) WorkflowExecutorAuditLogger(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorAuditLogger) BundleContext(org.osgi.framework.BundleContext) WorkflowManagementServiceImpl(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl) ServiceRegistration(org.osgi.framework.ServiceRegistration) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with AbstractEventHandler

use of org.wso2.carbon.identity.event.handler.AbstractEventHandler in project carbon-identity-framework by wso2.

the class IdentityEventServiceComponent method registerEventHandler.

@Reference(name = "event.handler", service = org.wso2.carbon.identity.event.handler.AbstractEventHandler.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "unRegisterEventHandler")
protected void registerEventHandler(AbstractEventHandler eventHandler) {
    String handlerName = eventHandler.getName();
    try {
        eventHandler.init(IdentityEventConfigBuilder.getInstance().getModuleConfigurations(handlerName));
    } catch (IdentityEventException | IdentityRuntimeException e) {
        log.warn("Properties for " + handlerName + " is not configured. This event handler will not be activated");
    }
    eventHandlerList.add(eventHandler);
    MessageHandlerComparator messageHandlerComparator = new MessageHandlerComparator(null);
    Collections.sort(eventHandlerList, messageHandlerComparator);
}
Also used : IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) MessageHandlerComparator(org.wso2.carbon.identity.core.handler.MessageHandlerComparator) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException) Reference(org.osgi.service.component.annotations.Reference)

Example 3 with AbstractEventHandler

use of org.wso2.carbon.identity.event.handler.AbstractEventHandler in project carbon-identity-framework by wso2.

the class EventDistributionTask method run.

@Override
public void run() {
    running = true;
    // Run forever until stop the bundle. Will stop in eventQueue.take()
    while (running) {
        try {
            final Event event = eventQueue.take();
            IdentityEventMessageContext eventContext = new IdentityEventMessageContext(event);
            for (final AbstractEventHandler module : notificationSendingModules) {
                // If the module is subscribed to the event, module will be executed.
                if (module.isEnabled(eventContext)) {
                    // Create a runnable and submit to the thread pool for sending message.
                    Runnable msgSender = new Runnable() {

                        @Override
                        public void run() {
                            if (log.isDebugEnabled()) {
                                log.debug("Executing " + module.getName() + " on event" + event.getEventName());
                            }
                            try {
                                module.handleEvent(event);
                            } catch (IdentityEventException e) {
                                log.error("Error while invoking notification sending module " + module.getName(), e);
                            }
                        }
                    };
                    IdentityEventServiceDataHolder.getInstance().getThreadPool().submit(msgSender);
                }
            }
        } catch (InterruptedException e) {
            log.error("Error while picking up event from event queue", e);
        }
    }
}
Also used : AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) Event(org.wso2.carbon.identity.event.event.Event) IdentityEventMessageContext(org.wso2.carbon.identity.event.bean.IdentityEventMessageContext)

Example 4 with AbstractEventHandler

use of org.wso2.carbon.identity.event.handler.AbstractEventHandler in project carbon-identity-framework by wso2.

the class IdentityEventServiceImpl method handleEvent.

@Override
public void handleEvent(Event event) throws IdentityEventException {
    List<AbstractEventHandler> eventHandlerList = IdentityEventServiceComponent.eventHandlerList;
    IdentityEventMessageContext eventContext = new IdentityEventMessageContext(event);
    for (final AbstractEventHandler handler : eventHandlerList) {
        if (handler.canHandle(eventContext)) {
            if (handler.isAssociationAsync(event.getEventName())) {
                eventDistributionTask.addEventToQueue(event);
            } else {
                handler.handleEvent(event);
            }
        }
    }
}
Also used : AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) IdentityEventMessageContext(org.wso2.carbon.identity.event.bean.IdentityEventMessageContext)

Example 5 with AbstractEventHandler

use of org.wso2.carbon.identity.event.handler.AbstractEventHandler in project carbon-identity-framework by wso2.

the class IdentityEventServiceImplTest method testHandleEvent.

@Test
public void testHandleEvent() throws IdentityEventException {
    Event event = new Event("eventName");
    event.addEventProperty("value", "value");
    abstractEventHandler = mock(AbstractEventHandler.class);
    doReturn(true).when(abstractEventHandler).canHandle(any(MessageContext.class));
    doReturn(true).when(abstractEventHandler).isAssociationAsync(anyString());
    List list = new ArrayList();
    list.add(abstractEventHandler);
    IdentityEventServiceComponent.eventHandlerList = list;
    List abstractEventHandlerList = new ArrayList();
    abstractEventHandlerList.add(abstractEventHandler);
    IdentityEventService identityEventService = new IdentityEventServiceImpl(abstractEventHandlerList, 1);
    identityEventService.handleEvent(event);
    Mockito.verify(abstractEventHandler).canHandle(any(MessageContext.class));
}
Also used : AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) ArrayList(java.util.ArrayList) Event(org.wso2.carbon.identity.event.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) MessageContext(org.wso2.carbon.identity.core.bean.context.MessageContext) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Aggregations

AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)4 IdentityEventMessageContext (org.wso2.carbon.identity.event.bean.IdentityEventMessageContext)2 Event (org.wso2.carbon.identity.event.event.Event)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Activate (org.osgi.service.component.annotations.Activate)1 Reference (org.osgi.service.component.annotations.Reference)1 Test (org.testng.annotations.Test)1 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)1 MessageContext (org.wso2.carbon.identity.core.bean.context.MessageContext)1 MessageHandlerComparator (org.wso2.carbon.identity.core.handler.MessageHandlerComparator)1 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)1 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)1 WorkflowManagementService (org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService)1 WorkflowManagementServiceImpl (org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl)1 WorkflowPendingUserAuthnHandler (org.wso2.carbon.identity.workflow.mgt.handler.WorkflowPendingUserAuthnHandler)1 WorkflowAuditLogger (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowAuditLogger)1 WorkflowExecutorAuditLogger (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorAuditLogger)1