use of io.apiman.manager.api.rest.exceptions.PolicyNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method deletePlanPolicy.
/**
* @see IOrganizationResource#deletePlanPolicy(java.lang.String, java.lang.String, java.lang.String, long)
*/
@Override
public void deletePlanPolicy(String organizationId, String planId, String version, long policyId) throws OrganizationNotFoundException, PlanVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.planEdit, organizationId);
// Make sure the plan version exists
PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
if (pvb.getStatus() == PlanStatus.Locked) {
throw ExceptionFactory.invalidPlanStatusException();
}
try {
storage.beginTx();
PolicyBean policy = this.storage.getPolicy(PolicyType.Plan, organizationId, planId, version, policyId);
if (policy == null) {
throw ExceptionFactory.policyNotFoundException(policyId);
}
storage.deletePolicy(policy);
storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Plan, securityContext));
pvb.setModifiedBy(securityContext.getCurrentUser());
pvb.setModifiedOn(new Date());
storage.updatePlanVersion(pvb);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Deleted plan policy %s", policy));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.PolicyNotFoundException 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);
}
}
use of io.apiman.manager.api.rest.exceptions.PolicyNotFoundException 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);
}
}
use of io.apiman.manager.api.rest.exceptions.PolicyNotFoundException 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);
}
}
use of io.apiman.manager.api.rest.exceptions.PolicyNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method deleteApiPolicy.
/**
* @see IOrganizationResource#deleteApiPolicy(java.lang.String, java.lang.String, java.lang.String, long)
*/
@Override
public void deleteApiPolicy(String organizationId, String apiId, String version, long policyId) throws OrganizationNotFoundException, ApiVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
// Make sure the API exists and is in the right status.
ApiVersionBean avb = getApiVersion(organizationId, apiId, version);
if (avb.isPublicAPI()) {
if (avb.getStatus() == ApiStatus.Retired) {
throw ExceptionFactory.invalidApiStatusException();
}
} else {
if (avb.getStatus() == ApiStatus.Published || avb.getStatus() == ApiStatus.Retired) {
throw ExceptionFactory.invalidApiStatusException();
}
}
try {
storage.beginTx();
PolicyBean policy = this.storage.getPolicy(PolicyType.Api, organizationId, apiId, version, policyId);
if (policy == null) {
throw ExceptionFactory.policyNotFoundException(policyId);
}
storage.deletePolicy(policy);
storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Api, securityContext));
avb.setModifiedBy(securityContext.getCurrentUser());
avb.setModifiedOn(new Date());
storage.updateApiVersion(avb);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Deleted API %s policy: %s", apiId, policy));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations