use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class OrganizationResourceImpl method createPlanPolicy.
/**
* @see IOrganizationResource#createPlanPolicy(java.lang.String,
* java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.NewPolicyBean)
*/
@Override
public PolicyBean createPlanPolicy(String organizationId, String planId, String version, NewPolicyBean bean) throws OrganizationNotFoundException, PlanVersionNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.planEdit, organizationId);
// Make sure the plan version exists and is in the right state
PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
if (pvb.getStatus() == PlanStatus.Locked) {
throw ExceptionFactory.invalidPlanStatusException();
}
// $NON-NLS-1$
log.debug(String.format("Creating plan %s policy %s", planId, pvb));
PolicyBean policy = doCreatePolicy(organizationId, planId, version, bean, PolicyType.Plan);
try {
storage.beginTx();
pvb.setModifiedOn(new Date());
pvb.setModifiedBy(securityContext.getCurrentUser());
storage.commitTx();
} catch (Exception e) {
storage.rollbackTx();
log.error(e);
}
return policy;
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class OrganizationResourceImpl method createApiPolicy.
/**
* @see IOrganizationResource#createApiPolicy(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.NewPolicyBean)
*/
@Override
public PolicyBean createApiPolicy(String organizationId, String apiId, String version, NewPolicyBean bean) throws OrganizationNotFoundException, ApiVersionNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
// Make sure the API exists
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();
}
}
PolicyBean policy = doCreatePolicy(organizationId, apiId, version, bean, PolicyType.Api);
// $NON-NLS-1$
log.debug(String.format("Created API policy %s", avb));
try {
storage.beginTx();
avb.setModifiedOn(new Date());
avb.setModifiedBy(securityContext.getCurrentUser());
storage.commitTx();
} catch (Exception e) {
storage.rollbackTx();
log.error(e);
}
return policy;
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class OrganizationResourceImpl method createClientPolicy.
/**
* @see IOrganizationResource#createClientPolicy(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.NewPolicyBean)
*/
@Override
public PolicyBean createClientPolicy(String organizationId, String clientId, String version, NewPolicyBean bean) throws OrganizationNotFoundException, ClientVersionNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
// Make sure the Client exists
ClientVersionBean cvb = getClientVersionInternal(organizationId, clientId, version);
PolicyBean policy = doCreatePolicy(organizationId, clientId, version, bean, PolicyType.Client);
try {
storage.beginTx();
cvb.setModifiedBy(securityContext.getCurrentUser());
cvb.setModifiedOn(new Date());
storage.commitTx();
} catch (Exception e) {
storage.rollbackTx();
log.error(e);
}
return policy;
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class OrganizationResourceImpl method deleteClientPolicy.
/**
* @see IOrganizationResource#deleteClientPolicy(java.lang.String, java.lang.String, java.lang.String, long)
*/
@Override
public void deleteClientPolicy(String organizationId, String clientId, String version, long policyId) 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);
}
storage.deletePolicy(policy);
storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Client, securityContext));
cvb.setModifiedBy(securityContext.getCurrentUser());
cvb.setModifiedOn(new Date());
storage.updateClientVersion(cvb);
storage.commitTx();
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations