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