Search in sources :

Example 1 with PolicyDefinitionNotFoundException

use of io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException in project apiman by apiman.

the class PolicyDefinitionResourceImpl method get.

/**
 * @see IPolicyDefinitionResource#get(java.lang.String)
 */
@Override
public PolicyDefinitionBean get(String policyDefinitionId) throws PolicyDefinitionNotFoundException {
    // No permission check is needed
    try {
        storage.beginTx();
        PolicyDefinitionBean bean = storage.getPolicyDefinition(policyDefinitionId);
        if (bean == null) {
            throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId);
        }
        storage.commitTx();
        return bean;
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) UpdatePolicyDefinitionBean(io.apiman.manager.api.beans.policies.UpdatePolicyDefinitionBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PolicyDefinitionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)

Example 2 with PolicyDefinitionNotFoundException

use of io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException in project apiman by apiman.

the class PluginResourceImpl method getPolicyForm.

/**
 * @see IPluginResource#getPolicyForm(java.lang.Long, java.lang.String)
 */
@Override
public String getPolicyForm(Long pluginId, String policyDefId) throws PluginNotFoundException, PluginResourceNotFoundException, PolicyDefinitionNotFoundException {
    // No permission check is needed
    PluginBean pbean;
    PolicyDefinitionBean pdBean;
    try {
        pbean = storage.getPlugin(pluginId);
        if (pbean == null) {
            throw ExceptionFactory.pluginNotFoundException(pluginId);
        }
        pdBean = storage.getPolicyDefinition(policyDefId);
    } catch (AbstractRestException e) {
        throw e;
    } catch (Exception e) {
        throw new SystemErrorException(e);
    }
    PluginCoordinates coordinates = new PluginCoordinates(pbean.getGroupId(), pbean.getArtifactId(), pbean.getVersion(), pbean.getClassifier(), pbean.getType());
    try {
        if (pdBean == null) {
            throw ExceptionFactory.policyDefNotFoundException(policyDefId);
        }
        if (pdBean.getPluginId() == null || !pdBean.getPluginId().equals(pbean.getId())) {
            throw ExceptionFactory.pluginNotFoundException(pluginId);
        }
        if (pdBean.getFormType() == PolicyFormType.JsonSchema && pdBean.getForm() != null) {
            String formPath = pdBean.getForm();
            if (!formPath.startsWith("/")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                formPath = "META-INF/apiman/policyDefs/" + formPath;
            } else {
                formPath = formPath.substring(1);
            }
            Plugin plugin = pluginRegistry.loadPlugin(coordinates);
            PluginClassLoader loader = plugin.getLoader();
            InputStream resource = null;
            try {
                resource = loader.getResourceAsStream(formPath);
                if (resource == null) {
                    throw ExceptionFactory.pluginResourceNotFoundException(formPath, coordinates);
                }
                StringWriter writer = new StringWriter();
                IOUtils.copy(resource, writer);
                return writer.toString();
            } finally {
                IOUtils.closeQuietly(resource);
            }
        } else {
            throw ExceptionFactory.pluginResourceNotFoundException(null, coordinates);
        }
    } catch (AbstractRestException e) {
        throw e;
    } catch (Throwable t) {
        throw new SystemErrorException(t);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) PluginCoordinates(io.apiman.common.plugin.PluginCoordinates) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) NewPluginBean(io.apiman.manager.api.beans.plugins.NewPluginBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) PluginNotFoundException(io.apiman.manager.api.rest.exceptions.PluginNotFoundException) PluginResourceNotFoundException(io.apiman.manager.api.rest.exceptions.PluginResourceNotFoundException) InvalidPluginException(io.apiman.manager.api.core.exceptions.InvalidPluginException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) IOException(java.io.IOException) PluginAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PluginAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) Plugin(io.apiman.common.plugin.Plugin) PluginClassLoader(io.apiman.common.plugin.PluginClassLoader)

Example 3 with PolicyDefinitionNotFoundException

use of io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException in project apiman by apiman.

the class PolicyDefinitionResourceImpl method delete.

/**
 * @see IPolicyDefinitionResource#delete(java.lang.String)
 */
@Override
public void delete(String policyDefinitionId) throws PolicyDefinitionNotFoundException, NotAuthorizedException {
    securityContext.checkAdminPermissions();
    try {
        PolicyDefinitionBean pdb = storage.getPolicyDefinition(policyDefinitionId);
        if (pdb == null) {
            throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId);
        }
        if (pdb.getPluginId() != null) {
            // $NON-NLS-1$
            throw new SystemErrorException(Messages.i18n.format("CannotDeletePluginPolicyDef"));
        }
        storage.deletePolicyDefinition(pdb);
    } catch (AbstractRestException e) {
        throw e;
    } catch (Exception e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) UpdatePolicyDefinitionBean(io.apiman.manager.api.beans.policies.UpdatePolicyDefinitionBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PolicyDefinitionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)

Example 4 with PolicyDefinitionNotFoundException

use of io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException in project apiman by apiman.

the class PolicyDefinitionResourceImpl method update.

/**
 * @see IPolicyDefinitionResource#update(java.lang.String, io.apiman.manager.api.beans.policies.UpdatePolicyDefinitionBean)
 */
@Override
public void update(String policyDefinitionId, UpdatePolicyDefinitionBean bean) throws PolicyDefinitionNotFoundException, NotAuthorizedException {
    securityContext.checkAdminPermissions();
    try {
        PolicyDefinitionBean pdb = storage.getPolicyDefinition(policyDefinitionId);
        if (pdb == null) {
            throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId);
        }
        if (pdb.getPluginId() != null) {
            // $NON-NLS-1$
            throw new SystemErrorException(Messages.i18n.format("CannotUpdatePluginPolicyDef"));
        }
        if (bean.getName() != null)
            pdb.setName(bean.getName());
        if (bean.getDescription() != null)
            pdb.setDescription(bean.getDescription());
        if (bean.getIcon() != null)
            pdb.setIcon(bean.getIcon());
        storage.updatePolicyDefinition(pdb);
    } catch (AbstractRestException e) {
        throw e;
    } catch (Exception e) {
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) UpdatePolicyDefinitionBean(io.apiman.manager.api.beans.policies.UpdatePolicyDefinitionBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PolicyDefinitionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)

Example 5 with PolicyDefinitionNotFoundException

use of io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException in project apiman by apiman.

the class OrganizationResourceImpl method doCreatePolicy.

/**
 * Creates a policy for the given entity (supports creating policies for clients,
 * APIs, and plans).
 *
 * @param organizationId
 * @param entityId
 * @param entityVersion
 * @param bean
 * @return the stored policy bean (with updated information)
 */
private PolicyBean doCreatePolicy(String organizationId, String entityId, String entityVersion, NewPolicyBean bean, PolicyType type) throws PolicyDefinitionNotFoundException {
    if (bean.getDefinitionId() == null) {
        // $NON-NLS-1$
        throw ExceptionFactory.policyDefNotFoundException("null");
    }
    PolicyDefinitionBean def;
    try {
        storage.beginTx();
        def = storage.getPolicyDefinition(bean.getDefinitionId());
        if (def == null) {
            throw ExceptionFactory.policyDefNotFoundException(bean.getDefinitionId());
        }
        storage.rollbackTx();
    } catch (AbstractRestException e) {
        throw e;
    } catch (Exception e) {
        throw new SystemErrorException(e);
    }
    int newIdx;
    try {
        newIdx = query.getMaxPolicyOrderIndex(organizationId, entityId, entityVersion, type) + 1;
    } catch (StorageException e) {
        throw new SystemErrorException(e);
    }
    try {
        PolicyBean policy = new PolicyBean();
        policy.setId(null);
        policy.setDefinition(def);
        policy.setName(def.getName());
        policy.setConfiguration(bean.getConfiguration());
        policy.setCreatedBy(securityContext.getCurrentUser());
        policy.setCreatedOn(new Date());
        policy.setModifiedBy(securityContext.getCurrentUser());
        policy.setModifiedOn(new Date());
        policy.setOrganizationId(organizationId);
        policy.setEntityId(entityId);
        policy.setEntityVersion(entityVersion);
        policy.setType(type);
        policy.setOrderIndex(newIdx);
        storage.beginTx();
        if (type == PolicyType.Client) {
            ClientVersionBean cvb = storage.getClientVersion(organizationId, entityId, entityVersion);
            cvb.setModifiedBy(securityContext.getCurrentUser());
            cvb.setModifiedOn(new Date());
            storage.updateClientVersion(cvb);
        } else if (type == PolicyType.Api) {
            ApiVersionBean avb = storage.getApiVersion(organizationId, entityId, entityVersion);
            avb.setModifiedBy(securityContext.getCurrentUser());
            avb.setModifiedOn(new Date());
            storage.updateApiVersion(avb);
        } else if (type == PolicyType.Plan) {
            PlanVersionBean pvb = storage.getPlanVersion(organizationId, entityId, entityVersion);
            pvb.setModifiedBy(securityContext.getCurrentUser());
            pvb.setModifiedOn(new Date());
            storage.updatePlanVersion(pvb);
        }
        storage.createPolicy(policy);
        storage.createAuditEntry(AuditUtils.policyAdded(policy, type, securityContext));
        storage.commitTx();
        PolicyTemplateUtil.generatePolicyDescription(policy);
        // $NON-NLS-1$
        log.debug(String.format("Created client policy: %s", policy));
        return policy;
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) MalformedURLException(java.net.MalformedURLException) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) Date(java.util.Date) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Aggregations

PolicyDefinitionBean (io.apiman.manager.api.beans.policies.PolicyDefinitionBean)5 StorageException (io.apiman.manager.api.core.exceptions.StorageException)5 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)5 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)5 PolicyDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)5 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)5 UpdatePolicyDefinitionBean (io.apiman.manager.api.beans.policies.UpdatePolicyDefinitionBean)3 PolicyDefinitionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException)2 Plugin (io.apiman.common.plugin.Plugin)1 PluginClassLoader (io.apiman.common.plugin.PluginClassLoader)1 PluginCoordinates (io.apiman.common.plugin.PluginCoordinates)1 ApiEndpoint (io.apiman.gateway.engine.beans.ApiEndpoint)1 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)1 NewApiVersionBean (io.apiman.manager.api.beans.apis.NewApiVersionBean)1 UpdateApiVersionBean (io.apiman.manager.api.beans.apis.UpdateApiVersionBean)1 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)1 NewClientVersionBean (io.apiman.manager.api.beans.clients.NewClientVersionBean)1 NewPlanVersionBean (io.apiman.manager.api.beans.plans.NewPlanVersionBean)1 PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)1 NewPluginBean (io.apiman.manager.api.beans.plugins.NewPluginBean)1