Search in sources :

Example 91 with IdentityEventException

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

the class UserEmailVerificationHandler method triggerEmailNotificationToExistingEmail.

/**
 * Trigger a notification to the existing email address when the user attempts to update the existing email
 * address.
 *
 * @param sendTo       Send to email address.
 * @param templateType Email template type.
 * @param user         User.
 * @param props        Other properties.
 * @throws IdentityEventException IdentityEventException while sending notification to user.
 */
private void triggerEmailNotificationToExistingEmail(String sendTo, String templateType, User user, Map<String, String> props) throws IdentityEventException {
    if (log.isDebugEnabled()) {
        log.debug("Sending : " + templateType + " notification to user : " + user.toFullQualifiedUsername());
    }
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(IdentityRecoveryConstants.SEND_TO, sendTo);
    properties.put(IdentityRecoveryConstants.TEMPLATE_TYPE, templateType);
    if (CollectionUtils.size(props) > 0) {
        properties.putAll(props);
    }
    Event identityMgtEvent = new Event(IdentityEventConstants.Event.TRIGGER_NOTIFICATION, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventException e) {
        throw new IdentityEventException("Error while sending notification for user: " + user.toFullQualifiedUsername(), e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event)

Example 92 with IdentityEventException

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

the class UserEmailVerificationHandler method initNotificationForEmailVerificationOnUpdate.

private void initNotificationForEmailVerificationOnUpdate(User user, String secretKey, String verificationPendingEmailAddress) throws IdentityEventException {
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    try {
        userRecoveryDataStore.invalidate(user, RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE, RecoverySteps.VERIFY_EMAIL);
        UserRecoveryData recoveryDataDO = new UserRecoveryData(user, secretKey, RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE, RecoverySteps.VERIFY_EMAIL);
        /* Email address persisted in remaining set ids to maintain context information about the email address
            associated with the verification code generated. */
        recoveryDataDO.setRemainingSetIds(verificationPendingEmailAddress);
        userRecoveryDataStore.store(recoveryDataDO);
        triggerNotification(user, IdentityRecoveryConstants.NOTIFICATION_TYPE_VERIFY_EMAIL_ON_UPDATE, secretKey, Utils.getArbitraryProperties(), verificationPendingEmailAddress, recoveryDataDO);
    } catch (IdentityRecoveryException e) {
        throw new IdentityEventException("Error while sending notification for user: " + user.toFullQualifiedUsername(), e);
    }
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException)

Example 93 with IdentityEventException

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

the class UsernameRecoveryManagerImpl method triggerNotification.

/**
 * Trigger notification to send userName recovery information.
 *
 * @param user                User
 * @param notificationChannel Notification channel
 * @param eventName           Event name
 * @param metaProperties      Meta properties to be send with the notification.
 * @throws IdentityRecoveryException Error while triggering notification.
 */
private void triggerNotification(User user, String notificationChannel, String eventName, Map<String, String> metaProperties) throws IdentityRecoveryException {
    HashMap<String, Object> properties = new HashMap<>();
    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());
    properties.put(IdentityEventConstants.EventProperty.NOTIFICATION_CHANNEL, notificationChannel);
    if (metaProperties != null) {
        for (String key : metaProperties.keySet()) {
            String value = metaProperties.get(key);
            if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) {
                properties.put(key, value);
            }
        }
    }
    properties.put(IdentityRecoveryConstants.TEMPLATE_TYPE, IdentityRecoveryConstants.NOTIFICATION_ACCOUNT_ID_RECOVERY);
    Event identityMgtEvent = new Event(eventName, properties);
    try {
        IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
    } catch (IdentityEventException e) {
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_TRIGGER_NOTIFICATION, user.getUserName(), e);
    }
}
Also used : HashMap(java.util.HashMap) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) Event(org.wso2.carbon.identity.event.event.Event) JSONObject(org.json.JSONObject)

Example 94 with IdentityEventException

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

the class AccountConfirmationValidationHandler method handleEvent.

@Override
public void handleEvent(Event event) throws IdentityEventException {
    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 tenantDomain = (String) eventProperties.get(IdentityEventConstants.EventProperty.TENANT_DOMAIN);
    String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
    User user = new User();
    user.setUserName(userName);
    user.setTenantDomain(tenantDomain);
    user.setUserStoreDomain(domainName);
    boolean isSelfSignupEnabled = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ENABLE_SELF_SIGNUP, user.getTenantDomain()));
    boolean isEmailVerificationEnabled = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ENABLE_EMAIL_VERIFICATION, user.getTenantDomain()));
    if (!isSelfSignupEnabled && !isEmailVerificationEnabled) {
        if (log.isDebugEnabled()) {
            log.debug("Self signup feature and email verification are disabled in the tenant: " + tenantDomain);
        }
        return;
    }
    if (IdentityEventConstants.Event.POST_AUTHENTICATION.equals(event.getEventName())) {
        if (log.isDebugEnabled()) {
            log.debug("Handling PostAuthenticate for " + user);
        }
        boolean isAccountLocked;
        try {
            if (isAuthPolicyAccountExistCheck() && !isUserExistsInDomain(userStoreManager, userName)) {
                IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(UserCoreConstants.ErrorCode.USER_DOES_NOT_EXIST);
                IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
                return;
            }
            Map<String, String> values = userStoreManager.getUserClaimValues(userName, new String[] { ACCOUNT_LOCKED_CLAIM }, UserCoreConstants.DEFAULT_PROFILE);
            isAccountLocked = Boolean.parseBoolean(values.get(ACCOUNT_LOCKED_CLAIM));
        } catch (UserStoreException e) {
            throw new IdentityEventException("Error while retrieving account lock claim value", e);
        }
        if (!isAccountLocked) {
            // User account is unlocked. No need to process further.
            return;
        }
        boolean operationStatus = (Boolean) event.getEventProperties().get(IdentityEventConstants.EventProperty.OPERATION_STATUS);
        if (operationStatus && !isUserAccountConfirmed(user)) {
            IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(IdentityCoreConstants.USER_ACCOUNT_NOT_CONFIRMED_ERROR_CODE);
            IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
            throw new IdentityEventException(IdentityCoreConstants.USER_ACCOUNT_NOT_CONFIRMED_ERROR_CODE, "User : " + userName + " not confirmed yet.");
        } else if (isInvalidCredentialsScenario(operationStatus, user)) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Account unconfirmed user: %s in userstore: %s in tenant: %s is trying " + "to log in with an invalid password", userName, domainName, tenantDomain));
            }
            IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(IdentityCoreConstants.USER_INVALID_CREDENTIALS);
            IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
            throw new IdentityEventException(IdentityCoreConstants.USER_INVALID_CREDENTIALS, "Invalid login attempt by self registered user: " + userName);
        }
    }
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) IdentityErrorMsgContext(org.wso2.carbon.identity.core.model.IdentityErrorMsgContext)

Example 95 with IdentityEventException

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

the class AccountConfirmationValidationHandler method getRecoveryData.

private UserRecoveryData getRecoveryData(User user) throws IdentityEventException {
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    UserRecoveryData recoveryData;
    try {
        recoveryData = userRecoveryDataStore.loadWithoutCodeExpiryValidation(user);
    } catch (IdentityRecoveryException e) {
        throw new IdentityEventException("Error while loading recovery data for user ", e);
    }
    return recoveryData;
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException)

Aggregations

IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)75 HashMap (java.util.HashMap)42 Event (org.wso2.carbon.identity.event.event.Event)39 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)12 Map (java.util.Map)11 UserStoreException (org.wso2.carbon.user.core.UserStoreException)10 JSONObject (org.json.JSONObject)9 UserStoreException (org.wso2.carbon.user.api.UserStoreException)9 Property (org.wso2.carbon.identity.recovery.model.Property)7 Property (org.wso2.carbon.identity.application.common.model.Property)6 RealmService (org.wso2.carbon.user.core.service.RealmService)6 Test (org.testng.annotations.Test)5 Properties (java.util.Properties)4 IdentityGovernanceException (org.wso2.carbon.identity.governance.IdentityGovernanceException)4 NotificationChannelManagerException (org.wso2.carbon.identity.governance.exceptions.notiification.NotificationChannelManagerException)4