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);
}
}
}
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);
}
}
Aggregations