Search in sources :

Example 16 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class UserSelfRegistrationManagerTest method testResendConfirmationCode.

/**
 * Testing ResendConfirmationCode for user self registration.
 *
 * @param username                             Username
 * @param userstore                            Userstore domain
 * @param tenantDomain                         Tenant domain
 * @param preferredChannel                     Preferred Notification channel
 * @param errorMsg                             Error scenario
 * @param enableInternalNotificationManagement Manage notifications internally
 * @param expectedChannel                      Expected notification channel
 * @throws Exception If an error occurred while testing.
 */
@Test(dataProvider = "userDetailsForResendingAccountConfirmation")
public void testResendConfirmationCode(String username, String userstore, String tenantDomain, String preferredChannel, String errorMsg, String enableInternalNotificationManagement, String expectedChannel) throws Exception {
    // Build recovery user.
    User user = new User();
    user.setUserName(username);
    user.setUserStoreDomain(userstore);
    user.setTenantDomain(tenantDomain);
    UserRecoveryData userRecoveryData = new UserRecoveryData(user, "1234-4567-890", RecoveryScenarios.SELF_SIGN_UP, RecoverySteps.CONFIRM_SIGN_UP);
    // Storing preferred notification channel in remaining set ids.
    userRecoveryData.setRemainingSetIds(preferredChannel);
    mockConfigurations("true", enableInternalNotificationManagement);
    mockJDBCRecoveryDataStore(userRecoveryData);
    mockEmailTrigger();
    NotificationResponseBean responseBean = userSelfRegistrationManager.resendConfirmationCode(user, null);
    assertEquals(responseBean.getNotificationChannel(), expectedChannel, errorMsg);
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 17 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class MeApiServiceImpl method buildSuccessfulAPIResponse.

/**
 * Build response for a successful user self registration.
 *
 * @param notificationResponseBean NotificationResponseBean {@link NotificationResponseBean}
 * @return Response
 */
private Response buildSuccessfulAPIResponse(NotificationResponseBean notificationResponseBean) {
    // Check whether detailed api responses are enabled.
    if (isDetailedResponseBodyEnabled()) {
        String notificationChannel = notificationResponseBean.getNotificationChannel();
        if (NotificationChannels.EXTERNAL_CHANNEL.getChannelType().equals(notificationChannel)) {
            // Handle response when the notifications are externally managed.
            SuccessfulUserCreationExternalResponseDTO successfulUserCreationDTO = buildSuccessResponseForExternalChannel(notificationResponseBean);
            return Response.status(Response.Status.CREATED).entity(successfulUserCreationDTO).build();
        }
        SuccessfulUserCreationDTO successfulUserCreationDTO = buildSuccessResponseForInternalChannels(notificationResponseBean);
        return Response.status(Response.Status.CREATED).entity(successfulUserCreationDTO).build();
    } else {
        if (notificationResponseBean != null) {
            String notificationChannel = notificationResponseBean.getNotificationChannel();
            /*If the notifications are required in the form of legacy response, and notifications are externally
                 managed, the recoveryId should be in the response as text*/
            if (NotificationChannels.EXTERNAL_CHANNEL.getChannelType().equals(notificationChannel)) {
                return Response.status(Response.Status.CREATED).entity(notificationResponseBean.getRecoveryId()).build();
            }
        }
        return Response.status(Response.Status.CREATED).build();
    }
}
Also used : SuccessfulUserCreationDTO(org.wso2.carbon.identity.user.endpoint.dto.SuccessfulUserCreationDTO) SuccessfulUserCreationExternalResponseDTO(org.wso2.carbon.identity.user.endpoint.dto.SuccessfulUserCreationExternalResponseDTO)

Example 18 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class MeApiServiceImpl method mePost.

@Override
public Response mePost(SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO) {
    String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    if (StringUtils.isNotBlank(tenantFromContext)) {
        selfUserRegistrationRequestDTO.getUser().setTenantDomain(tenantFromContext);
    }
    if (selfUserRegistrationRequestDTO != null && StringUtils.isBlank(selfUserRegistrationRequestDTO.getUser().getRealm())) {
        selfUserRegistrationRequestDTO.getUser().setRealm(IdentityUtil.getPrimaryDomainName());
    }
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    NotificationResponseBean notificationResponseBean = null;
    try {
        notificationResponseBean = userSelfRegistrationManager.registerUser(Utils.getUser(selfUserRegistrationRequestDTO.getUser()), selfUserRegistrationRequestDTO.getUser().getPassword(), Utils.getClaims(selfUserRegistrationRequestDTO.getUser().getClaims()), Utils.getProperties(selfUserRegistrationRequestDTO.getProperties()));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while registering self up user ", e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            Utils.handleConflict(e.getMessage(), e.getErrorCode());
        } else {
            Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
        }
    } catch (IdentityRecoveryException e) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return buildSuccessfulAPIResponse(notificationResponseBean);
}
Also used : NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 19 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class MeApiServiceImpl method meResendCodePost.

@Override
public Response meResendCodePost(MeResendCodeRequestDTO meResendCodeRequestDTO) {
    ResendCodeRequestDTO resendCodeRequestDTO = convertToResendCodeRequest(meResendCodeRequestDTO);
    NotificationResponseBean notificationResponseBean = null;
    String recoveryScenario = getRecoveryScenarioFromProperties(resendCodeRequestDTO.getProperties());
    if (!StringUtils.isBlank(recoveryScenario)) {
        notificationResponseBean = doResendConfirmationCode(recoveryScenario, notificationResponseBean, resendCodeRequestDTO);
    }
    if (notificationResponseBean == null) {
        ErrorDTO errorDTO = Utils.getErrorDTO(Constants.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_RECOVERY_SCENARIO.getCode(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_RECOVERY_SCENARIO.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
    }
    return Response.status(Response.Status.CREATED).entity(notificationResponseBean.getKey()).build();
}
Also used : NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) ErrorDTO(org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO) MeResendCodeRequestDTO(org.wso2.carbon.identity.user.endpoint.dto.MeResendCodeRequestDTO) ResendCodeRequestDTO(org.wso2.carbon.identity.user.endpoint.dto.ResendCodeRequestDTO)

Example 20 with NotificationResponseBean

use of org.wso2.carbon.identity.recovery.bean.NotificationResponseBean in project identity-governance by wso2-extensions.

the class ResendCodeApiServiceImpl method resendCodePost.

@Override
public Response resendCodePost(ResendCodeRequestDTO resendCodeRequestDTO) {
    // Remove any empty properties if exists.
    List<PropertyDTO> properties = resendCodeRequestDTO.getProperties();
    properties.removeIf(property -> StringUtils.isEmpty(property.getKey()));
    String tenantFromContext = getTenantDomainFromContext();
    if (StringUtils.isNotBlank(tenantFromContext)) {
        resendCodeRequestDTO.getUser().setTenantDomain(tenantFromContext);
    }
    // Resolve the username using the login attribute when multi attribute login is enabled.
    ResolvedUserResult resolvedUserResult = FrameworkUtils.processMultiAttributeLoginIdentification(resendCodeRequestDTO.getUser().getUsername(), resendCodeRequestDTO.getUser().getTenantDomain());
    if (ResolvedUserResult.UserResolvedStatus.SUCCESS.equals(resolvedUserResult.getResolvedStatus())) {
        resendCodeRequestDTO.getUser().setUsername(resolvedUserResult.getUser().getUsername());
    }
    NotificationResponseBean notificationResponseBean = null;
    String recoveryScenario = getRecoveryScenarioFromProperties(resendCodeRequestDTO.getProperties());
    if (StringUtils.isBlank(recoveryScenario)) {
        notificationResponseBean = doResendConfirmationCodeForSelfSignUp(notificationResponseBean, resendCodeRequestDTO);
    } else {
        notificationResponseBean = doResendConfirmationCode(recoveryScenario, notificationResponseBean, resendCodeRequestDTO);
    }
    if (notificationResponseBean == null) {
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setRef(Utils.getCorrelation());
        errorDTO.setMessage("This service is not yet implemented.");
        return Response.status(Response.Status.NOT_IMPLEMENTED).entity(errorDTO).build();
    }
    // when notifications internally managed key might not be set.
    if (StringUtils.isBlank(notificationResponseBean.getKey())) {
        return Response.status(Response.Status.CREATED).build();
    }
    return Response.status(Response.Status.CREATED).entity(notificationResponseBean.getKey()).build();
}
Also used : NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) ErrorDTO(org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO) ResolvedUserResult(org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult) PropertyDTO(org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO)

Aggregations

NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)15 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)8 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)5 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)4 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)4 SuccessfulUserCreationDTO (org.wso2.carbon.identity.user.endpoint.dto.SuccessfulUserCreationDTO)4 Test (org.testng.annotations.Test)3 ResolvedUserResult (org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult)3 ResendConfirmationManager (org.wso2.carbon.identity.recovery.confirmation.ResendConfirmationManager)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)2 User (org.wso2.carbon.identity.application.common.model.User)2 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)2 NotificationChannelManagerException (org.wso2.carbon.identity.governance.exceptions.notiification.NotificationChannelManagerException)2 NotificationChannelManager (org.wso2.carbon.identity.governance.service.notification.NotificationChannelManager)2 PolicyViolationException (org.wso2.carbon.identity.mgt.policy.PolicyViolationException)2 Property (org.wso2.carbon.identity.recovery.model.Property)2 UserSelfRegistrationManager (org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager)2