Search in sources :

Example 1 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class SecurityQuestionApiServiceImpl method securityQuestionGet.

@Override
public Response securityQuestionGet(String username, String realm, String tenantDomain) {
    if (IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT) != null) {
        tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    }
    User user = new User();
    user.setUserName(username);
    if (StringUtils.isNotBlank(realm)) {
        user.setUserStoreDomain(realm);
    } else {
        user.setUserStoreDomain(UserStoreConfigConstants.PRIMARY);
    }
    if (StringUtils.isBlank(tenantDomain)) {
        user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    } else {
        user.setTenantDomain(tenantDomain);
    }
    int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
    if (StringUtils.isBlank(realm)) {
        String[] userList = RecoveryUtil.getUserList(tenantId, username);
        if (ArrayUtils.isEmpty(userList)) {
            String msg = "Unable to find an user with username: " + username + " in the system.";
            LOG.error(msg);
        } else if (userList.length == 1) {
            user.setUserStoreDomain(IdentityUtil.extractDomainFromName(userList[0]));
        } else {
            String msg = "There are multiple users with username: " + username + " in the system, " + "please send the correct user-store domain along with the username.";
            LOG.error(msg);
            RecoveryUtil.handleBadRequest(msg, Constants.ERROR_CODE_MULTIPLE_USERS_MATCHING);
        }
    }
    InitiateQuestionResponseDTO initiateQuestionResponseDTO = null;
    SecurityQuestionPasswordRecoveryManager securityQuestionBasedPwdRecoveryManager = RecoveryUtil.getSecurityQuestionBasedPwdRecoveryManager();
    try {
        ChallengeQuestionResponse challengeQuestionResponse = securityQuestionBasedPwdRecoveryManager.initiateUserChallengeQuestion(user);
        initiateQuestionResponseDTO = RecoveryUtil.getInitiateQuestionResponseDTO(challengeQuestionResponse);
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while initiating password recovery flow using security questions ", e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_CHALLENGE_QUESTION_NOT_FOUND.getCode().equals(e.getErrorCode())) {
            return Response.noContent().build();
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.accepted(initiateQuestionResponseDTO).build();
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) ChallengeQuestionResponse(org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) InitiateQuestionResponseDTO(org.wso2.carbon.identity.recovery.endpoint.dto.InitiateQuestionResponseDTO) SecurityQuestionPasswordRecoveryManager(org.wso2.carbon.identity.recovery.password.SecurityQuestionPasswordRecoveryManager) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 2 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class SetPasswordApiServiceImpl method setPasswordPost.

@Override
public Response setPasswordPost(ResetPasswordRequestDTO resetPasswordRequest) {
    NotificationPasswordRecoveryManager notificationPasswordRecoveryManager = RecoveryUtil.getNotificationBasedPwdRecoveryManager();
    User user = null;
    try {
        user = notificationPasswordRecoveryManager.updateUserPassword(resetPasswordRequest.getKey(), resetPasswordRequest.getPassword(), RecoveryUtil.getProperties(resetPasswordRequest.getProperties()));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while resetting password ", e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_HISTORY_VIOLATE.getCode().equals(e.getErrorCode())) {
            RetryErrorDTO errorDTO = new RetryErrorDTO();
            errorDTO.setCode(e.getErrorCode());
            errorDTO.setMessage(e.getMessage());
            errorDTO.setDescription(e.getMessage());
            errorDTO.setKey(resetPasswordRequest.getKey());
            return Response.status(Response.Status.PRECONDITION_FAILED).entity(errorDTO).build();
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.ok(RecoveryUtil.getUserDTO(user)).build();
}
Also used : NotificationPasswordRecoveryManager(org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager) RetryErrorDTO(org.wso2.carbon.identity.recovery.endpoint.dto.RetryErrorDTO) User(org.wso2.carbon.identity.application.common.model.User) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 3 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class ValidateAnswerApiServiceImpl method validateAnswerPost.

@Override
public Response validateAnswerPost(AnswerVerificationRequestDTO answerVerificationRequest) {
    SecurityQuestionPasswordRecoveryManager securityQuestionBasedPwdRecoveryManager = RecoveryUtil.getSecurityQuestionBasedPwdRecoveryManager();
    ChallengeQuestionResponse challengeQuestion = null;
    try {
        challengeQuestion = securityQuestionBasedPwdRecoveryManager.validateUserChallengeQuestions(RecoveryUtil.getUserChallengeAnswers(answerVerificationRequest.getAnswers()), answerVerificationRequest.getKey(), RecoveryUtil.getProperties(answerVerificationRequest.getProperties()));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while verifying challenge answers in recovery flow", e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_ANSWER_FOR_SECURITY_QUESTION.getCode().equals(e.getErrorCode())) {
            RetryErrorDTO errorDTO = new RetryErrorDTO();
            errorDTO.setCode(e.getErrorCode());
            errorDTO.setMessage(e.getMessage());
            errorDTO.setDescription(e.getMessage());
            errorDTO.setKey(answerVerificationRequest.getKey());
            return Response.status(Response.Status.PRECONDITION_FAILED).entity(errorDTO).build();
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.ok(RecoveryUtil.getInitiateQuestionResponseDTO(challengeQuestion)).build();
}
Also used : RetryErrorDTO(org.wso2.carbon.identity.recovery.endpoint.dto.RetryErrorDTO) ChallengeQuestionResponse(org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) SecurityQuestionPasswordRecoveryManager(org.wso2.carbon.identity.recovery.password.SecurityQuestionPasswordRecoveryManager) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 4 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class SecurityQuestionApiServiceImplTest method testIdentityRecoveryClientExceptionforSecurityQuestionGet.

@Test
public void testIdentityRecoveryClientExceptionforSecurityQuestionGet() throws IdentityRecoveryException {
    mockClasses();
    Mockito.when(securityQuestionPasswordRecoveryManager.initiateUserChallengeQuestion(any(User.class))).thenThrow(new IdentityRecoveryClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_CHALLENGE_QUESTION_NOT_FOUND.getCode(), ""));
    assertNotNull(securityQuestionApiService.securityQuestionGet("admin", null, null));
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException) Test(org.testng.annotations.Test)

Example 5 with IdentityRecoveryClientException

use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.

the class IntrospectCodeApiServiceImpl method introspectCodePost.

@Override
public Response introspectCodePost(CodeValidationRequestDTO codeValidationRequestDTO) {
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    CodeValidateInfoResponseDTO codeDetails = null;
    UserRecoveryData recoveryData = null;
    try {
        // Get the map of properties in the request.
        HashMap<String, String> propertyMap = Utils.getPropertiesMap(codeValidationRequestDTO.getProperties());
        // Get externally verified channel information.
        VerifiedChannelDTO verifiedChannelDTO = codeValidationRequestDTO.getVerifiedChannel();
        String verifiedChannelType = null;
        String verifiedChannelClaim = null;
        // Handling verified channel details not in the request.
        if (verifiedChannelDTO != null) {
            verifiedChannelClaim = verifiedChannelDTO.getClaim();
            verifiedChannelType = verifiedChannelDTO.getType();
        }
        // Confirm code.
        recoveryData = userSelfRegistrationManager.introspectUserSelfRegistration(true, codeValidationRequestDTO.getCode(), verifiedChannelType, verifiedChannelClaim, propertyMap);
        if (recoveryData != null && recoveryData.getUser() != null && recoveryData.getUser().getUserName() != null) {
            codeDetails = getCodeIntrospectResponse(recoveryData);
        } else {
            Utils.handleNotFound(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CODE.getMessage(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CODE.getCode());
        }
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while confirming sent in code", e);
        }
        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 Response.accepted(codeDetails).build();
}
Also used : UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) CodeValidateInfoResponseDTO(org.wso2.carbon.identity.user.endpoint.dto.CodeValidateInfoResponseDTO) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) 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