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);
}
}
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);
}
}
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);
}
}
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);
});
}
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));
});
}
Aggregations