Search in sources :

Example 21 with ErrorResponse

use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.

the class BrandingPreferenceApiServiceImpl method addBrandingPreference.

// TODO: Improve API to manage application level & language level theming resources in addition to the tenant level.
@Override
public Response addBrandingPreference(BrandingPreferenceModel brandingPreferenceModel) {
    if (StringUtils.isBlank(brandingPreferenceModel.getType().toString())) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    if (!ORGANIZATION_TYPE.equals(brandingPreferenceModel.getType().toString())) {
        return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Not Implemented.").build();
    }
    if ((!DEFAULT_LOCALE.equals(brandingPreferenceModel.getLocale())) && StringUtils.isNotBlank(brandingPreferenceModel.getLocale())) {
        return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Not Implemented.").build();
    }
    BrandingPreferenceModel createdBrandingPreferenceModel = brandingPreferenceManagementService.addBrandingPreference(brandingPreferenceModel);
    URI location = null;
    try {
        location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + BRANDING_PREFERENCE_CONTEXT_PATH + QUERY_PARAM_INDICATOR + URLEncoder.encode(String.format(GET_PREFERENCE_COMPONENT_WITH_QUERY_PARAM, ORGANIZATION_TYPE, getTenantDomainFromContext(), DEFAULT_LOCALE), StandardCharsets.UTF_8.name()));
    } catch (UnsupportedEncodingException e) {
        ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build();
        throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse);
    }
    return Response.created(location).entity(createdBrandingPreferenceModel).build();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) BrandingPreferenceModel(org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingPreferenceModel) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) URI(java.net.URI) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 22 with ErrorResponse

use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.

the class ServerAuthenticatorManagementService method handleApplicationMgtException.

/**
 * Handle IdentityApplicationManagementException, extract error code, error description and status code to be sent
 * in the response.
 *
 * @param e         IdentityApplicationManagementException
 * @param errorEnum Error information.
 * @return APIError.
 */
private APIError handleApplicationMgtException(IdentityApplicationManagementException e, Constants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof IdentityApplicationManagementClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof IdentityApplicationManagementServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).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) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 23 with ErrorResponse

use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.

the class ServerAuthenticatorManagementService method handleNotImplementedCapabilities.

private void handleNotImplementedCapabilities(Integer limit, Integer offset) {
    Constants.ErrorMessage errorEnum = null;
    if (limit != null || offset != null) {
        errorEnum = Constants.ErrorMessage.ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
    }
    if (errorEnum != null) {
        ErrorResponse errorResponse = getErrorBuilder(errorEnum, null).build(log, errorEnum.getDescription());
        Response.Status status = Response.Status.NOT_IMPLEMENTED;
        throw new APIError(status, errorResponse);
    }
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) Constants(org.wso2.carbon.identity.api.server.authenticators.common.Constants) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 24 with ErrorResponse

use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.

the class ServerClaimManagementService method handleException.

private APIError handleException(Exception e, Constant.ErrorMessage errorEnum, String... data) {
    ErrorResponse errorResponse = getErrorBuilder(errorEnum, data).build(LOG, e, buildErrorDescription(errorEnum, data));
    Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
    return new APIError(status, errorResponse);
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 25 with ErrorResponse

use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method handleNotFoundError.

private APIError handleNotFoundError(String resourceId, GovernanceConstants.ErrorMessage errorMessage) {
    Response.Status status = Response.Status.NOT_FOUND;
    ErrorResponse errorResponse = getErrorBuilder(errorMessage, resourceId).build(LOG, errorMessage.getDescription());
    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)

Aggregations

Response (javax.ws.rs.core.Response)53 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)47 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)47 Test (org.testng.annotations.Test)12 Response (feign.Response)11 APIError (org.wso2.carbon.identity.api.user.common.error.APIError)10 ErrorResponse (org.wso2.carbon.identity.api.user.common.error.ErrorResponse)9 ArrayList (java.util.ArrayList)6 DCRMServiceStub (org.wso2.carbon.apimgt.core.auth.DCRMServiceStub)6 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)6 ScopeRegistration (org.wso2.carbon.apimgt.core.auth.ScopeRegistration)6 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)6 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)6 ErrorResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse)6 RetryErrorResponse (org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RetryErrorResponse)6 HashMap (java.util.HashMap)5 UserNameMapper (org.wso2.carbon.apimgt.core.api.UserNameMapper)5 SCIMServiceStub (org.wso2.carbon.apimgt.core.auth.SCIMServiceStub)5 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)5 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)4