Search in sources :

Example 36 with UserRecoveryDataStore

use of org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore in project identity-governance by wso2-extensions.

the class MobileNumberVerificationHandler method initNotificationForMobileNumberVerificationOnUpdate.

/**
 * Store verification details in the recovery data store and initiate notification.
 *
 * @param user  User.
 * @param verificationPendingMobileNumber Updated mobile number that is pending verification.
 * @throws IdentityEventException
 */
private void initNotificationForMobileNumberVerificationOnUpdate(User user, String verificationPendingMobileNumber) throws IdentityEventException {
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    try {
        userRecoveryDataStore.invalidate(user, RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE, RecoverySteps.VERIFY_MOBILE_NUMBER);
        String secretKey = Utils.generateSecretKey(NotificationChannels.SMS_CHANNEL.getChannelType(), user.getTenantDomain(), String.valueOf(RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE));
        UserRecoveryData recoveryDataDO = new UserRecoveryData(user, secretKey, RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE, RecoverySteps.VERIFY_MOBILE_NUMBER);
        /* Mobile number is persisted in remaining set ids to maintain context information about the mobile number
            associated with the verification code generated. */
        recoveryDataDO.setRemainingSetIds(verificationPendingMobileNumber);
        userRecoveryDataStore.store(recoveryDataDO);
        triggerNotification(user, secretKey, Utils.getArbitraryProperties(), verificationPendingMobileNumber);
    } catch (IdentityRecoveryException e) {
        throw new IdentityEventException("Error while sending notification to user: " + user.toFullQualifiedUsername() + " for mobile verification on update.", 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 37 with UserRecoveryDataStore

use of org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore in project identity-governance by wso2-extensions.

the class UserEmailVerificationHandler method setRecoveryData.

protected void setRecoveryData(User user, Enum recoveryScenario, Enum recoveryStep, String secretKey) throws IdentityEventException {
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    try {
        userRecoveryDataStore.invalidate(user);
        UserRecoveryData recoveryDataDO = new UserRecoveryData(user, secretKey, recoveryScenario, recoveryStep);
        userRecoveryDataStore.store(recoveryDataDO);
    } catch (IdentityRecoveryException e) {
        throw new IdentityEventException("Error while setting recovery data for user ", 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 38 with UserRecoveryDataStore

use of org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore 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 39 with UserRecoveryDataStore

use of org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore 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)

Example 40 with UserRecoveryDataStore

use of org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore in project identity-api-server by wso2.

the class ServerTenantManagementService method validateInputAgainstCode.

/**
 * Validate details attached to the code sent in email verification with the sent in details.
 * @param tenant tenant
 * @throws TenantManagementClientException error in validating code
 */
private void validateInputAgainstCode(ChannelVerifiedTenantModel tenant) throws TenantManagementClientException {
    String code = tenant.getCode();
    if (StringUtils.isBlank(code)) {
        throw new TenantManagementClientException(ERROR_CODE_MISSING_REQUIRED_PARAMETER.getCode(), String.format(ERROR_CODE_MISSING_REQUIRED_PARAMETER.getMessage(), CODE));
    }
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    // If the code is validated, the load method will return data. Otherwise method will throw exceptions.
    try {
        UserRecoveryData recoveryData = userRecoveryDataStore.load(code);
        if (recoveryData != null && recoveryData.getUser() != null && tenant.getOwners() != null && tenant.getOwners().get(0) != null && tenant.getOwners().get(0).getEmail() != null && tenant.getOwners().get(0).getEmail().equalsIgnoreCase(recoveryData.getUser().getUserName())) {
            userRecoveryDataStore.invalidate(code);
            return;
        } else {
            // the confirmed email using the code and submitted emails are different.
            userRecoveryDataStore.invalidate(code);
            log.warn("The confirmed email using the code and submitted emails are different.");
            throw new TenantManagementClientException(ERROR_CODE_INVALID_EMAIL.getCode(), String.format(ERROR_CODE_INVALID_EMAIL.getMessage(), CODE));
        }
    } catch (IdentityRecoveryException e) {
        throw handleException(Response.Status.UNAUTHORIZED, TenantManagementConstants.ErrorMessage.ERROR_CODE_ERROR_VALIDATING_TENANT_CODE, null);
    }
}
Also used : TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException)

Aggregations

UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)40 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)35 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)23 User (org.wso2.carbon.identity.application.common.model.User)15 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)13 HashMap (java.util.HashMap)5 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)4 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)4 ChallengeQuestionManager (org.wso2.carbon.identity.recovery.ChallengeQuestionManager)3 ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)3 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)3 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)3 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)3 IdentityException (org.wso2.carbon.identity.base.IdentityException)2 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)2 ChallengeQuestionResponse (org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse)2 InternalServerErrorException (org.wso2.carbon.identity.user.endpoint.exceptions.InternalServerErrorException)2 UserFunctionalityManagementClientException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException)2 UserFunctionalityManagementException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException)2