Search in sources :

Example 6 with IdentityRecoveryClientException

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

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

the class ClaimsApiServiceImpl method claimsGet.

@Override
public Response claimsGet(String tenantDomain) {
    if (IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT) != null) {
        tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    }
    if (StringUtils.isBlank(tenantDomain)) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    } else if (!RecoveryUtil.isValidTenantDomain(tenantDomain)) {
        RecoveryUtil.handleBadRequest("Invalid tenant domain :" + tenantDomain, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_TENANT.getCode());
    }
    String dialect = IdentityRecoveryConstants.WSO2CARBON_CLAIM_DIALECT;
    NotificationUsernameRecoveryManager notificationBasedUsernameRecoveryManager = RecoveryUtil.getNotificationBasedUsernameRecoveryManager();
    ClaimDTO[] claimDTOs = new ClaimDTO[0];
    try {
        Claim[] userClaims = notificationBasedUsernameRecoveryManager.getIdentitySupportedClaims(dialect, tenantDomain);
        claimDTOs = RecoveryUtil.getClaimDTOs(userClaims);
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while getting all identity claims ", e);
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, null);
    } catch (Throwable throwable) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.ok(claimDTOs).build();
}
Also used : ClaimDTO(org.wso2.carbon.identity.recovery.endpoint.dto.ClaimDTO) NotificationUsernameRecoveryManager(org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) Claim(org.wso2.carbon.user.api.Claim) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 8 with IdentityRecoveryClientException

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

the class ResendCodeApiServiceImplTest method testIdentityRecoveryClientExceptioninResendCodePost.

@Test
public void testIdentityRecoveryClientExceptioninResendCodePost() throws IdentityRecoveryException {
    Mockito.when(userSelfRegistrationManager.resendConfirmationCode(Utils.getUser(resendCodeRequestDTO().getUser()), Utils.getProperties(resendCodeRequestDTO().getProperties()))).thenThrow(new IdentityRecoveryClientException("Recovery Exception"));
    assertEquals(resendCodeApiService.resendCodePost(resendCodeRequestDTO()).getStatus(), 501);
}
Also used : IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException) Test(org.testng.annotations.Test)

Example 9 with IdentityRecoveryClientException

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

the class ValidateCodeApiServiceImplTest method testIdentityRecoveryClientExceptioninResendCodePost.

@Test
public void testIdentityRecoveryClientExceptioninResendCodePost() throws IdentityRecoveryException {
    Mockito.when(userSelfRegistrationManager.getConfirmedSelfRegisteredUser(anyString(), anyString(), anyString(), anyMap())).thenThrow(new IdentityRecoveryClientException("Recovery Exception"));
    assertEquals(validateCodeApiServiceImpl.validateCodePost(createCodeValidationRequestDTO()).getStatus(), 202);
}
Also used : IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException) Test(org.testng.annotations.Test)

Example 10 with IdentityRecoveryClientException

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

the class MeApiServiceImplTest method testIdentityRecoveryClientExceptionInMePost.

@Test
public void testIdentityRecoveryClientExceptionInMePost() throws IdentityRecoveryException {
    Mockito.when(userSelfRegistrationManager.registerUser(any(User.class), anyString(), any(Claim[].class), any(Property[].class))).thenThrow(new IdentityRecoveryClientException("Recovery Exception"));
    assertEquals(meApiService.mePost(selfUserRegistrationRequestDTO()).getStatus(), 201);
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException) Test(org.testng.annotations.Test)

Aggregations

IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)29 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)17 User (org.wso2.carbon.identity.application.common.model.User)11 Test (org.testng.annotations.Test)6 UserSelfRegistrationManager (org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 NotificationPasswordRecoveryManager (org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager)4 HashMap (java.util.HashMap)3 NotificationChannels (org.wso2.carbon.identity.governance.service.notification.NotificationChannels)3 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)3 ChallengeQuestionResponse (org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse)3 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)3 ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)3 UserChallengeAnswer (org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)3 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)3 SecurityQuestionPasswordRecoveryManager (org.wso2.carbon.identity.recovery.password.SecurityQuestionPasswordRecoveryManager)3 IdentityEventClientException (org.wso2.carbon.identity.event.IdentityEventClientException)2 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)2 IdentityEventServerException (org.wso2.carbon.identity.event.IdentityEventServerException)2 RetryErrorDTO (org.wso2.carbon.identity.recovery.endpoint.dto.RetryErrorDTO)2