Search in sources :

Example 16 with APIError

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

the class ServerIdpManagementService method handleTemplateMgtException.

/**
 * Handle template management exceptions and return related API errors.
 *
 * @param e {@link TemplateManagementException}.
 * @param errorEnum Error message with error code and description.
 * @param data Additional information.
 * @return API error.
 */
private APIError handleTemplateMgtException(TemplateManagementException e, Constants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof TemplateManagementClientException) {
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e.getMessage());
            errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        } else {
            errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof TemplateManagementServerException) {
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
            errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        } else {
            errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        if (e.getErrorCode() != null) {
            errorResponse = getErrorBuilder(e.getErrorCode(), e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
        } else {
            errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
        }
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : IdentityProviderTemplateListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) IdentityProviderListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse) FederatedAuthenticatorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse) Response(javax.ws.rs.core.Response) IdentityProviderResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse) OutboundConnectorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse) ProvisioningResponse(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse) TemplateManagementServerException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) TemplateManagementClientException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 17 with APIError

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

the class KeyStoreService method handleException.

private APIError handleException(KeyStoreConstants.ErrorMessage errorMessage, String data, String description, Response.Status status) {
    ErrorResponse.Builder builder = new ErrorResponse.Builder().withCode(errorMessage.getCode()).withMessage(generateErrorMessage(errorMessage.getMessage(), data)).withDescription(description);
    ErrorResponse errorResponse = builder.build();
    return new APIError(status, errorResponse);
}
Also used : APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 18 with APIError

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

the class UpdateInboundProtocols method apply.

@Override
public void apply(ServiceProvider application, InboundProtocols inboundProtocols) {
    List<InboundAuthenticationRequestConfig> inbounds = new ArrayList<>();
    try {
        if (inboundProtocols.getOidc() != null) {
            inbounds.add(createOAuthInbound(application.getApplicationName(), inboundProtocols.getOidc()));
        }
        if (inboundProtocols.getSaml() != null) {
            inbounds.add(createSAMLInbound(application, inboundProtocols.getSaml()));
        }
        if (inboundProtocols.getWsTrust() != null) {
            inbounds.add(createWsTrustInbound(inboundProtocols.getWsTrust()));
        }
    } catch (APIError error) {
        if (log.isDebugEnabled()) {
            log.debug("Error while adding inbound protocols for application id: " + application.getApplicationResourceId() + ". Cleaning up possible partially created inbound " + "configurations.");
        }
        rollbackInbounds(inbounds);
        throw error;
    }
    if (inboundProtocols.getPassiveSts() != null) {
        inbounds.add(createPassiveSTSInboundConfig(inboundProtocols.getPassiveSts()));
    }
    if (inboundProtocols.getCustom() != null) {
        inboundProtocols.getCustom().forEach(inboundConfigModel -> {
            // TODO Add validate at swagger to make sure inbound key and name are not null.
            InboundAuthenticationRequestConfig inboundRequestConfig = createCustomInbound(inboundConfigModel);
            inbounds.add(inboundRequestConfig);
        });
    }
    InboundAuthenticationConfig inboundAuthConfig = new InboundAuthenticationConfig();
    inboundAuthConfig.setInboundAuthenticationRequestConfigs(inbounds.toArray(new InboundAuthenticationRequestConfig[0]));
    application.setInboundAuthenticationConfig(inboundAuthConfig);
}
Also used : InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) ArrayList(java.util.ArrayList) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) APIError(org.wso2.carbon.identity.api.server.common.error.APIError)

Example 19 with APIError

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

the class BrandingPreferenceManagementService method handleBrandingPreferenceMgtException.

/**
 * Handle branding preference management exceptions and return an API error.
 *
 * @param exception Branding preference management exception
 * @param errorEnum Branding preference management error enum.
 * @param data      Relevant data.
 * @return Processed API Error.
 */
private APIError handleBrandingPreferenceMgtException(BrandingPreferenceMgtException exception, BrandingPreferenceManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (exception instanceof BrandingPreferenceMgtClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, exception.getMessage());
        if (exception.getErrorCode() != null) {
            String errorCode = exception.getErrorCode();
            errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(exception.getMessage());
        if (BRANDING_PREFERENCE_ALREADY_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
            status = Response.Status.CONFLICT;
        } else if (BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
            status = Response.Status.NOT_FOUND;
        } else {
            status = Response.Status.BAD_REQUEST;
        }
    } else if (exception instanceof BrandingPreferenceMgtServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
        if (exception.getErrorCode() != null) {
            String errorCode = exception.getErrorCode();
            errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(exception.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, 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) BrandingPreferenceMgtServerException(org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) BrandingPreferenceMgtClientException(org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtClientException)

Example 20 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError 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)

Aggregations

APIError (org.wso2.carbon.identity.api.server.common.error.APIError)52 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)47 Response (javax.ws.rs.core.Response)41 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)4 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)4 UserStoreListResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)4 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 ErrorMessage (org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage)3 FederatedAuthenticatorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse)3 IdentityProviderListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse)3 IdentityProviderResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse)3 IdentityProviderTemplateListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse)3 OutboundConnectorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse)3 ProvisioningResponse (org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse)3 OwnerResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse)3 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)3 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)3 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)3