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