Search in sources :

Example 1 with RecoveryChannelInfoDTO

use of org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO 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 RecoveryChannelInfoDTO

use of org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO 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 RecoveryChannelInfoDTO

use of org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO 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 RecoveryChannelInfoDTO

use of org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO 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)

Example 5 with RecoveryChannelInfoDTO

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

the class NotificationUsernameRecoveryManager method verifyUsername.

/**
 * Recovery username of the user who matches the given set of claims.
 *
 * @param claims       User claims
 * @param tenantDomain Tenant domain
 * @param notify       Notify user existence
 * @return Username if notifications are externally managed
 * @throws IdentityRecoveryException Error while recovering the username
 */
public String verifyUsername(UserClaim[] claims, String tenantDomain, Boolean notify) throws IdentityRecoveryException {
    // Resolve Tenant domain.
    if (StringUtils.isBlank(tenantDomain)) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    // Resolve notification internally managed status.
    boolean isNotificationInternallyManaged = isNotificationsInternallyManaged(tenantDomain, notify);
    HashMap<String, String> userClaims = buildUserClaimsMap(claims);
    // Validate the claims.
    if (claims.length < 1) {
        throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_NO_FIELD_FOUND_FOR_USER_RECOVERY, null);
    }
    RecoveryInformationDTO recoveryInformationDTO = initiateUsernameRecovery(userClaims, tenantDomain, isNotificationInternallyManaged);
    /*
        recoveryChannelInfoDTO will be NULL for successful username recovery or when notify user existence in not
        enabled and no user is matched to the given claims.
         */
    if (recoveryInformationDTO == null) {
        return null;
    } else {
        return recoveryInformationDTO.getUsername();
    }
}
Also used : RecoveryInformationDTO(org.wso2.carbon.identity.recovery.dto.RecoveryInformationDTO)

Aggregations

RecoveryChannelInfoDTO (org.wso2.carbon.identity.recovery.dto.RecoveryChannelInfoDTO)7 RecoveryInformationDTO (org.wso2.carbon.identity.recovery.dto.RecoveryInformationDTO)5 NotificationChannelDTO (org.wso2.carbon.identity.recovery.dto.NotificationChannelDTO)4 HashMap (java.util.HashMap)3 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)3 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)3 User (org.wso2.carbon.identity.application.common.model.User)2 UserAccountRecoveryManager (org.wso2.carbon.identity.recovery.internal.service.impl.UserAccountRecoveryManager)2 RecoveryChannel (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannel)2 RecoveryChannelInformation (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryChannelInformation)2 ArrayList (java.util.ArrayList)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)1 NotificationChannel (org.wso2.carbon.identity.recovery.model.NotificationChannel)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 AccountRecoveryType (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType)1