Search in sources :

Example 1 with RecoveryChannel

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

the class RecoveryUtil method buildRecoveryChannelInformation.

/**
 * Build the channel response object list.
 *
 * @param channels Available notification channels list as objects of {@link NotificationChannelDTO}
 * @return List of RecoveryChannels {@link RecoveryChannel}
 */
public static List<RecoveryChannel> buildRecoveryChannelInformation(NotificationChannelDTO[] channels) {
    List<RecoveryChannel> recoveryChannelDTOS = new ArrayList<>();
    if (channels != null) {
        // Create a response object and add the details to each object.
        for (NotificationChannelDTO channel : channels) {
            RecoveryChannel recoveryChannel = new RecoveryChannel();
            recoveryChannel.setId(Integer.toString(channel.getId()));
            recoveryChannel.setType(channel.getType());
            recoveryChannel.setValue(channel.getValue());
            if (StringUtils.isNotEmpty(channel.getValue())) {
                recoveryChannel.setPreferred(channel.isPreferred());
            }
            recoveryChannelDTOS.add(recoveryChannel);
        }
    }
    return recoveryChannelDTOS;
}
Also used : NotificationChannelDTO(org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO) RecoveryChannel(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel) ArrayList(java.util.ArrayList)

Example 2 with RecoveryChannel

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

the class PasswordRecoveryService method buildRecoveryChannelInformation.

/**
 * Method to build recovery channel information.
 *
 * @param recoveryInformationDTO RecoveryInformation with recovery information
 * @return RecoveryChannelInformation
 */
private RecoveryChannelInformation buildRecoveryChannelInformation(RecoveryInformationDTO recoveryInformationDTO) {
    RecoveryChannelInfoDTO recoveryChannelInfoDTO = recoveryInformationDTO.getRecoveryChannelInfoDTO();
    List<RecoveryChannel> channels = RecoveryUtil.buildRecoveryChannelInformation(recoveryChannelInfoDTO.getNotificationChannelDTOs());
    RecoveryChannelInformation recoveryChannelInformation = new RecoveryChannelInformation();
    recoveryChannelInformation.setRecoveryCode(recoveryChannelInfoDTO.getRecoveryCode());
    recoveryChannelInformation.setChannels(channels);
    return recoveryChannelInformation;
}
Also used : RecoveryChannel(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel) RecoveryChannelInformation(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannelInformation) RecoveryChannelInfoDTO(org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)

Example 3 with RecoveryChannel

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

the class UsernameRecoveryService method buildUsernameRecoveryInitResponse.

/**
 * Build a list of account recovery options available for successful user identification and channel retrieval.
 *
 * @param recoveryInformationDTO User recovery information object {@link RecoveryInformationDTO}
 * @param tenantDomain           Tenant domain
 * @return List of {@link AccountRecoveryType}
 */
private List<AccountRecoveryType> buildUsernameRecoveryInitResponse(RecoveryInformationDTO recoveryInformationDTO, String tenantDomain) {
    RecoveryChannelInfoDTO recoveryChannelInfoDTO = recoveryInformationDTO.getRecoveryChannelInfoDTO();
    List<RecoveryChannel> channels = RecoveryUtil.buildRecoveryChannelInformation(recoveryChannelInfoDTO.getNotificationChannelDTOs());
    // Build Recovery Channel Information.
    RecoveryChannelInformation recoveryChannelInformation = new RecoveryChannelInformation();
    recoveryChannelInformation.setRecoveryCode(recoveryChannelInfoDTO.getRecoveryCode());
    recoveryChannelInformation.setChannels(channels);
    // Build next API calls.
    ArrayList<APICall> apiCallsArrayList = new ArrayList<>();
    apiCallsArrayList.add(RecoveryUtil.buildApiCall(Constants.APICall.RECOVER_USERNAME_API.getType(), Constants.RelationStates.NEXT_REL, RecoveryUtil.buildURIForBody(tenantDomain, Constants.APICall.RECOVER_USERNAME_API.getApiUrl(), Constants.ACCOUNT_RECOVERY_ENDPOINT_BASEPATH), null));
    // Build recovery type information.
    AccountRecoveryType accountRecoveryType = new AccountRecoveryType();
    accountRecoveryType.setMode(Constants.RECOVERY_WITH_NOTIFICATIONS);
    accountRecoveryType.setChannelInfo(recoveryChannelInformation);
    accountRecoveryType.setLinks(apiCallsArrayList);
    ArrayList<AccountRecoveryType> recoveryTypeDTOS = new ArrayList<>();
    recoveryTypeDTOS.add(accountRecoveryType);
    return recoveryTypeDTOS;
}
Also used : AccountRecoveryType(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType) RecoveryChannel(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel) RecoveryChannelInformation(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannelInformation) RecoveryChannelInfoDTO(org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO) APICall(org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall) ArrayList(java.util.ArrayList)

Aggregations

RecoveryChannel (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel)3 ArrayList (java.util.ArrayList)2 RecoveryChannelInfoDTO (org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)2 RecoveryChannelInformation (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannelInformation)2 NotificationChannelDTO (org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO)1 APICall (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall)1 AccountRecoveryType (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType)1