Search in sources :

Example 1 with NotificationResponseBean

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

the class RecoverPasswordApiServiceImplTest method testRecoverPasswordPost.

@Test
public void testRecoverPasswordPost() throws IdentityRecoveryException {
    mockedIdentityTenantUtil.when(() -> IdentityTenantUtil.getTenantId(anyString())).thenReturn(-1234);
    mockedRecoveryUtil.when(RecoveryUtil::getNotificationBasedPwdRecoveryManager).thenReturn(notificationPasswordRecoveryManager);
    ResolvedUserResult resolvedUserResult = new ResolvedUserResult(ResolvedUserResult.UserResolvedStatus.FAIL);
    Mockito.when(notificationPasswordRecoveryManager.sendRecoveryNotification(isNull(), anyString(), anyBoolean(), isNull())).thenReturn(notificationResponseBean);
    mockedFrameworkUtils.when(() -> FrameworkUtils.processMultiAttributeLoginIdentification(anyString(), anyString())).thenReturn(resolvedUserResult);
    assertEquals(recoverPasswordApiService.recoverPasswordPost(buildRecoveryInitiatingRequestDTO(), "", true).getStatus(), 202);
}
Also used : ResolvedUserResult(org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult) Test(org.testng.annotations.Test)

Example 2 with NotificationResponseBean

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

the class LiteApiServiceImpl method buildSuccessResponseForInternalChannels.

/**
 * Build the successResponseDTO for successful user identification and channel retrieve when the notifications
 * are managed internally.
 *
 * @param notificationResponseBean NotificationResponseBean
 * @return SuccessfulUserCreationDTO
 */
private SuccessfulUserCreationDTO buildSuccessResponseForInternalChannels(NotificationResponseBean notificationResponseBean) {
    SuccessfulUserCreationDTO successDTO = new SuccessfulUserCreationDTO();
    successDTO.setCode(notificationResponseBean.getCode());
    successDTO.setMessage(notificationResponseBean.getMessage());
    successDTO.setNotificationChannel(notificationResponseBean.getNotificationChannel());
    return successDTO;
}
Also used : SuccessfulUserCreationDTO(org.wso2.carbon.identity.user.endpoint.dto.SuccessfulUserCreationDTO)

Example 3 with NotificationResponseBean

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

the class LiteApiServiceImpl method litePost.

@Override
public Response litePost(LiteUserRegistrationRequestDTO liteUserRegistrationRequestDTO) {
    // reject if username is not present.
    if (liteUserRegistrationRequestDTO == null || (StringUtils.isBlank(liteUserRegistrationRequestDTO.getEmail()) && StringUtils.isBlank(liteUserRegistrationRequestDTO.getMobile()))) {
        Utils.handleBadRequest(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getMessage(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getCode());
    }
    String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    List<PropertyDTO> properties = new ArrayList<>();
    User user = new User();
    user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    user.setUserStoreDomain(IdentityUtil.getPrimaryDomainName());
    user.setUserName(liteUserRegistrationRequestDTO.getEmail());
    PropertyDTO propertyDTO = new PropertyDTO();
    propertyDTO.setKey(IdentityRecoveryConstants.IS_LITE_SIGN_UP);
    propertyDTO.setValue("true");
    properties.add(propertyDTO);
    if (StringUtils.isNotBlank(liteUserRegistrationRequestDTO.getRealm())) {
        user.setUserStoreDomain(liteUserRegistrationRequestDTO.getRealm());
    }
    if (StringUtils.isNotBlank(tenantFromContext)) {
        user.setTenantDomain(tenantFromContext);
    }
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    NotificationResponseBean notificationResponseBean = null;
    properties.addAll(liteUserRegistrationRequestDTO.getProperties());
    try {
        notificationResponseBean = userSelfRegistrationManager.registerLiteUser(user, Utils.getClaims(liteUserRegistrationRequestDTO.getClaims()), Utils.getProperties(properties));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while self registering lite 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 : User(org.wso2.carbon.identity.application.common.model.User) NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) ArrayList(java.util.ArrayList) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 4 with NotificationResponseBean

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

the class LiteApiServiceImpl 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)

Example 5 with NotificationResponseBean

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

the class MeApiServiceImpl method doResendConfirmationCode.

private NotificationResponseBean doResendConfirmationCode(String recoveryScenario, NotificationResponseBean notificationResponseBean, ResendCodeRequestDTO resendCodeRequestDTO) {
    UserRecoveryData userRecoveryData = null;
    // Currently this me/resend-code API supports resend code during mobile verification scenario only.
    if (RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario)) {
        userRecoveryData = Utils.getUserRecoveryData(resendCodeRequestDTO, recoveryScenario);
    }
    if (userRecoveryData == null) {
        return notificationResponseBean;
    }
    ResendConfirmationManager resendConfirmationManager = Utils.getResendConfirmationManager();
    if (RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario) && RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.equals(userRecoveryData.getRecoveryScenario()) && RecoverySteps.VERIFY_MOBILE_NUMBER.equals(userRecoveryData.getRecoveryStep())) {
        notificationResponseBean = setNotificationResponseBean(resendConfirmationManager, RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString(), RecoverySteps.VERIFY_MOBILE_NUMBER.toString(), IdentityRecoveryConstants.NOTIFICATION_TYPE_VERIFY_MOBILE_ON_UPDATE, resendCodeRequestDTO);
    }
    return notificationResponseBean;
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) ResendConfirmationManager(org.wso2.carbon.identity.recovery.confirmation.ResendConfirmationManager)

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