Search in sources :

Example 1 with UpdatePolicyBean

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

the class OrganizationResourceImpl method updatePlanPolicy.

/**
 * @see IOrganizationResource#updatePlanPolicy(java.lang.String,
 *      java.lang.String, java.lang.String, long, io.apiman.manager.api.beans.policies.UpdatePolicyBean)
 */
@Override
public void updatePlanPolicy(String organizationId, String planId, String version, long policyId, UpdatePolicyBean bean) throws OrganizationNotFoundException, PlanVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.planEdit, organizationId);
    // Make sure the plan version exists
    PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
    try {
        storage.beginTx();
        PolicyBean policy = storage.getPolicy(PolicyType.Plan, organizationId, planId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) {
            policy.setConfiguration(bean.getConfiguration());
        // Note: we do not audit the policy configuration since it may have sensitive data
        }
        policy.setModifiedOn(new Date());
        policy.setModifiedBy(this.securityContext.getCurrentUser());
        storage.updatePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Plan, securityContext));
        pvb.setModifiedBy(securityContext.getCurrentUser());
        pvb.setModifiedOn(new Date());
        storage.updatePlanVersion(pvb);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Updated plan policy %s", 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) 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) Date(java.util.Date) 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) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Example 2 with UpdatePolicyBean

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

the class OrganizationResourceImpl method updateClientPolicy.

/**
 * @see IOrganizationResource#updateClientPolicy(java.lang.String, java.lang.String, java.lang.String, long, io.apiman.manager.api.beans.policies.UpdatePolicyBean)
 */
@Override
public void updateClientPolicy(String organizationId, String clientId, String version, long policyId, UpdatePolicyBean bean) throws OrganizationNotFoundException, ClientVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
    // Make sure the client version exists.
    ClientVersionBean cvb = getClientVersionInternal(organizationId, clientId, version);
    try {
        storage.beginTx();
        PolicyBean policy = this.storage.getPolicy(PolicyType.Client, organizationId, clientId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) {
            policy.setConfiguration(bean.getConfiguration());
        // TODO figure out what changed and include that in the audit entry
        }
        policy.setModifiedOn(new Date());
        policy.setModifiedBy(this.securityContext.getCurrentUser());
        storage.updatePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Client, securityContext));
        cvb.setModifiedOn(new Date());
        cvb.setModifiedBy(securityContext.getCurrentUser());
        storage.updateClientVersion(cvb);
        storage.commitTx();
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) 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) Date(java.util.Date) 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)

Example 3 with UpdatePolicyBean

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

the class OrganizationResourceImpl method updateApiPolicy.

/**
 * @see IOrganizationResource#updateApiPolicy(java.lang.String,
 *      java.lang.String, java.lang.String, long, io.apiman.manager.api.beans.policies.UpdatePolicyBean)
 */
@Override
public void updateApiPolicy(String organizationId, String apiId, String version, long policyId, UpdatePolicyBean bean) throws OrganizationNotFoundException, ApiVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
    // Make sure the API exists
    ApiVersionBean avb = getApiVersion(organizationId, apiId, version);
    try {
        storage.beginTx();
        PolicyBean policy = storage.getPolicy(PolicyType.Api, organizationId, apiId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        // TODO capture specific change values when auditing policy updates
        if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) {
            policy.setConfiguration(bean.getConfiguration());
        }
        policy.setModifiedOn(new Date());
        policy.setModifiedBy(securityContext.getCurrentUser());
        storage.updatePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Api, securityContext));
        avb.setModifiedBy(securityContext.getCurrentUser());
        avb.setModifiedOn(new Date());
        storage.updateApiVersion(avb);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Updated API policy %s", 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) 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) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) Date(java.util.Date) 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)

Example 4 with UpdatePolicyBean

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

the class ClientAppService method updateClientPolicy.

@Transactional
public void updateClientPolicy(String organizationId, String clientId, String version, long policyId, UpdatePolicyBean bean) throws OrganizationNotFoundException, ClientVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    // Make sure the client version exists.
    ClientVersionBean cvb = getClientVersionInternal(organizationId, clientId, version);
    tryAction(() -> {
        PolicyBean policy = this.storage.getPolicy(PolicyType.Client, organizationId, clientId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) {
            policy.setConfiguration(bean.getConfiguration());
        // TODO figure out what changed and include that in the audit entry
        }
        policy.setModifiedOn(new Date());
        policy.setModifiedBy(this.securityContext.getCurrentUser());
        storage.updatePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Client, securityContext));
        cvb.setModifiedOn(new Date());
        cvb.setModifiedBy(securityContext.getCurrentUser());
        storage.updateClientVersion(cvb);
    });
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Example 5 with UpdatePolicyBean

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

the class PlanService method updatePlanPolicy.

public void updatePlanPolicy(String organizationId, String planId, String version, long policyId, UpdatePolicyBean bean) throws OrganizationNotFoundException, PlanVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    // Make sure the plan version exists
    PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
    tryAction(() -> {
        PolicyBean policy = storage.getPolicy(PolicyType.Plan, organizationId, planId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) {
            policy.setConfiguration(bean.getConfiguration());
        // Note: we do not audit the policy configuration since it may have sensitive data
        }
        policy.setModifiedOn(new Date());
        policy.setModifiedBy(this.securityContext.getCurrentUser());
        storage.updatePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Plan, securityContext));
        pvb.setModifiedBy(securityContext.getCurrentUser());
        pvb.setModifiedOn(new Date());
        storage.updatePlanVersion(pvb);
        // $NON-NLS-1$
        LOGGER.debug(String.format("Updated plan policy %s", policy));
    });
}
Also used : PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) Date(java.util.Date) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean)

Aggregations

NewPolicyBean (io.apiman.manager.api.beans.policies.NewPolicyBean)6 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)6 UpdatePolicyBean (io.apiman.manager.api.beans.policies.UpdatePolicyBean)6 Date (java.util.Date)6 StorageException (io.apiman.manager.api.core.exceptions.StorageException)3 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)3 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)3 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)3 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)3 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)3 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)3 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)3 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)3 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)3 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)3 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)3 ContractAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)3 ContractNotFoundException (io.apiman.manager.api.rest.exceptions.ContractNotFoundException)3 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)3 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)3