Search in sources :

Example 96 with ErrorDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class ScopesApiServiceImplTest method testUpdateScope.

@Test(dataProvider = "BuildUpdateScope")
public void testUpdateScope(Response.Status expectation, Throwable throwable) throws Exception {
    ScopeToUpdateDTO scopeToUpdateDTO = new ScopeToUpdateDTO();
    scopeToUpdateDTO.setDescription("some description");
    scopeToUpdateDTO.setBindings(Collections.<String>emptyList());
    if (Response.Status.OK.equals(expectation)) {
        when(ScopeUtils.getScopeDTO(any(Scope.class))).thenReturn(any(ScopeDTO.class));
        assertEquals(scopesApiService.updateScope(scopeToUpdateDTO, someScopeName).getStatus(), Response.Status.OK.getStatusCode(), "Error occurred while updating scopes");
    } else if (Response.Status.BAD_REQUEST.equals(expectation)) {
        when(oAuth2ScopeService.updateScope(any(Scope.class))).thenThrow(IdentityOAuth2ScopeClientException.class);
        callRealMethod();
        try {
            scopesApiService.updateScope(scopeToUpdateDTO, someScopeName);
        } catch (ScopeEndpointException e) {
            assertEquals(e.getResponse().getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "Cannot find HTTP Response, Bad Request in Case of " + "IdentityOAuth2ScopeClientException");
            assertEquals(((ErrorDTO) (e.getResponse().getEntity())).getMessage(), Response.Status.BAD_REQUEST.getReasonPhrase(), "Cannot find appropriate error message " + "for HTTP Response, Bad Request");
        } finally {
            reset(oAuth2ScopeService);
        }
    } else if (Response.Status.NOT_FOUND.equals(expectation)) {
        ((IdentityOAuth2ScopeException) throwable).setErrorCode(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_NOT_FOUND_SCOPE.getCode());
        when(oAuth2ScopeService.updateScope(any(Scope.class))).thenThrow(throwable);
        callRealMethod();
        try {
            scopesApiService.updateScope(scopeToUpdateDTO, someScopeName);
        } catch (ScopeEndpointException e) {
            assertEquals(e.getResponse().getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Cannot find HTTP Response, Not Found in Case of " + "IdentityOAuth2ScopeClientException");
            assertEquals(((ErrorDTO) (e.getResponse().getEntity())).getMessage(), Response.Status.NOT_FOUND.getReasonPhrase(), "Cannot find appropriate error message " + "for HTTP Response, Not Found");
        } finally {
            reset(oAuth2ScopeService);
        }
    } else if (Response.Status.INTERNAL_SERVER_ERROR.equals(expectation)) {
        when(oAuth2ScopeService.updateScope(any(Scope.class))).thenThrow(IdentityOAuth2ScopeException.class);
        callRealMethod();
        try {
            scopesApiService.updateScope(scopeToUpdateDTO, someScopeName);
        } catch (ScopeEndpointException e) {
            assertEquals(e.getResponse().getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Cannot find HTTP Response, Internal Server Error in case of " + "IdentityOAuth2ScopeException");
            assertNull(e.getResponse().getEntity(), "Do not include error message in case of " + "Server Exception");
        } finally {
            reset(oAuth2ScopeService);
        }
    }
}
Also used : ScopeEndpointException(org.wso2.carbon.identity.oauth.scope.endpoint.exceptions.ScopeEndpointException) Scope(org.wso2.carbon.identity.oauth2.bean.Scope) ScopeDTO(org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO) ErrorDTO(org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO) ScopeToUpdateDTO(org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeToUpdateDTO) IdentityOAuth2ScopeClientException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeClientException) IdentityOAuth2ScopeException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 97 with ErrorDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class ScopeUtilsTest method testGetErrorDTO.

@Test(description = "Testing getErrorDTO")
public void testGetErrorDTO() throws Exception {
    ErrorDTO errorDTOexpected = new ErrorDTO();
    errorDTOexpected.setCode(CODE);
    errorDTOexpected.setMessage(MESSAGE);
    errorDTOexpected.setDescription(DESCRIPTION);
    ErrorDTO errorDTO1 = ScopeUtils.getErrorDTO(MESSAGE, CODE, DESCRIPTION);
    assertEquals(errorDTO1.getCode(), errorDTOexpected.getCode(), "Actual code is not match for expected code");
    assertEquals(errorDTO1.getMessage(), errorDTOexpected.getMessage(), "Actual message is not match for expected message");
    assertEquals(errorDTO1.getDescription(), errorDTOexpected.getDescription(), "Actual description is not match for expected description");
}
Also used : ErrorDTO(org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO) Test(org.testng.annotations.Test)

Example 98 with ErrorDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRMUtils method buildDCRMEndpointException.

private static DCRMEndpointException buildDCRMEndpointException(Response.Status status, String code, String description, boolean isStatusOnly) {
    if (isStatusOnly) {
        return new DCRMEndpointException(status);
    } else {
        String error = DCRMConstants.ErrorCodes.INVALID_CLIENT_METADATA;
        if (code.equals(DCRMConstants.ErrorMessages.BAD_REQUEST_INVALID_REDIRECT_URI.toString())) {
            error = DCRMConstants.ErrorCodes.INVALID_REDIRECT_URI;
        }
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setError(error);
        errorDTO.setErrorDescription(description);
        errorDTO.setRef(getCorrelation());
        return new DCRMEndpointException(status, errorDTO);
    }
}
Also used : ErrorDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ErrorDTO) DCRMEndpointException(org.wso2.carbon.identity.oauth2.dcr.endpoint.exceptions.DCRMEndpointException)

Example 99 with ErrorDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO 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 100 with ErrorDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO 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)

Aggregations

ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)170 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)154 HashMap (java.util.HashMap)109 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)48 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)45 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)40 Map (java.util.Map)29 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)15 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)15 IOException (java.io.IOException)11 Test (org.testng.annotations.Test)11 Application (org.wso2.carbon.apimgt.core.models.Application)11 URI (java.net.URI)10 URISyntaxException (java.net.URISyntaxException)10 ArrayList (java.util.ArrayList)10 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)9 ErrorDTO (org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO)9 Response (javax.ws.rs.core.Response)7 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)7 ErrorDTO (org.wso2.carbon.identity.configuration.mgt.endpoint.dto.ErrorDTO)7