Search in sources :

Example 36 with IdentityRecoveryClientException

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);
}
Also used : IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException) Test(org.testng.annotations.Test)

Example 37 with IdentityRecoveryClientException

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();
}
Also used : NotificationPasswordRecoveryManager(org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) IdentityRecoveryServerException(org.wso2.carbon.identity.recovery.IdentityRecoveryServerException) Property(org.wso2.carbon.identity.recovery.model.Property) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 38 with IdentityRecoveryClientException

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;
}
Also used : NotificationChannels(org.wso2.carbon.identity.governance.service.notification.NotificationChannels)

Example 39 with IdentityRecoveryClientException

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);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

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