Search in sources :

Example 1 with APICall

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall in project identity-api-user by wso2.

the class RecoveryUtil method buildRetryPasswordResetObject.

/**
 * Returns a new PreconditionFailedException.
 *
 * @param className     Class name
 * @param tenantDomain  Tenant domain
 * @param description   Description of the exception
 * @param code          Error code
 * @param resetCode     Reset code given to the user by confirmation API
 * @param correlationId Correlation Id
 * @return A new PreconditionFailedException with the specified details as a response
 */
private static PreconditionFailedException buildRetryPasswordResetObject(String className, String tenantDomain, String description, String code, String resetCode, String correlationId) {
    // Build next API calls.
    ArrayList<APICall> apiCallsArrayList = new ArrayList<>();
    apiCallsArrayList.add(RecoveryUtil.buildApiCall(Constants.APICall.RESET_PASSWORD_API.getType(), Constants.RelationStates.NEXT_REL, buildURIForBody(tenantDomain, Constants.APICall.RESET_PASSWORD_API.getApiUrl(), Constants.ACCOUNT_RECOVERY_ENDPOINT_BASEPATH), null));
    RetryErrorResponse retryErrorResponse = buildRetryErrorResponse(Constants.STATUS_PRECONDITION_FAILED_MESSAGE_DEFAULT, code, description, resetCode, correlationId, apiCallsArrayList);
    if (StringUtils.isNotBlank(className)) {
        description = String.format("%s : %s - %s", LOG_MESSAGE_PREFIX, className, description);
    }
    log.error(description);
    return new PreconditionFailedException(retryErrorResponse);
}
Also used : APICall(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall) ArrayList(java.util.ArrayList) RetryErrorResponse(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RetryErrorResponse) PreconditionFailedException(org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.exceptions.PreconditionFailedException)

Example 2 with APICall

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall 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 3 with APICall

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall in project identity-api-user by wso2.

the class PasswordRecoveryService method buildAccountRecoveryType.

/**
 * Build recovery information for recover with notifications.
 *
 * @param recoveryType               Recovery type
 * @param recoveryChannelInformation RecoveryChannelInformation which wraps recovery channel information
 * @param apiCallsArrayList          Available API calls
 * @return AccountRecoveryType which wraps recovery options available for the user
 */
private AccountRecoveryType buildAccountRecoveryType(String recoveryType, RecoveryChannelInformation recoveryChannelInformation, ArrayList<APICall> apiCallsArrayList) {
    AccountRecoveryType accountRecoveryType = new AccountRecoveryType();
    accountRecoveryType.setMode(recoveryType);
    accountRecoveryType.setChannelInfo(recoveryChannelInformation);
    accountRecoveryType.setLinks(apiCallsArrayList);
    return accountRecoveryType;
}
Also used : AccountRecoveryType(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType)

Example 4 with APICall

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall in project identity-api-user by wso2.

the class PasswordRecoveryService method buildPasswordRecoveryInternalResponse.

/**
 * Build PasswordRecoveryInternalNotifyResponse for successful password recovery.
 *
 * @param passwordRecoverDTO {@link PasswordRecoverDTO}PasswordRecoverDTO object
 * @param apiCallsArrayList  List of available API calls
 * @return {@link PasswordRecoveryInternalNotifyResponse}
 */
private PasswordRecoveryInternalNotifyResponse buildPasswordRecoveryInternalResponse(PasswordRecoverDTO passwordRecoverDTO, ArrayList<APICall> apiCallsArrayList) {
    PasswordRecoveryInternalNotifyResponse passwordRecoveryResponse = new PasswordRecoveryInternalNotifyResponse();
    passwordRecoveryResponse.setCode(passwordRecoverDTO.getCode());
    passwordRecoveryResponse.setMessage(passwordRecoverDTO.getMessage());
    passwordRecoveryResponse.setNotificationChannel(passwordRecoverDTO.getNotificationChannel());
    passwordRecoveryResponse.setLinks(apiCallsArrayList);
    passwordRecoveryResponse.setResendCode(passwordRecoverDTO.getResendCode());
    return passwordRecoveryResponse;
}
Also used : PasswordRecoveryInternalNotifyResponse(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.PasswordRecoveryInternalNotifyResponse)

Example 5 with APICall

use of org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall in project identity-api-user by wso2.

the class PasswordRecoveryService method buildPasswordRecoveryInitResponse.

/**
 * Build a list of account recovery options available for a successful password recovery.
 *
 * @param tenantDomain           Tenant domain
 * @param recoveryInformationDTO RecoveryInformationDTO which wraps the password recovery information
 * @return List of {@link AccountRecoveryType}
 */
private List<AccountRecoveryType> buildPasswordRecoveryInitResponse(String tenantDomain, RecoveryInformationDTO recoveryInformationDTO) {
    ArrayList<AccountRecoveryType> accountRecoveryTypes = new ArrayList<>();
    boolean isNotificationBasedRecoveryEnabled = recoveryInformationDTO.isNotificationBasedRecoveryEnabled();
    boolean isQuestionBasedRecoveryAllowedForUser = recoveryInformationDTO.isQuestionBasedRecoveryAllowedForUser();
    if (isNotificationBasedRecoveryEnabled) {
        // Build next API calls list.
        ArrayList<APICall> apiCallsArrayList = new ArrayList<>();
        apiCallsArrayList.add(RecoveryUtil.buildApiCall(Constants.APICall.RECOVER_PASSWORD_API.getType(), Constants.RelationStates.NEXT_REL, RecoveryUtil.buildURIForBody(tenantDomain, Constants.APICall.RECOVER_PASSWORD_API.getApiUrl(), Constants.ACCOUNT_RECOVERY_ENDPOINT_BASEPATH), null));
        RecoveryChannelInformation recoveryChannelInformation = buildRecoveryChannelInformation(recoveryInformationDTO);
        // Build recovery information for recover with notifications.
        AccountRecoveryType accountRecoveryType = buildAccountRecoveryType(Constants.RECOVERY_WITH_NOTIFICATIONS, recoveryChannelInformation, apiCallsArrayList);
        accountRecoveryTypes.add(accountRecoveryType);
    }
    if (isQuestionBasedRecoveryAllowedForUser) {
        // Build next API calls list.
        ArrayList<APICall> apiCallsArrayList = new ArrayList<>();
        apiCallsArrayList.add(RecoveryUtil.buildApiCall(Constants.APICall.RECOVER_WITH_SECURITY_QUESTIONS_API.getType(), Constants.RelationStates.NEXT_REL, RecoveryUtil.buildURIForBody(tenantDomain, Constants.APICall.RECOVER_WITH_SECURITY_QUESTIONS_API.getApiUrl(), Constants.CHALLENGE_QUESTIONS_ENDPOINT_BASEPATH), recoveryInformationDTO.getUsername()));
        // Build recovery information for recover with security questions.
        AccountRecoveryType accountRecoveryType = buildAccountRecoveryType(Constants.RECOVER_WITH_CHALLENGE_QUESTIONS, null, apiCallsArrayList);
        accountRecoveryTypes.add(accountRecoveryType);
    }
    return accountRecoveryTypes;
}
Also used : AccountRecoveryType(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType) RecoveryChannelInformation(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannelInformation) APICall(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall) ArrayList(java.util.ArrayList)

Aggregations

APICall (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall)6 ArrayList (java.util.ArrayList)5 AccountRecoveryType (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType)3 RecoveryChannelInformation (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannelInformation)2 RetryErrorResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RetryErrorResponse)2 RecoveryChannelInfoDTO (org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)1 PreconditionFailedException (org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.exceptions.PreconditionFailedException)1 PasswordRecoveryExternalNotifyResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.PasswordRecoveryExternalNotifyResponse)1 PasswordRecoveryInternalNotifyResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.PasswordRecoveryInternalNotifyResponse)1 RecoveryChannel (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel)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 ResetCodeResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ResetCodeResponse)1