use of org.wso2.carbon.identity.event.IdentityEventException in project carbon-identity-framework by wso2.
the class FrameworkUtils method triggerSessionExpireEvent.
/**
* Trigger SESSION_EXPIRE event on session expiry due to a session idle timeout or a remember me session time out.
*
* @param request HttpServletRequest.
* @param context Authentication context.
* @param sessionContext Session context.
* @throws FrameworkException Error in triggering the session expiry event.
*/
private static void triggerSessionExpireEvent(HttpServletRequest request, AuthenticationContext context, SessionContext sessionContext) throws FrameworkException {
AuthenticatedUser authenticatedUser = new AuthenticatedUser();
if (sessionContext != null) {
Object authenticatedUserObj = sessionContext.getProperty(FrameworkConstants.AUTHENTICATED_USER);
if (authenticatedUserObj instanceof AuthenticatedUser) {
authenticatedUser = (AuthenticatedUser) authenticatedUserObj;
}
context.setSubject(authenticatedUser);
IdentityEventService eventService = FrameworkServiceDataHolder.getInstance().getIdentityEventService();
try {
Map<String, Object> eventProperties = new HashMap<>();
eventProperties.put(IdentityEventConstants.EventProperty.REQUEST, request);
eventProperties.put(IdentityEventConstants.EventProperty.CONTEXT, context);
eventProperties.put(IdentityEventConstants.EventProperty.SESSION_CONTEXT, sessionContext);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put(FrameworkConstants.AnalyticsAttributes.USER, authenticatedUser);
paramMap.put(FrameworkConstants.AnalyticsAttributes.SESSION_ID, context.getSessionIdentifier());
Map<String, Object> unmodifiableParamMap = Collections.unmodifiableMap(paramMap);
eventProperties.put(IdentityEventConstants.EventProperty.PARAMS, unmodifiableParamMap);
Event event = new Event(IdentityEventConstants.EventName.SESSION_EXPIRE.name(), eventProperties);
eventService.handleEvent(event);
} catch (IdentityEventException e) {
throw new FrameworkException("Error in triggering session expire event for the session: " + context.getSessionIdentifier() + " of user: " + authenticatedUser.toFullQualifiedUsername(), e);
}
}
}
use of org.wso2.carbon.identity.event.IdentityEventException 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.IdentityEventException in project carbon-identity-framework by wso2.
the class WorkflowPendingUserAuthnHandler method validatePendingApproval.
/**
* Validate whether the user account approval is pending.
*
* @param username Username.
* @throws IdentityEventException If an error occurred while validating pending approval.
*/
private void validatePendingApproval(String username, int tenantId) throws IdentityEventException {
boolean isPendingApproval;
try {
Entity entity = new Entity(MultitenantUtils.getTenantAwareUsername(username), WFConstant.WORKFLOW_ENTITY_TYPE, tenantId);
WorkflowManagementService workflowManagementService = new WorkflowManagementServiceImpl();
isPendingApproval = workflowManagementService.entityHasPendingWorkflowsOfType(entity, WFConstant.WORKFLOW_REQUEST_TYPE);
} catch (WorkflowException e) {
throw new IdentityEventException("Error occurred while checking the pending approvals for " + "the account of the user: " + username, e);
} catch (IdentityRuntimeException e) {
throw new IdentityEventException("Can't find the tenant domain for the user: " + username, e);
}
if (isPendingApproval) {
IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(IdentityCoreConstants.USER_ACCOUNT_PENDING_APPROVAL_ERROR_CODE);
IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
throw new IdentityEventException(WorkflowErrorConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_PENDING_APPROVAL.getCode(), WorkflowErrorConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_PENDING_APPROVAL.getMessage());
}
}
use of org.wso2.carbon.identity.event.IdentityEventException in project carbon-identity-framework by wso2.
the class RoleManagementEventPublisherProxy method doPublishEvent.
private void doPublishEvent(Event event) {
try {
if (log.isDebugEnabled()) {
log.debug("Event: " + event.getEventName() + " is published for the role management operation in " + "the tenant with the tenantId: " + event.getEventProperties().get(IdentityEventConstants.EventProperty.TENANT_ID));
}
IdentityEventService eventService = RoleManagementServiceComponentHolder.getInstance().getIdentityEventService();
eventService.handleEvent(event);
} catch (IdentityEventException e) {
log.error("Error while publishing the event: " + event.getEventName() + ".", e);
}
}
use of org.wso2.carbon.identity.event.IdentityEventException in project carbon-identity-framework by wso2.
the class IdentityEventServiceComponent method activate.
@Activate
protected void activate(ComponentContext context) {
try {
IdentityEventServiceDataHolder.getInstance().setEventMgtService(new IdentityEventServiceImpl(eventHandlerList, Integer.parseInt(IdentityEventConfigBuilder.getInstance().getThreadPoolSize())));
context.getBundleContext().registerService(IdentityEventService.class.getName(), IdentityEventServiceDataHolder.getInstance().getEventMgtService(), null);
} catch (IdentityEventException e) {
log.error("Error while initiating IdentityMgtService.");
}
if (log.isDebugEnabled()) {
log.debug("Identity Management Listener is enabled");
}
}
Aggregations