Search in sources :

Example 1 with DCRMServerException

use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException in project identity-inbound-auth-oauth by wso2-extensions.

the class RegisterApiServiceImpl method updateApplication.

@Override
public Response updateApplication(UpdateRequestDTO updateRequest, String clientId) {
    ApplicationDTO applicationDTO = null;
    try {
        Application application = DCRMUtils.getOAuth2DCRMService().updateApplication(DCRMUtils.getApplicationUpdateRequest(updateRequest), clientId);
        applicationDTO = DCRMUtils.getApplicationDTOFromApplication(application);
    } catch (DCRMClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client error while updating application \n" + updateRequest.toString(), e);
        }
        DCRMUtils.handleErrorResponse(e, LOG);
    } catch (DCRMServerException e) {
        DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, e, true, LOG);
    } catch (Throwable throwable) {
        DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, throwable, true, LOG);
    }
    return Response.status(Response.Status.OK).entity(applicationDTO).build();
}
Also used : ApplicationDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ApplicationDTO) DCRMClientException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMClientException) DCRMServerException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException) Application(org.wso2.carbon.identity.oauth.dcr.bean.Application)

Example 2 with DCRMServerException

use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException in project identity-inbound-auth-oauth by wso2-extensions.

the class RegisterApiServiceImpl method registerApplication.

@Override
public Response registerApplication(RegistrationRequestDTO registrationRequest) {
    ApplicationDTO applicationDTO = null;
    try {
        Application application = DCRMUtils.getOAuth2DCRMService().registerApplication(DCRMUtils.getApplicationRegistrationRequest(registrationRequest));
        applicationDTO = DCRMUtils.getApplicationDTOFromApplication(application);
    } catch (DCRMClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client error while registering application \n" + registrationRequest.toString(), e);
        }
        DCRMUtils.handleErrorResponse(e, LOG);
    } catch (DCRMServerException e) {
        DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, e, true, LOG);
    } catch (Throwable throwable) {
        DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, throwable, true, LOG);
    }
    return Response.status(Response.Status.CREATED).entity(applicationDTO).build();
}
Also used : ApplicationDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ApplicationDTO) DCRMClientException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMClientException) DCRMServerException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException) Application(org.wso2.carbon.identity.oauth.dcr.bean.Application)

Example 3 with DCRMServerException

use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException in project identity-inbound-auth-oauth by wso2-extensions.

the class RegisterApiServiceImpl method getApplication.

@Override
public Response getApplication(String clientId) {
    ApplicationDTO applicationDTO = null;
    try {
        Application application = DCRMUtils.getOAuth2DCRMService().getApplication(clientId);
        applicationDTO = DCRMUtils.getApplicationDTOFromApplication(application);
    } catch (DCRMClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client error while retrieving  application with client key:" + clientId, e);
        }
        DCRMUtils.handleErrorResponse(e, LOG);
    } catch (DCRMServerException e) {
        DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, e, true, LOG);
    } catch (Throwable throwable) {
        DCRMUtils.handleErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, throwable, true, LOG);
    }
    return Response.status(Response.Status.OK).entity(applicationDTO).build();
}
Also used : ApplicationDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ApplicationDTO) DCRMClientException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMClientException) DCRMServerException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException) Application(org.wso2.carbon.identity.oauth.dcr.bean.Application)

Example 4 with DCRMServerException

use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException in project identity-inbound-auth-oauth by wso2-extensions.

the class RegisterApiServiceImplTest method testUpdateApplicationServerException.

@Test
public void testUpdateApplicationServerException() throws Exception {
    UpdateRequestDTO updateRequestDTO = new UpdateRequestDTO();
    doThrow(new DCRMServerException("Server")).when(dcrmService).updateApplication(any(ApplicationUpdateRequest.class), any(String.class));
    try {
        registerApiService.updateApplication(updateRequestDTO, validclientId);
    } catch (DCRMEndpointException e) {
        Assert.assertEquals(e.getResponse().getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : DCRMServerException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException) ApplicationUpdateRequest(org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest) UpdateRequestDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.UpdateRequestDTO) DCRMEndpointException(org.wso2.carbon.identity.oauth2.dcr.endpoint.exceptions.DCRMEndpointException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with DCRMServerException

use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRMService method validateRequestTenantDomain.

/**
 * Validates whether the tenant domain in the request matches with the application tenant domain.
 *
 * @param clientId Consumer key of application.
 * @throws DCRMException DCRMException
 */
private void validateRequestTenantDomain(String clientId) throws DCRMException {
    try {
        String tenantDomainOfApp = OAuth2Util.getTenantDomainOfOauthApp(clientId);
        OAuth2Util.validateRequestTenantDomain(tenantDomainOfApp);
    } catch (InvalidOAuthClientException e) {
        throw new DCRMClientException(DCRMConstants.ErrorMessages.TENANT_DOMAIN_MISMATCH.getErrorCode(), String.format(DCRMConstants.ErrorMessages.TENANT_DOMAIN_MISMATCH.getMessage(), clientId));
    } catch (IdentityOAuth2Exception e) {
        throw new DCRMServerException(String.format(DCRMConstants.ErrorMessages.FAILED_TO_VALIDATE_TENANT_DOMAIN.getMessage(), clientId));
    }
}
Also used : DCRMClientException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMClientException) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) DCRMServerException(org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException) InvalidOAuthClientException(org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)

Aggregations

DCRMServerException (org.wso2.carbon.identity.oauth.dcr.exception.DCRMServerException)5 DCRMClientException (org.wso2.carbon.identity.oauth.dcr.exception.DCRMClientException)4 Application (org.wso2.carbon.identity.oauth.dcr.bean.Application)3 ApplicationDTO (org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.ApplicationDTO)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 InvalidOAuthClientException (org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)1 ApplicationUpdateRequest (org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)1 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)1 UpdateRequestDTO (org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.UpdateRequestDTO)1 DCRMEndpointException (org.wso2.carbon.identity.oauth2.dcr.endpoint.exceptions.DCRMEndpointException)1