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);
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations