Search in sources :

Example 1 with PolicyChainBean

use of io.apiman.manager.api.beans.policies.PolicyChainBean in project apiman by apiman.

the class OrganizationResourceImpl method getApiPolicyChain.

/**
 * @see IOrganizationResource#getApiPolicyChain(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public PolicyChainBean getApiPolicyChain(String organizationId, String apiId, String version, String planId) throws ApiVersionNotFoundException, PlanNotFoundException {
    // No permission check is needed, because this would break All APIs UI
    // Try to get the API first - will throw an exception if not found.
    ApiVersionBean avb = getApiVersion(organizationId, apiId, version);
    try {
        String planVersion = null;
        Set<ApiPlanBean> plans = avb.getPlans();
        if (plans != null) {
            for (ApiPlanBean apiPlanBean : plans) {
                if (apiPlanBean.getPlanId().equals(planId)) {
                    planVersion = apiPlanBean.getVersion();
                    break;
                }
            }
        }
        if (planVersion == null) {
            throw ExceptionFactory.planNotFoundException(planId);
        }
        // Hide sensitive data and set only needed data for the UI
        List<PolicySummaryBean> apiPolicies = RestHelper.hideSensitiveDataFromPolicySummaryBeanList(securityContext, query.getPolicies(organizationId, apiId, version, PolicyType.Api));
        List<PolicySummaryBean> planPolicies = RestHelper.hideSensitiveDataFromPolicySummaryBeanList(securityContext, query.getPolicies(organizationId, planId, planVersion, PolicyType.Plan));
        PolicyChainBean chain = new PolicyChainBean();
        chain.getPolicies().addAll(planPolicies);
        chain.getPolicies().addAll(apiPolicies);
        return chain;
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) PolicyChainBean(io.apiman.manager.api.beans.policies.PolicyChainBean)

Example 2 with PolicyChainBean

use of io.apiman.manager.api.beans.policies.PolicyChainBean in project apiman by apiman.

the class ApiService method getApiPolicyChain.

public PolicyChainBean getApiPolicyChain(String organizationId, String apiId, String version, String planId) throws ApiVersionNotFoundException, PlanNotFoundException {
    // Try to get the API first - will throw an exception if not found.
    ApiVersionBean avb = getApiVersionFromStorage(organizationId, apiId, version);
    return tryAction(() -> {
        String planVersion = null;
        Set<ApiPlanBean> plans = avb.getPlans();
        if (plans != null) {
            for (ApiPlanBean apiPlanBean : plans) {
                if (apiPlanBean.getPlanId().equals(planId)) {
                    planVersion = apiPlanBean.getVersion();
                    break;
                }
            }
        }
        if (planVersion == null) {
            throw ExceptionFactory.planNotFoundException(planId);
        }
        // Hide sensitive data and set only needed data for the UI
        List<PolicySummaryBean> apiPolicies = RestHelper.hideSensitiveDataFromPolicySummaryBeanList(securityContext, query.getPolicies(organizationId, apiId, version, PolicyType.Api));
        List<PolicySummaryBean> planPolicies = RestHelper.hideSensitiveDataFromPolicySummaryBeanList(securityContext, query.getPolicies(organizationId, planId, planVersion, PolicyType.Plan));
        PolicyChainBean chain = new PolicyChainBean();
        chain.getPolicies().addAll(planPolicies);
        chain.getPolicies().addAll(apiPolicies);
        return chain;
    });
}
Also used : PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) PolicyChainBean(io.apiman.manager.api.beans.policies.PolicyChainBean)

Aggregations

ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)2 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)2 NewApiVersionBean (io.apiman.manager.api.beans.apis.NewApiVersionBean)2 UpdateApiVersionBean (io.apiman.manager.api.beans.apis.UpdateApiVersionBean)2 PolicyChainBean (io.apiman.manager.api.beans.policies.PolicyChainBean)2 PolicySummaryBean (io.apiman.manager.api.beans.summary.PolicySummaryBean)2 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)1