use of org.wso2.carbon.identity.notification.mgt.NotificationManagementException 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 PublisherEvent event = eventQueue.take();
for (final NotificationSendingModule module : notificationSendingModules) {
// If the module is subscribed to the event, module will be executed.
try {
if (module.isSubscribed(event)) {
// 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.getModuleName() + " on event" + event.getEventName());
}
try {
module.sendMessage(event);
} catch (NotificationManagementException e) {
log.error("Error while invoking notification sending module " + module.getModuleName(), e);
}
}
};
NotificationManagementServiceDataHolder.getInstance().getThreadPool().submit(msgSender);
}
} catch (NotificationManagementException e) {
log.error("Error while getting subscription status from notification module " + module.getModuleName(), e);
}
}
} catch (InterruptedException e) {
log.error("Error while picking up event from event queue", e);
}
}
}
use of org.wso2.carbon.identity.notification.mgt.NotificationManagementException in project carbon-identity-framework by wso2.
the class NotificationManagementServiceComponent method addNotificationSendingModule.
/**
* Will register message sending modules dynamically. This method is used to bind the notification sending
* modules in to msg mgt component
*
* @param module MessageSendingModule
*/
@Reference(name = "ldap.tenant.manager.listener.service", service = NotificationSendingModule.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "removeNotificationSendingModule")
protected void addNotificationSendingModule(NotificationSendingModule module) throws MessageRemovedException {
ModuleConfiguration moduleConfiguration;
if (StringUtils.isEmpty(module.getModuleName())) {
if (log.isDebugEnabled()) {
log.debug("Cannot register module without a valid module name");
}
return;
}
if (log.isDebugEnabled()) {
log.debug("Registering a message sending module " + module.getModuleName());
}
if (configBuilder != null) {
moduleConfiguration = configBuilder.getModuleConfigurations(module.getModuleName());
} else {
moduleConfiguration = new ModuleConfiguration();
}
try {
module.init(moduleConfiguration);
notificationSendingModules.add(module);
} catch (NotificationManagementException e) {
log.error("Error while initializing Notification sending module " + module.getModuleName(), e);
}
}
use of org.wso2.carbon.identity.notification.mgt.NotificationManagementException in project carbon-identity-framework by wso2.
the class UserOperationsNotificationListener method sendNotification.
/**
* This function builds the required configuration object for Notification sender and pass it
* to the notification sender with the relevant event.
*
* @param operation Type or operation took place in user operation listener
* @param username username of the subjected user for attribute change
*/
private void sendNotification(String operation, String username) {
NotificationSender notificationSender = IdentityMgtServiceComponent.getNotificationSender();
if (notificationSender != null) {
try {
PublisherEvent event = new PublisherEvent(eventName);
event.addEventProperty(operationLabel, operation);
event.addEventProperty(usernameLabel, username);
if (log.isDebugEnabled()) {
log.debug("Invoking notification sender");
}
notificationSender.invoke(event);
} catch (NotificationManagementException e) {
log.error("Error while sending notifications on user operations", e);
}
} else {
log.error("No registered notification sender found. Notification sending aborted");
}
}
use of org.wso2.carbon.identity.notification.mgt.NotificationManagementException in project carbon-identity-framework by wso2.
the class EntitlementNotificationExtension method handle.
/**
* handler will decide the process depending on the status in status holder
*
* @param about indicates what is related with this admin status action
* @param statusHolder <code>StatusHolder</code>
* @throws EntitlementException
*/
@Override
public void handle(String about, StatusHolder statusHolder) throws EntitlementException {
if (!EntitlementConstants.Status.ABOUT_POLICY.equalsIgnoreCase(about)) {
return;
}
String action = null;
String typeOfAction = statusHolder.getType();
// If papUpdate notifications are enabled through entitlement.properties
if (papUpdate) {
if (EntitlementConstants.StatusTypes.UPDATE_POLICY.equals(typeOfAction)) {
action = NotificationConstants.ACTION_LABEL_UPDATE;
} else if (EntitlementConstants.StatusTypes.DELETE_POLICY.equals(typeOfAction)) {
action = NotificationConstants.ACTION_LABEL_DELETE;
} else if (EntitlementConstants.StatusTypes.ADD_POLICY.equals(typeOfAction)) {
action = NotificationConstants.ACTION_LABEL_CREATE;
}
}
// if pdpUpdate properties are enabled through entitlement.properties
if (pdpUpdate && action == null) {
if (EntitlementConstants.StatusTypes.PUBLISH_POLICY.equals(typeOfAction)) {
action = statusHolder.getTargetAction();
}
if (action == null || (pdpActions.size() > 0 && !pdpActions.contains(action))) {
return;
}
if (EntitlementConstants.PolicyPublish.ACTION_CREATE.equals(action) || EntitlementConstants.PolicyPublish.ACTION_UPDATE.equals(action)) {
action = NotificationConstants.ACTION_LABEL_UPDATE;
}
}
if (action == null) {
return;
}
// Setting up properties and configuration object to be sent to the NotificationSender,
// which is consumed by all subscribed Message Sending Modules
NotificationSender notificationSender = EntitlementServiceComponent.getNotificationSender();
if (notificationSender != null) {
try {
PublisherEvent event = new PublisherEvent(eventName);
event.addEventProperty(NotificationConstants.TARGET_ID_PROPERTY_LABEL, statusHolder.getKey());
event.addEventProperty(NotificationConstants.USERNAME_PROPERTY_LABEL, statusHolder.getUser());
event.addEventProperty(NotificationConstants.TARGET_PROPERTY_LABEL, statusHolder.getTarget());
event.addEventProperty(NotificationConstants.ACTION_PROPERTY_LABEL, action);
if (log.isDebugEnabled()) {
log.debug("Invoking notification sender");
}
notificationSender.invoke(event);
} catch (NotificationManagementException e) {
log.error("Error while invoking notification sender", e);
}
} else {
if (log.isDebugEnabled()) {
log.error("No registered notification sending service found");
}
}
}
use of org.wso2.carbon.identity.notification.mgt.NotificationManagementException in project carbon-identity-framework by wso2.
the class NotificationManagementServiceComponent method activate.
@Activate
protected void activate(ComponentContext context) {
// messages on a registered event
try {
// Pass the bundle context to read property file in a case it is not found in default location.
try {
configBuilder = new NotificationMgtConfigBuilder(context.getBundleContext());
} catch (NotificationManagementException e) {
log.error("Error while building Notification Mgt configuration", e);
}
// Read the thread pool size from configurations. If not present in configurations use default value.
if (configBuilder != null && configBuilder.getThreadPoolSize() != null) {
try {
threadPoolSize = Integer.parseInt(configBuilder.getThreadPoolSize());
} catch (NumberFormatException e) {
if (log.isDebugEnabled()) {
log.debug("Error while parsing thread pool size configuration, " + "setting default size :" + NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE);
}
threadPoolSize = NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE;
}
} else {
if (log.isDebugEnabled()) {
log.debug("No configuration found for thread pool size, " + "setting default size :" + NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE);
}
threadPoolSize = NotificationMgtConstants.THREAD_POOL_DEFAULT_SIZE;
}
if (log.isDebugEnabled()) {
log.debug("Notification mgt thread pool size " + threadPoolSize);
}
// Register Notification sender as the service class
notificationSender = new NotificationSender(notificationSendingModules, threadPoolSize);
context.getBundleContext().registerService(NotificationSender.class.getName(), notificationSender, null);
if (log.isDebugEnabled()) {
log.debug("Notification Management bundle is activated");
}
// Catch throwable since there may be run time exceptions.
} catch (Throwable e) {
log.error("Error while initiating Notification Management component", e);
}
}
Aggregations