use of org.wso2.carbon.identity.event.bean.IdentityEventMessageContext in project carbon-identity-framework by wso2.
the class ConsentDeletionUserEventHandler method handleEvent.
/**
* Delete consents issued against a particular user when a user is deleted.
*
* @param event Post User Delete event.
* @throws IdentityEventException IdentityEventException.
*/
@Override
public void handleEvent(Event event) throws IdentityEventException {
IdentityEventMessageContext eventContext = new IdentityEventMessageContext(event);
if (!isEnabled(eventContext)) {
if (log.isDebugEnabled()) {
log.debug("ConsentDeletionUserEventHandler is disabled. Not handling the " + event.getEventName() + " event.");
}
return;
}
Map<String, Object> eventProperties = event.getEventProperties();
String userName = (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_NAME);
UserStoreManager userStoreManager = (UserStoreManager) eventProperties.get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER);
String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
String tenantDomain = getUserTenantDomain(eventProperties);
String usernameWithUserStoreDomain = UserCoreUtil.addDomainToName(userName, domainName);
if (log.isDebugEnabled()) {
log.debug(String.format("Deleting consents for user: %s , in tenant domain :%s", usernameWithUserStoreDomain, tenantDomain));
}
ConsentManager consentManager = IdentityConsentDataHolder.getInstance().getPrivilegedConsentManager();
try {
List<ReceiptListResponse> receiptListResponses = consentManager.searchReceipts(consentSearchLimit, 0, usernameWithUserStoreDomain, null, "*", null);
if (log.isDebugEnabled()) {
log.debug(String.format("Found %d receipts issued for user: %s, in tenant domain: %s", receiptListResponses.size(), usernameWithUserStoreDomain, tenantDomain));
}
receiptListResponses.forEach(rethrowConsumer(receiptListResponse -> {
if (log.isDebugEnabled()) {
log.debug(String.format("Deleting receipt with ID : %s, issued for application %s", receiptListResponse.getConsentReceiptId(), receiptListResponse.getSpDisplayName()));
}
consentManager.deleteReceipt(receiptListResponse.getConsentReceiptId());
}));
} catch (ConsentManagementException e) {
throw new IdentityEventException("Error while deleting consents for user " + userName, e);
}
}
use of org.wso2.carbon.identity.event.bean.IdentityEventMessageContext in project carbon-identity-framework by wso2.
the class IdentityEventMessageContextTest method testGetEvent.
@Test
public void testGetEvent() {
IdentityEventMessageContext identityEventMessageContext = new IdentityEventMessageContext(event);
Assert.assertNotNull(identityEventMessageContext.getEvent());
}
use of org.wso2.carbon.identity.event.bean.IdentityEventMessageContext 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.bean.IdentityEventMessageContext in project carbon-identity-framework by wso2.
the class AbstractEventHandler method canHandle.
public boolean canHandle(MessageContext messageContext) throws IdentityRuntimeException {
Event event = ((IdentityEventMessageContext) messageContext).getEvent();
String eventName = event.getEventName();
List<Subscription> subscriptionList = null;
if (configs != null) {
subscriptionList = configs.getSubscriptions();
} else {
return false;
}
if (subscriptionList != null) {
for (Subscription subscription : subscriptionList) {
if (subscription.getSubscriptionName().equals(eventName)) {
return true;
}
}
}
return false;
}
use of org.wso2.carbon.identity.event.bean.IdentityEventMessageContext 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);
}
}
}
}
Aggregations