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);
}
}
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);
}
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);
}
}
}
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);
}
}
}
}
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));
}
Aggregations