use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class ValidateAnswerApiServiceImplTest method testIdentityRecoveryClientExceptionwithCodeforValidateAnswerPost.
@Test
public void testIdentityRecoveryClientExceptionwithCodeforValidateAnswerPost() throws IdentityRecoveryException {
mockedRecoveryUtil.when(RecoveryUtil::getSecurityQuestionBasedPwdRecoveryManager).thenReturn(securityQuestionPasswordRecoveryManager);
Mockito.when(securityQuestionPasswordRecoveryManager.validateUserChallengeQuestions(isNull(), anyString(), isNull())).thenThrow(new IdentityRecoveryClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_ANSWER_FOR_SECURITY_QUESTION.getCode(), ""));
assertEquals(validateAnswerApiService.validateAnswerPost(buildAnswerVerificationRequestDTO()).getStatus(), 412);
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class PasswordRecoveryManagerImpl method reset.
/**
* Reset the password for password recovery, if the password reset code is valid.
*
* @param resetCode Password reset code
* @param password New password
* @param properties Properties
* @return SuccessfulPasswordResetDTO {@link SuccessfulPasswordResetDTO} object which contain the information
* for a successful password update
* @throws IdentityRecoveryException Error while resetting the password
*/
@Override
public SuccessfulPasswordResetDTO reset(String resetCode, char[] password, Map<String, String> properties) throws IdentityRecoveryException {
// Validate the password.
if (ArrayUtils.isEmpty(password)) {
throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_NO_PASSWORD_IN_REQUEST.getCode(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_NO_PASSWORD_IN_REQUEST.getMessage(), null);
}
String newPassword = String.valueOf(password);
NotificationPasswordRecoveryManager notificationPasswordRecoveryManager = NotificationPasswordRecoveryManager.getInstance();
Property[] metaProperties = buildPropertyList(null, properties);
try {
notificationPasswordRecoveryManager.updatePassword(resetCode, newPassword, metaProperties);
} catch (IdentityRecoveryServerException e) {
String errorCode = Utils.prependOperationScenarioToErrorCode(e.getErrorCode(), IdentityRecoveryConstants.PASSWORD_RECOVERY_SCENARIO);
throw Utils.handleServerException(errorCode, e.getMessage(), null);
} catch (IdentityRecoveryClientException e) {
throw mapClientExceptionWithImprovedErrorCodes(e);
} catch (IdentityEventException e) {
if (log.isDebugEnabled()) {
log.debug("PasswordRecoveryManagerImpl: Error while resetting password ", e);
}
throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED_ERROR_PASSWORD_RESET.getCode(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED_ERROR_PASSWORD_RESET.getMessage(), null);
}
return buildSuccessfulPasswordUpdateDTO();
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class LiteUserRegistrationHandler method isNotificationChannelVerified.
/**
* Checks whether the notification channel is already verified for the user.
*
* @param username Username
* @param tenantDomain Tenant domain
* @param notificationChannel Notification channel
* @param eventProperties Properties related to the event
* @return True if the channel is already verified.
*/
private boolean isNotificationChannelVerified(String username, String tenantDomain, String notificationChannel, Map<String, Object> eventProperties) throws IdentityRecoveryClientException {
boolean isEnableAccountLockForVerifiedPreferredChannelEnabled = Boolean.parseBoolean(IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.ENABLE_ACCOUNT_LOCK_FOR_VERIFIED_PREFERRED_CHANNEL));
if (!isEnableAccountLockForVerifiedPreferredChannelEnabled) {
if (log.isDebugEnabled()) {
String message = String.format("SkipAccountLockOnVerifiedPreferredChannel is enabled for user : %s in domain : %s. " + "Checking whether the user is already verified", username, tenantDomain);
log.debug(message);
}
// Get the notification channel which matches the given channel type.
NotificationChannels channel = getNotificationChannel(username, notificationChannel);
// Get the matching claim uri for the channel.
String verifiedClaimUri = channel.getVerifiedClaimUrl();
// Get the verified status for given channel.
boolean notificationChannelVerified = Boolean.parseBoolean((String) eventProperties.get(verifiedClaimUri));
if (notificationChannelVerified) {
if (log.isDebugEnabled()) {
String message = String.format("Preferred Notification channel : %1$s is verified for the user : %2$s " + "in domain : %3$s. Therefore, no notifications will be sent.", notificationChannel, username, tenantDomain);
log.debug(message);
}
}
return notificationChannelVerified;
}
return false;
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-api-server by wso2.
the class ServerChallengeService method handleIdentityRecoveryException.
/**
* Handle IdentityRecoveryException, extract error code, error description and status code to be sent in the
* response
*
* @param e
* @param errorEnum
* @return
*/
private APIError handleIdentityRecoveryException(IdentityRecoveryException e, ChallengeConstant.ErrorMessage errorEnum) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof IdentityRecoveryClientException) {
errorResponse = getErrorBuilder(errorEnum).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(Constants.ERROR_CODE_DELIMITER) ? errorCode : ChallengeConstant.CHALLENGE_QUESTION_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else {
errorResponse = getErrorBuilder(errorEnum).build(log, e, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
Aggregations