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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations