Search in sources :

Example 1 with IdentityEventException

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);
        }
    }
}
Also used : FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) JSONObject(org.json.JSONObject) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) IdentityEventService(org.wso2.carbon.identity.event.services.IdentityEventService)

Example 2 with IdentityEventException

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);
    }
}
Also used : IdentityConsentMgtUtils(org.wso2.carbon.identity.consent.mgt.IdentityConsentMgtUtils) IdentityConsentDataHolder(org.wso2.carbon.identity.consent.mgt.internal.IdentityConsentDataHolder) InitConfig(org.wso2.carbon.identity.core.handler.InitConfig) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) LambdaExceptionUtils.rethrowConsumer(org.wso2.carbon.identity.core.util.LambdaExceptionUtils.rethrowConsumer) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) Event(org.wso2.carbon.identity.event.event.Event) UserCoreConstants(org.wso2.carbon.user.core.UserCoreConstants) MessageContext(org.wso2.carbon.identity.core.bean.context.MessageContext) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) List(java.util.List) Map(java.util.Map) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) IdentityEventMessageContext(org.wso2.carbon.identity.event.bean.IdentityEventMessageContext) IdentityEventConstants(org.wso2.carbon.identity.event.IdentityEventConstants) UserCoreUtil(org.wso2.carbon.user.core.util.UserCoreUtil) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) IdentityEventMessageContext(org.wso2.carbon.identity.event.bean.IdentityEventMessageContext)

Example 3 with IdentityEventException

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());
    }
}
Also used : Entity(org.wso2.carbon.identity.workflow.mgt.bean.Entity) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException) IdentityErrorMsgContext(org.wso2.carbon.identity.core.model.IdentityErrorMsgContext) WorkflowManagementService(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService) WorkflowManagementServiceImpl(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl)

Example 4 with IdentityEventException

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);
    }
}
Also used : IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) IdentityEventService(org.wso2.carbon.identity.event.services.IdentityEventService)

Example 5 with IdentityEventException

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");
    }
}
Also used : IdentityEventServiceImpl(org.wso2.carbon.identity.event.services.IdentityEventServiceImpl) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) IdentityEventService(org.wso2.carbon.identity.event.services.IdentityEventService) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)70 HashMap (java.util.HashMap)41 Event (org.wso2.carbon.identity.event.event.Event)37 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)17 User (org.wso2.carbon.identity.application.common.model.User)14 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)14 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)13 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)13 IdentityEventService (org.wso2.carbon.identity.event.services.IdentityEventService)11 UserStoreException (org.wso2.carbon.user.core.UserStoreException)10 Map (java.util.Map)9 JSONObject (org.json.JSONObject)9 UserStoreException (org.wso2.carbon.user.api.UserStoreException)9 Property (org.wso2.carbon.identity.recovery.model.Property)7 RealmService (org.wso2.carbon.user.core.service.RealmService)6 Properties (java.util.Properties)4 Test (org.testng.annotations.Test)4 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)4 Property (org.wso2.carbon.identity.application.common.model.Property)4 IdentityGovernanceException (org.wso2.carbon.identity.governance.IdentityGovernanceException)4