Search in sources :

Example 1 with ResendConfirmationDTO

use of org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO in project identity-api-user by wso2.

the class PasswordRecoveryService method buildResendConfirmationResponse.

/**
 * Build Resend confirmation code response according to the notification channel.
 *
 * @param tenantDomain          Tenant domain in the request.
 * @param resendConfirmationDTO ResendConfirmationDTO
 * @return Response
 */
private Response buildResendConfirmationResponse(String tenantDomain, ResendConfirmationDTO resendConfirmationDTO) {
    ArrayList<APICall> apiCallsArrayList = new ArrayList<>();
    // Add confirm API call information.
    apiCallsArrayList.add(RecoveryUtil.buildApiCall(Constants.APICall.CONFIRM_PASSWORD_RECOVERY_API.getType(), Constants.RelationStates.NEXT_REL, RecoveryUtil.buildURIForBody(tenantDomain, Constants.APICall.CONFIRM_PASSWORD_RECOVERY_API.getApiUrl(), Constants.ACCOUNT_RECOVERY_ENDPOINT_BASEPATH), null));
    // Add resend confirmation code API call information.
    apiCallsArrayList.add(RecoveryUtil.buildApiCall(Constants.APICall.RESEND_CONFIRMATION_API.getType(), Constants.RelationStates.RESEND_REL, RecoveryUtil.buildURIForBody(tenantDomain, Constants.APICall.RESEND_CONFIRMATION_API.getApiUrl(), Constants.ACCOUNT_RECOVERY_ENDPOINT_BASEPATH), null));
    if (NotificationChannels.EXTERNAL_CHANNEL.getChannelType().equals(resendConfirmationDTO.getNotificationChannel())) {
        ResendConfirmationCodeExternalResponse resendConfirmationCodeExternalResponse = new ResendConfirmationCodeExternalResponse();
        resendConfirmationCodeExternalResponse.setCode(resendConfirmationDTO.getSuccessCode());
        resendConfirmationCodeExternalResponse.setMessage(resendConfirmationDTO.getSuccessMessage());
        resendConfirmationCodeExternalResponse.setNotificationChannel(resendConfirmationDTO.getNotificationChannel());
        resendConfirmationCodeExternalResponse.setResendCode(resendConfirmationDTO.getResendCode());
        resendConfirmationCodeExternalResponse.setConfirmationCode(resendConfirmationDTO.getExternalConfirmationCode());
        resendConfirmationCodeExternalResponse.setLinks(apiCallsArrayList);
        return Response.ok().entity(resendConfirmationCodeExternalResponse).build();
    } else {
        ResendConfirmationCodeInternalResponse resendConfirmationCodeInternalResponse = new ResendConfirmationCodeInternalResponse();
        resendConfirmationCodeInternalResponse.setCode(resendConfirmationDTO.getSuccessCode());
        resendConfirmationCodeInternalResponse.setMessage(resendConfirmationDTO.getSuccessMessage());
        resendConfirmationCodeInternalResponse.setNotificationChannel(resendConfirmationDTO.getNotificationChannel());
        resendConfirmationCodeInternalResponse.setResendCode(resendConfirmationDTO.getResendCode());
        resendConfirmationCodeInternalResponse.setLinks(apiCallsArrayList);
        return Response.accepted().entity(resendConfirmationCodeInternalResponse).build();
    }
}
Also used : APICall(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall) ArrayList(java.util.ArrayList) ResendConfirmationCodeExternalResponse(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ResendConfirmationCodeExternalResponse) ResendConfirmationCodeInternalResponse(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ResendConfirmationCodeInternalResponse)

Example 2 with ResendConfirmationDTO

use of org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO in project identity-api-user by wso2.

the class PasswordRecoveryService method resendConfirmation.

/**
 * Resend the recovery confirmation code to the user.
 *
 * @param resendConfirmationRequest ResendConfirmationRequest {@link ResendConfirmationRequest} object
 *                                  which wraps the resend request
 * @return Response
 */
public Response resendConfirmation(ResendConfirmationRequest resendConfirmationRequest) {
    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    String resendCode = resendConfirmationRequest.getResendCode();
    Map<String, String> properties = RecoveryUtil.buildPropertiesMap(resendConfirmationRequest.getProperties());
    try {
        ResendConfirmationDTO resendConfirmationDTO = UserAccountRecoveryServiceDataHolder.getPasswordRecoveryManager().resend(tenantDomain, resendCode, properties);
        if (resendConfirmationDTO == null) {
            if (log.isDebugEnabled()) {
                log.debug("No ResendConfirmationDTO data for resend code :" + resendCode);
            }
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        }
        return buildResendConfirmationResponse(tenantDomain, resendConfirmationDTO);
    } catch (IdentityRecoveryClientException e) {
        throw RecoveryUtil.handleClientExceptions(PasswordRecoveryService.class.getName(), tenantDomain, IdentityRecoveryConstants.PASSWORD_RECOVERY_SCENARIO, Util.getCorrelation(), e);
    } catch (IdentityRecoveryException e) {
        throw RecoveryUtil.buildInternalServerErrorResponse(PasswordRecoveryService.class.getName(), Constants.SERVER_ERROR, e.getErrorCode(), Util.getCorrelation(), e);
    }
}
Also used : ResendConfirmationDTO(org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 3 with ResendConfirmationDTO

use of org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO in project identity-governance by wso2-extensions.

the class ResendConfirmationManager method resendConfirmation.

/**
 * Resend confirmation information for the user bound to the resend code. The user will be notified via a channel
 * recovered from the recovery data of the user.
 *
 * @param tenantDomain         Tenant domain
 * @param resendCode           Previously issued confirmation code
 * @param recoveryScenario     Name of the recovery scenario
 *                             {@link org.wso2.carbon.identity.recovery.RecoveryScenarios}
 * @param recoveryStep         Name of the recovery step {@link org.wso2.carbon.identity.recovery.RecoverySteps}
 * @param notificationScenario Notification template name related to the recovery scenario (Eg: org.wso2.carbon
 *                             .identity.recovery.IdentityRecoveryConstants
 *                             .NOTIFICATION_TYPE_RESEND_PASSWORD_RESET
 * @param properties           Meta properties
 * @return ResendConfirmationDTO {@link ResendConfirmationDTO} bean resend operation information
 * @throws IdentityRecoveryException Error while sending confirmation info
 */
public ResendConfirmationDTO resendConfirmation(String tenantDomain, String resendCode, String recoveryScenario, String recoveryStep, String notificationScenario, Property[] properties) throws IdentityRecoveryException {
    RecoverySteps step = RecoverySteps.getRecoveryStep(recoveryStep);
    RecoveryScenarios scenario = RecoveryScenarios.getRecoveryScenario(recoveryScenario);
    UserAccountRecoveryManager userAccountRecoveryManager = UserAccountRecoveryManager.getInstance();
    // Get Recovery data.
    UserRecoveryData userRecoveryData = userAccountRecoveryManager.getUserRecoveryData(resendCode, RecoverySteps.RESEND_CONFIRMATION_CODE);
    User user = userRecoveryData.getUser();
    // Validate the tenant domain and the recovery scenario in the request.
    validateRequestAttributes(user, scenario, userRecoveryData.getRecoveryScenario(), tenantDomain, resendCode);
    validateCallback(properties, user.getTenantDomain());
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    String notificationChannel = validateNotificationChannel(userRecoveryData.getRemainingSetIds());
    String confirmationCode;
    UserRecoveryData confirmationCodeRecoveryData = userRecoveryDataStore.loadWithoutCodeExpiryValidation(user, scenario, step);
    /* Checking whether the existing confirmation code can be used based on the email confirmation code tolerance
           and the existing recovery details. */
    if (Utils.reIssueExistingConfirmationCode(confirmationCodeRecoveryData, notificationChannel)) {
        confirmationCode = confirmationCodeRecoveryData.getSecret();
    } else {
        userRecoveryDataStore.invalidate(user);
        confirmationCode = Utils.generateSecretKey(notificationChannel, user.getTenantDomain(), recoveryScenario);
        // Store new confirmation code.
        addRecoveryDataObject(confirmationCode, notificationChannel, scenario, step, user);
    }
    ResendConfirmationDTO resendConfirmationDTO = new ResendConfirmationDTO();
    // Notification needs to trigger if the notification channel is not equal to EXTERNAL.
    if (!NotificationChannels.EXTERNAL_CHANNEL.getChannelType().equals(notificationChannel)) {
        String eventName = Utils.resolveEventName(notificationChannel);
        triggerNotification(user, notificationChannel, notificationScenario, confirmationCode, eventName, properties);
    } else {
        resendConfirmationDTO.setExternalConfirmationCode(confirmationCode);
    }
    resendCode = generateResendCode(notificationChannel, scenario, userRecoveryData);
    resendConfirmationDTO.setNotificationChannel(notificationChannel);
    resendConfirmationDTO.setResendCode(resendCode);
    resendConfirmationDTO.setSuccessCode(IdentityRecoveryConstants.SuccessEvents.SUCCESS_STATUS_CODE_RESEND_CONFIRMATION_CODE.getCode());
    resendConfirmationDTO.setSuccessMessage(IdentityRecoveryConstants.SuccessEvents.SUCCESS_STATUS_CODE_RESEND_CONFIRMATION_CODE.getMessage());
    return resendConfirmationDTO;
}
Also used : RecoverySteps(org.wso2.carbon.identity.recovery.RecoverySteps) RecoveryScenarios(org.wso2.carbon.identity.recovery.RecoveryScenarios) User(org.wso2.carbon.identity.application.common.model.User) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) ResendConfirmationDTO(org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) UserAccountRecoveryManager(org.wso2.carbon.identity.recovery.internal.service.impl.UserAccountRecoveryManager)

Example 4 with ResendConfirmationDTO

use of org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO in project identity-governance by wso2-extensions.

the class PasswordRecoveryManagerImpl method resend.

/**
 * Resend the password recovery information to the user via user specified channel.
 *
 * @param tenantDomain Tenant Domain
 * @param resendCode   Resend code
 * @param properties   Meta properties
 * @return ResendConfirmationDTO {@link ResendConfirmationDTO} which wraps the information for a successful
 * recovery information resend
 * @throws IdentityRecoveryException Error while sending recovery information
 */
@Override
public ResendConfirmationDTO resend(String tenantDomain, String resendCode, Map<String, String> properties) throws IdentityRecoveryException {
    validateTenantDomain(tenantDomain);
    Property[] metaProperties = buildPropertyList(null, properties);
    ResendConfirmationManager resendConfirmationManager = ResendConfirmationManager.getInstance();
    try {
        return resendConfirmationManager.resendConfirmation(tenantDomain, resendCode, RecoveryScenarios.NOTIFICATION_BASED_PW_RECOVERY.name(), RecoverySteps.UPDATE_PASSWORD.name(), IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_PASSWORD_RESET, metaProperties);
    } catch (IdentityRecoveryException e) {
        e.setErrorCode(Utils.prependOperationScenarioToErrorCode(e.getErrorCode(), IdentityRecoveryConstants.PASSWORD_RECOVERY_SCENARIO));
        throw e;
    }
}
Also used : IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) ResendConfirmationManager(org.wso2.carbon.identity.recovery.confirmation.ResendConfirmationManager) Property(org.wso2.carbon.identity.recovery.model.Property)

Aggregations

IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)2 ResendConfirmationDTO (org.wso2.carbon.identity.recovery.dto.ResendConfirmationDTO)2 ArrayList (java.util.ArrayList)1 User (org.wso2.carbon.identity.application.common.model.User)1 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)1 RecoveryScenarios (org.wso2.carbon.identity.recovery.RecoveryScenarios)1 RecoverySteps (org.wso2.carbon.identity.recovery.RecoverySteps)1 ResendConfirmationManager (org.wso2.carbon.identity.recovery.confirmation.ResendConfirmationManager)1 UserAccountRecoveryManager (org.wso2.carbon.identity.recovery.internal.service.impl.UserAccountRecoveryManager)1 Property (org.wso2.carbon.identity.recovery.model.Property)1 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)1 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)1 APICall (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall)1 ResendConfirmationCodeExternalResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ResendConfirmationCodeExternalResponse)1 ResendConfirmationCodeInternalResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ResendConfirmationCodeInternalResponse)1