Search in sources :

Example 21 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class ResendCodeApiServiceImpl method doResendConfirmationCode.

private NotificationResponseBean doResendConfirmationCode(String recoveryScenario, NotificationResponseBean notificationResponseBean, ResendCodeRequestDTO resendCodeRequestDTO) {
    UserRecoveryData userRecoveryData = Utils.getUserRecoveryData(resendCodeRequestDTO, recoveryScenario);
    if (userRecoveryData == null) {
        return notificationResponseBean;
    }
    ResendConfirmationManager resendConfirmationManager = Utils.getResendConfirmationManager();
    if (RecoveryScenarios.ASK_PASSWORD.toString().equals(recoveryScenario) && RecoveryScenarios.ASK_PASSWORD.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.UPDATE_PASSWORD.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.ASK_PASSWORD.toString(), RecoverySteps.UPDATE_PASSWORD.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_ASK_PASSWORD, resendCodeRequestDTO);
    } else if (RecoveryScenarios.NOTIFICATION_BASED_PW_RECOVERY.toString().equals(recoveryScenario) && RecoveryScenarios.NOTIFICATION_BASED_PW_RECOVERY.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.UPDATE_PASSWORD.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.NOTIFICATION_BASED_PW_RECOVERY.toString(), RecoverySteps.UPDATE_PASSWORD.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_PASSWORD_RESET, resendCodeRequestDTO);
    } else if (RecoveryScenarios.SELF_SIGN_UP.toString().equals(recoveryScenario) && RecoveryScenarios.SELF_SIGN_UP.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.CONFIRM_SIGN_UP.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.SELF_SIGN_UP.toString(), RecoverySteps.CONFIRM_SIGN_UP.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_ACCOUNT_CONFIRM, resendCodeRequestDTO);
    } else if (RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK.toString().equals(recoveryScenario) && RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.UPDATE_PASSWORD.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK.toString(), RecoverySteps.UPDATE_PASSWORD.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_ADMIN_FORCED_PASSWORD_RESET, resendCodeRequestDTO);
    } else if (RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP.toString().equals(recoveryScenario) && RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.UPDATE_PASSWORD.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP.toString(), RecoverySteps.UPDATE_PASSWORD.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_ADMIN_FORCED_PASSWORD_RESET_WITH_OTP, resendCodeRequestDTO);
    } else if (RecoveryScenarios.TENANT_ADMIN_ASK_PASSWORD.toString().equals(recoveryScenario) && RecoveryScenarios.TENANT_ADMIN_ASK_PASSWORD.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.UPDATE_PASSWORD.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.TENANT_ADMIN_ASK_PASSWORD.toString(), RecoverySteps.UPDATE_PASSWORD.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_TENANT_REGISTRATION_CONFIRMATION, resendCodeRequestDTO);
    } else if (RecoveryScenarios.LITE_SIGN_UP.toString().equals(recoveryScenario) && RecoveryScenarios.LITE_SIGN_UP.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.CONFIRM_LITE_SIGN_UP.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.LITE_SIGN_UP.toString(), RecoverySteps.CONFIRM_LITE_SIGN_UP.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_LITE_USER_EMAIL_CONFIRM, resendCodeRequestDTO);
    } else if (RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario) && RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.VERIFY_EMAIL.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE.toString(), RecoverySteps.VERIFY_EMAIL.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_VERIFY_EMAIL_ON_UPDATE, resendCodeRequestDTO);
    }
    return notificationResponseBean;
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) ResendConfirmationManager(org.wso2.carbon.identity.recovery.confirmation.ResendConfirmationManager)

Example 22 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class RecoverPasswordApiServiceImpl method recoverPasswordPost.

@Override
public Response recoverPasswordPost(RecoveryInitiatingRequestDTO recoveryInitiatingRequest, String type, Boolean notify) {
    String tenantDomainFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    if (StringUtils.isNotBlank(tenantDomainFromContext)) {
        recoveryInitiatingRequest.getUser().setTenantDomain(tenantDomainFromContext);
    } else {
        recoveryInitiatingRequest.getUser().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    }
    UserDTO user = recoveryInitiatingRequest.getUser();
    int tenantIdFromContext = IdentityTenantUtil.getTenantId(user.getTenantDomain());
    ResolvedUserResult resolvedUserResult = FrameworkUtils.processMultiAttributeLoginIdentification(user.getUsername(), user.getTenantDomain());
    if (resolvedUserResult != null && ResolvedUserResult.UserResolvedStatus.SUCCESS.equals(resolvedUserResult.getResolvedStatus())) {
        user.setUsername(resolvedUserResult.getUser().getUsername());
        UserDTO userDTO = recoveryInitiatingRequest.getUser();
        userDTO.setUsername(user.getUsername());
        recoveryInitiatingRequest.setUser(userDTO);
    }
    NotificationPasswordRecoveryManager notificationPasswordRecoveryManager = RecoveryUtil.getNotificationBasedPwdRecoveryManager();
    NotificationResponseBean notificationResponseBean = null;
    try {
        notificationResponseBean = notificationPasswordRecoveryManager.sendRecoveryNotification(RecoveryUtil.getUser(recoveryInitiatingRequest.getUser()), type, notify, RecoveryUtil.getProperties(recoveryInitiatingRequest.getProperties()));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while sending recovery notification ", e);
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        if (throwable != null && StringUtils.equals(Constants.ERROR_MESSAGE_EMAIL_NOT_FOUND, throwable.getMessage())) {
            LOG.error(throwable.getMessage(), throwable);
            RecoveryUtil.handleBadRequest(throwable.getMessage(), Constants.ERROR_CODE_EMAIL_NOT_FOUND);
        }
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    if (StringUtils.isBlank(notificationResponseBean.getKey())) {
        return Response.accepted().build();
    }
    return Response.accepted(notificationResponseBean.getKey()).build();
}
Also used : NotificationPasswordRecoveryManager(org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager) NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) ResolvedUserResult(org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) org.wso2.carbon.identity.recovery.endpoint(org.wso2.carbon.identity.recovery.endpoint) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 23 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class PasswordRecoveryManagerImpl method notifyUser.

/**
 * Send recovery information to the user.
 *
 * @param user                         User
 * @param notificationChannel          Notification Channel
 * @param manageNotificationInternally Manage notifications internally
 * @param properties                   Meta properties
 * @return NotificationResponseBean
 * @throws IdentityRecoveryException Error while sending notifications
 */
private NotificationResponseBean notifyUser(User user, String notificationChannel, boolean manageNotificationInternally, Map<String, String> properties) throws IdentityRecoveryException {
    Property[] metaProperties = buildPropertyList(notificationChannel, properties);
    NotificationResponseBean notificationResponseBean;
    try {
        notificationResponseBean = NotificationPasswordRecoveryManager.getInstance().sendRecoveryNotification(user, null, manageNotificationInternally, metaProperties);
    } catch (IdentityRecoveryException exception) {
        if (StringUtils.isNotEmpty(exception.getErrorCode())) {
            String errorCode = exception.getErrorCode();
            if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_CALLBACK_URL_NOT_VALID.getCode().equals(errorCode)) {
                exception.setErrorCode(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CALLBACK_PASSWORD_RESET.getCode());
            } else if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode().equals(errorCode)) {
                exception.setErrorCode(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED_ERROR_PASSWORD_RESET.getCode());
            }
            exception.setErrorCode(Utils.prependOperationScenarioToErrorCode(exception.getErrorCode(), IdentityRecoveryConstants.PASSWORD_RECOVERY_SCENARIO));
        }
        throw exception;
    }
    if (notificationResponseBean == null) {
        if (log.isDebugEnabled()) {
            log.debug("Empty Response while notifying password recovery information for user : " + user.getUserName());
        }
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED_ERROR_PASSWORD_RESET, null);
    }
    return notificationResponseBean;
}
Also used : NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) Property(org.wso2.carbon.identity.recovery.model.Property)

Example 24 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class PasswordRecoveryManagerImpl method notify.

/**
 * Verify the recovery code and send recovery information via channel which matches the given channel id.
 *
 * @param recoveryCode RecoveryId of the user
 * @param channelId    Channel Id of the user
 * @param tenantDomain Tenant Domain
 * @param properties   Meta properties in the recovery request
 * @return UsernameRecoverDTO {@link PasswordRecoverDTO} object that contains notified
 * channel details and success status code
 * @throws IdentityRecoveryException Error while notifying user
 */
@Override
public PasswordRecoverDTO notify(String recoveryCode, String channelId, String tenantDomain, Map<String, String> properties) throws IdentityRecoveryException {
    validateTenantDomain(tenantDomain);
    validateConfigurations(tenantDomain);
    int channelIDCode = validateChannelID(channelId);
    UserAccountRecoveryManager userAccountRecoveryManager = UserAccountRecoveryManager.getInstance();
    // Get Recovery data.
    UserRecoveryData userRecoveryData = userAccountRecoveryManager.getUserRecoveryData(recoveryCode, RecoverySteps.SEND_RECOVERY_INFORMATION);
    String notificationChannel = extractNotificationChannelDetails(userRecoveryData.getRemainingSetIds(), channelIDCode);
    // Resolve notify status according to the notification channel of the user.
    boolean manageNotificationsInternally = true;
    if (NotificationChannels.EXTERNAL_CHANNEL.getChannelType().equals(notificationChannel)) {
        manageNotificationsInternally = false;
    }
    NotificationResponseBean notificationResponseBean = notifyUser(userRecoveryData.getUser(), notificationChannel, manageNotificationsInternally, properties);
    String secretKey = notificationResponseBean.getKey();
    String resendCode = generateResendCode(notificationChannel, userRecoveryData);
    return buildPasswordRecoveryResponseDTO(notificationChannel, secretKey, resendCode);
}
Also used : NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserAccountRecoveryManager(org.wso2.carbon.identity.recovery.internal.service.impl.UserAccountRecoveryManager)

Aggregations

NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)15 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)8 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)5 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)4 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)4 SuccessfulUserCreationDTO (org.wso2.carbon.identity.user.endpoint.dto.SuccessfulUserCreationDTO)4 Test (org.testng.annotations.Test)3 ResolvedUserResult (org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult)3 ResendConfirmationManager (org.wso2.carbon.identity.recovery.confirmation.ResendConfirmationManager)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)2 User (org.wso2.carbon.identity.application.common.model.User)2 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)2 NotificationChannelManagerException (org.wso2.carbon.identity.governance.exceptions.notiification.NotificationChannelManagerException)2 NotificationChannelManager (org.wso2.carbon.identity.governance.service.notification.NotificationChannelManager)2 PolicyViolationException (org.wso2.carbon.identity.mgt.policy.PolicyViolationException)2 Property (org.wso2.carbon.identity.recovery.model.Property)2 UserSelfRegistrationManager (org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager)2