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