Search in sources :

Example 1 with IdentityEventClientException

use of org.wso2.carbon.identity.event.IdentityEventClientException in project identity-governance by wso2-extensions.

the class ChallengeAnswerValidationHandler method handleEvent.

@Override
public void handleEvent(Event event) throws IdentityEventException {
    String eventName = event.getEventName();
    Map<String, Object> eventProperties = event.getEventProperties();
    UserStoreManager userStoreManager = (UserStoreManager) eventProperties.get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER);
    User user = (User) eventProperties.get(IdentityEventConstants.EventProperty.USER);
    UserChallengeAnswer[] userChallengeAnswers = (UserChallengeAnswer[]) eventProperties.get(IdentityEventConstants.EventProperty.USER_CHALLENGE_ANSWERS);
    Map<String, String> existingQuestionAndAnswers = (Map<String, String>) eventProperties.get(IdentityEventConstants.EventProperty.USER_OLD_CHALLENGE_ANSWERS);
    user.setUserStoreDomain(userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME));
    if (IdentityEventConstants.Event.PRE_SET_CHALLENGE_QUESTION_ANSWERS.equals(eventName)) {
        try {
            validateChallengeAnswers(user, userChallengeAnswers, existingQuestionAndAnswers);
        } catch (IdentityRecoveryClientException e) {
            throw new IdentityEventClientException(e.getErrorCode(), e.getMessage(), e);
        } catch (IdentityRecoveryServerException e) {
            throw new IdentityEventServerException(e.getErrorCode(), e.getMessage(), e);
        }
    }
}
Also used : IdentityEventServerException(org.wso2.carbon.identity.event.IdentityEventServerException) User(org.wso2.carbon.identity.application.common.model.User) IdentityRecoveryServerException(org.wso2.carbon.identity.recovery.IdentityRecoveryServerException) IdentityEventClientException(org.wso2.carbon.identity.event.IdentityEventClientException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) UserChallengeAnswer(org.wso2.carbon.identity.recovery.model.UserChallengeAnswer) HashMap(java.util.HashMap) Map(java.util.Map) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 2 with IdentityEventClientException

use of org.wso2.carbon.identity.event.IdentityEventClientException in project identity-governance by wso2-extensions.

the class ChallengeQuestionManager method triggerChallengeAnswersValidation.

/**
 * Trigger challenge question answers validation according to the given event name.
 *
 * @param user                 User
 * @param userChallengeAnswers Array of challenge answers
 * @param eventName            Event name
 * @throws IdentityRecoveryClientException Error while validating the challenge answers
 * @throws IdentityRecoveryServerException Error while getting the user store manager or triggering the event.
 */
private void triggerChallengeAnswersValidation(User user, UserChallengeAnswer[] userChallengeAnswers, Map<String, String> existingQuestionAndAnswers, String eventName) throws IdentityRecoveryClientException, IdentityRecoveryServerException {
    Map<String, Object> properties = new HashMap<>();
    properties.put(IdentityEventConstants.EventProperty.USER, user);
    properties.put(IdentityEventConstants.EventProperty.USER_CHALLENGE_ANSWERS, userChallengeAnswers);
    properties.put(IdentityEventConstants.EventProperty.USER_OLD_CHALLENGE_ANSWERS, existingQuestionAndAnswers);
    try {
        UserStoreManager userStoreManager;
        if (IdentityUtil.getPrimaryDomainName().equals(user.getUserStoreDomain())) {
            userStoreManager = (UserStoreManager) CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
        } else {
            userStoreManager = ((UserStoreManager) CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager()).getSecondaryUserStoreManager(user.getUserStoreDomain());
        }
        properties.put(IdentityEventConstants.EventProperty.USER_STORE_MANAGER, userStoreManager);
    } catch (UserStoreException e) {
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_LOAD_USER_STORE_MANAGER, null, e);
    }
    Event identityMgtEvent = new Event(eventName, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventClientException e) {
        throw new IdentityRecoveryClientException(e.getErrorCode(), e.getMessage(), e);
    } catch (IdentityEventServerException e) {
        throw new IdentityRecoveryServerException(e.getErrorCode(), e.getMessage(), e);
    } catch (IdentityEventException e) {
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_PUBLISH_EVENT, eventName, e);
    }
}
Also used : IdentityEventServerException(org.wso2.carbon.identity.event.IdentityEventServerException) HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Event(org.wso2.carbon.identity.event.event.Event) IdentityEventClientException(org.wso2.carbon.identity.event.IdentityEventClientException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager)

Example 3 with IdentityEventClientException

use of org.wso2.carbon.identity.event.IdentityEventClientException in project identity-governance by wso2-extensions.

the class NotificationPasswordRecoveryManager method publishEvent.

private void publishEvent(User user, String notify, String code, String password, Property[] metaProperties, String eventName, UserRecoveryData userRecoveryData) throws IdentityRecoveryException {
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(IdentityEventConstants.EventProperty.USER, user);
    properties.put(IdentityEventConstants.EventProperty.USER_NAME, user.getUserName());
    properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getTenantDomain());
    properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getUserStoreDomain());
    if (userRecoveryData != null) {
        properties.put(IdentityEventConstants.EventProperty.RECOVERY_SCENARIO, userRecoveryData.getRecoveryScenario().name());
    }
    if (StringUtils.isNotBlank(code)) {
        properties.put(IdentityRecoveryConstants.CONFIRMATION_CODE, code);
    }
    if (StringUtils.isNotBlank(notify)) {
        properties.put(IdentityRecoveryConstants.NOTIFY, notify);
    }
    if (metaProperties != null) {
        for (Property metaProperty : metaProperties) {
            if (StringUtils.isNotBlank(metaProperty.getValue()) && StringUtils.isNotBlank(metaProperty.getKey())) {
                properties.put(metaProperty.getKey(), metaProperty.getValue());
            }
        }
    }
    Event identityMgtEvent = new Event(eventName, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventClientException e) {
        throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_ERROR_HANDLING_THE_EVENT.getCode(), e.getMessage(), null);
    } catch (IdentityEventException e) {
        log.error("Error occurred while publishing event " + eventName + " for user " + user);
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_PUBLISH_EVENT, eventName, e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) IdentityEventClientException(org.wso2.carbon.identity.event.IdentityEventClientException) JSONObject(org.json.JSONObject) Property(org.wso2.carbon.identity.recovery.model.Property)

Aggregations

HashMap (java.util.HashMap)3 IdentityEventClientException (org.wso2.carbon.identity.event.IdentityEventClientException)3 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)2 IdentityEventServerException (org.wso2.carbon.identity.event.IdentityEventServerException)2 Event (org.wso2.carbon.identity.event.event.Event)2 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)2 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 User (org.wso2.carbon.identity.application.common.model.User)1 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)1 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)1 Property (org.wso2.carbon.identity.recovery.model.Property)1 UserChallengeAnswer (org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1