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