Search in sources :

Example 1 with IdentityEventServerException

use of org.wso2.carbon.identity.event.IdentityEventServerException 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 IdentityEventServerException

use of org.wso2.carbon.identity.event.IdentityEventServerException 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)

Aggregations

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