Search in sources :

Example 1 with NotificationChannelDTO

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

the class UserAccountRecoveryManagerTest method testGetSelfSignUpUsers.

/**
 * Test recovery data for self registered users with verified notification channels.
 *
 * @throws Exception Error while getting recovery information
 */
private void testGetSelfSignUpUsers() throws Exception {
    when(userStoreManager.getUserClaimValues(anyString(), ArgumentMatchers.any(String[].class), isNull())).thenReturn(userClaims);
    RecoveryChannelInfoDTO recoveryChannelInfoDTO = userAccountRecoveryManager.retrieveUserRecoveryInformation(userClaims, StringUtils.EMPTY, RecoveryScenarios.USERNAME_RECOVERY, null);
    assertNotNull(recoveryChannelInfoDTO, "Recovery Information for user : ");
    assertEquals(recoveryChannelInfoDTO.getUsername(), UserProfile.USERNAME.getValue(), "Notifications Externally managed scenario. Recovered username : ");
    assertNotNull(recoveryChannelInfoDTO.getRecoveryCode(), "Notifications Externally managed scenario. RecoveryCode : ");
    NotificationChannelDTO[] notificationChannelDTOS = recoveryChannelInfoDTO.getNotificationChannelDTOs();
    assertEquals(notificationChannelDTOS.length, 2, "Notifications Externally managed scenario. Available recovery channels");
    checkMaskedRecoveryValues(notificationChannelDTOS);
}
Also used : NotificationChannelDTO(org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO) RecoveryChannelInfoDTO(org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)

Example 2 with NotificationChannelDTO

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

the class UserAccountRecoveryManagerTest method testGetUserWithNotificationsExternallyManaged.

/**
 * Test notifications externally managed scenario.
 *
 * @throws Exception Error while getting user recovery data
 */
private void testGetUserWithNotificationsExternallyManaged() throws Exception {
    mockGetUserList(new String[] { UserProfile.USERNAME.getValue() });
    mockRecoveryConfigs(false);
    mockJDBCRecoveryDataStore();
    mockIdentityEventService();
    mockBuildUser();
    RecoveryChannelInfoDTO recoveryChannelInfoDTO = userAccountRecoveryManager.retrieveUserRecoveryInformation(userClaims, StringUtils.EMPTY, RecoveryScenarios.USERNAME_RECOVERY, null);
    assertEquals(recoveryChannelInfoDTO.getUsername(), UserProfile.USERNAME.getValue(), "Notifications Externally managed scenario. Recovered username : ");
    assertNotNull(recoveryChannelInfoDTO.getRecoveryCode(), "Notifications Externally managed scenario. RecoveryCode : ");
    NotificationChannelDTO[] notificationChannelDTOS = recoveryChannelInfoDTO.getNotificationChannelDTOs();
    assertEquals(notificationChannelDTOS.length, 1, "Notifications Externally managed scenario. Available recovery channels");
    assertEquals(notificationChannelDTOS[0].getType(), NotificationChannels.EXTERNAL_CHANNEL.getChannelType(), "Notification channel : ");
}
Also used : NotificationChannelDTO(org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO) RecoveryChannelInfoDTO(org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)

Example 3 with NotificationChannelDTO

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

the class UserAccountRecoveryManager method buildUserRecoveryInformationResponseDTO.

/**
 * Prepare the response to be sent to the recovery APIs.
 *
 * @param username                Username of the user
 * @param recoveryCode            Recovery code given to the user
 * @param notificationChannelDTOs List of NotificationChannelsResponseDTOs available for the user.
 * @return RecoveryChannelInfoDTO object.
 */
private RecoveryChannelInfoDTO buildUserRecoveryInformationResponseDTO(String username, String recoveryCode, NotificationChannelDTO[] notificationChannelDTOs) {
    RecoveryChannelInfoDTO recoveryChannelInfoDTO = new RecoveryChannelInfoDTO();
    recoveryChannelInfoDTO.setUsername(username);
    recoveryChannelInfoDTO.setRecoveryCode(recoveryCode);
    recoveryChannelInfoDTO.setNotificationChannelDTOs(notificationChannelDTOs);
    return recoveryChannelInfoDTO;
}
Also used : RecoveryChannelInfoDTO(org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)

Example 4 with NotificationChannelDTO

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

the class UserAccountRecoveryManager method buildNotificationChannelsResponseDTO.

/**
 * Set notification channel details for each communication channels available for the user.
 *
 * @param channelId    Channel Id
 * @param channelType  Channel Type (Eg: EMAIL)
 * @param value        Channel Value (Eg: wso2@gmail.com)
 * @param preference   Whether user marked the channel as a preferred channel of communication
 * @param tenantDomain Tenant domain
 * @return NotificationChannelDTO object.
 * @throws IdentityRecoveryServerException IdentityRecoveryServerException
 */
private NotificationChannelDTO buildNotificationChannelsResponseDTO(int channelId, String channelType, String value, boolean preference, String tenantDomain) throws IdentityRecoveryServerException {
    NotificationChannelDTO notificationChannelDTO = new NotificationChannelDTO();
    notificationChannelDTO.setId(channelId);
    notificationChannelDTO.setType(channelType);
    // Encode the channel Values.
    if (NotificationChannels.EMAIL_CHANNEL.getChannelType().equals(channelType)) {
        notificationChannelDTO.setValue(maskEmailAddress(value, tenantDomain));
    } else if (NotificationChannels.SMS_CHANNEL.getChannelType().equals(channelType)) {
        notificationChannelDTO.setValue(maskMobileNumber(value));
    } else {
        notificationChannelDTO.setValue(value);
    }
    notificationChannelDTO.setPreferred(preference);
    return notificationChannelDTO;
}
Also used : NotificationChannelDTO(org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO)

Example 5 with NotificationChannelDTO

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

the class UserAccountRecoveryManager method retrieveUserRecoveryInformation.

/**
 * Initiate the recovery flow for the user with matching claims.
 *
 * @param claims           User claims
 * @param tenantDomain     Tenant domain
 * @param recoveryScenario Recovery scenario
 * @param properties       Meta properties
 * @return RecoveryChannelInfoDTO object.
 */
public RecoveryChannelInfoDTO retrieveUserRecoveryInformation(Map<String, String> claims, String tenantDomain, RecoveryScenarios recoveryScenario, Map<String, String> properties) throws IdentityRecoveryException {
    // Retrieve the user who matches the given set of claims.
    String username = getUsernameByClaims(claims, tenantDomain);
    if (StringUtils.isNotEmpty(username)) {
        User user = Utils.buildUser(username, tenantDomain);
        // If the account is locked or disabled, do not let the user to recover the account.
        checkAccountLockedStatus(user);
        List<NotificationChannel> notificationChannels;
        // Get the notification management mechanism.
        boolean isNotificationsInternallyManaged = Utils.isNotificationsInternallyManaged(tenantDomain, properties);
        /* If the notification is internally managed, then notification channels available for the user needs to
            be retrieved. If external notifications are enabled, external channel list should be returned.*/
        if (isNotificationsInternallyManaged) {
            notificationChannels = getInternalNotificationChannelList(username, tenantDomain, recoveryScenario);
        } else {
            notificationChannels = getExternalNotificationChannelList();
        }
        // Validate whether the user account is eligible for account recovery.
        checkUserValidityForAccountRecovery(user, recoveryScenario, notificationChannels, properties);
        // This flow will be initiated only if the user has any verified channels.
        NotificationChannelDTO[] notificationChannelDTOS = getNotificationChannelsResponseDTOList(tenantDomain, notificationChannels);
        UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
        // Get the existing RESEND_CONFIRMATION_CODE details if there is any.
        UserRecoveryData recoveryDataDO = userRecoveryDataStore.loadWithoutCodeExpiryValidation(user, recoveryScenario, RecoverySteps.RESEND_CONFIRMATION_CODE);
        String recoveryCode = UUIDGenerator.generateUUID();
        String notificationChannelList = getNotificationChannelListForRecovery(notificationChannels);
        /* Check whether the existing confirmation code can be used based on the email confirmation code tolerance
               with the extracted RESEND_CONFIRMATION_CODE details. */
        if (Utils.reIssueExistingConfirmationCode(recoveryDataDO, NotificationChannels.EMAIL_CHANNEL.getChannelType())) {
            /* Update the existing RESEND_CONFIRMATION_CODE details with new code details without changing the
                   time created of the RESEND_CONFIRMATION_CODE. */
            userRecoveryDataStore.invalidateWithoutChangeTimeCreated(recoveryDataDO.getSecret(), recoveryCode, RecoverySteps.SEND_RECOVERY_INFORMATION, notificationChannelList);
        } else {
            addRecoveryDataObject(username, tenantDomain, recoveryCode, recoveryScenario, notificationChannelList);
        }
        return buildUserRecoveryInformationResponseDTO(username, recoveryCode, notificationChannelDTOS);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No valid user found for the given claims");
        }
        throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_NO_USER_FOUND, null);
    }
}
Also used : NotificationChannel(org.wso2.carbon.identity.recovery.model.NotificationChannel) User(org.wso2.carbon.identity.application.common.model.User) NotificationChannelDTO(org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)

Aggregations

NotificationChannelDTO (org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO)7 RecoveryChannelInfoDTO (org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)4 ArrayList (java.util.ArrayList)2 NotificationChannel (org.wso2.carbon.identity.recovery.model.NotificationChannel)2 HashMap (java.util.HashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 User (org.wso2.carbon.identity.application.common.model.User)1 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)1 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)1 RecoveryChannel (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel)1