use of io.apiman.manager.api.rest.exceptions.SystemErrorException in project apiman by apiman.
the class OrganizationResourceImpl method getApiRegistry.
/**
* Gets the API registry.
* @param organizationId
* @param clientId
* @param version
* @throws ClientVersionNotFoundException
*/
private ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws ClientVersionNotFoundException {
// Try to get the client first - will throw a ClientVersionNotFoundException if not found.
ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version);
Map<String, IGatewayLink> gatewayLinks = new HashMap<>();
Map<String, GatewayBean> gateways = new HashMap<>();
boolean txStarted = false;
try {
ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
apiRegistry.setApiKey(clientVersion.getApikey());
List<ApiEntryBean> apis = apiRegistry.getApis();
storage.beginTx();
txStarted = true;
for (ApiEntryBean api : apis) {
String gatewayId = api.getGatewayId();
// Don't return the gateway id.
api.setGatewayId(null);
GatewayBean gateway = gateways.get(gatewayId);
if (gateway == null) {
gateway = storage.getGateway(gatewayId);
gateways.put(gatewayId, gateway);
}
IGatewayLink link = gatewayLinks.get(gatewayId);
if (link == null) {
link = gatewayLinkFactory.create(gateway);
gatewayLinks.put(gatewayId, link);
}
ApiEndpoint se = link.getApiEndpoint(api.getApiOrgId(), api.getApiId(), api.getApiVersion());
String apiEndpoint = se.getEndpoint();
api.setHttpEndpoint(apiEndpoint);
}
return apiRegistry;
} catch (StorageException | GatewayAuthenticationException e) {
throw new SystemErrorException(e);
} finally {
if (txStarted) {
storage.rollbackTx();
}
for (IGatewayLink link : gatewayLinks.values()) {
link.close();
}
}
}
use of io.apiman.manager.api.rest.exceptions.SystemErrorException in project apiman by apiman.
the class OrganizationResourceImpl method revokeAll.
/**
* @see IOrganizationResource#revokeAll(java.lang.String, java.lang.String)
*/
@Override
public void revokeAll(String organizationId, String userId) throws OrganizationNotFoundException, RoleNotFoundException, UserNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.orgAdmin, organizationId);
get(organizationId);
users.get(userId);
MembershipData auditData = new MembershipData();
auditData.setUserId(userId);
// $NON-NLS-1$
auditData.addRole("*");
try {
storage.beginTx();
storage.deleteMemberships(userId, organizationId);
storage.createAuditEntry(AuditUtils.membershipRevoked(organizationId, auditData, securityContext));
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.SystemErrorException in project apiman by apiman.
the class OrganizationResourceImpl method createClient.
/**
* @see IOrganizationResource#createClient(java.lang.String, io.apiman.manager.api.beans.clients.NewClientBean)
*/
@Override
public ClientBean createClient(String organizationId, NewClientBean bean) throws OrganizationNotFoundException, ClientAlreadyExistsException, NotAuthorizedException, InvalidNameException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
FieldValidator.validateName(bean.getName());
ClientBean newClient = new ClientBean();
newClient.setId(BeanUtils.idFromName(bean.getName()));
newClient.setName(bean.getName());
newClient.setDescription(bean.getDescription());
newClient.setCreatedBy(securityContext.getCurrentUser());
newClient.setCreatedOn(new Date());
try {
// Store/persist the new client
storage.beginTx();
OrganizationBean org = getOrganizationFromStorage(organizationId);
newClient.setOrganization(org);
if (storage.getClient(org.getId(), newClient.getId()) != null) {
throw ExceptionFactory.clientAlreadyExistsException(bean.getName());
}
storage.createClient(newClient);
storage.createAuditEntry(AuditUtils.clientCreated(newClient, securityContext));
if (bean.getInitialVersion() != null) {
NewClientVersionBean newClientVersion = new NewClientVersionBean();
newClientVersion.setVersion(bean.getInitialVersion());
createClientVersionInternal(newClientVersion, newClient);
}
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created client %s: %s", newClient.getName(), newClient));
return newClient;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.SystemErrorException in project apiman by apiman.
the class OrganizationResourceImpl method revoke.
/**
* @see IOrganizationResource#revoke(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void revoke(String organizationId, String roleId, String userId) throws OrganizationNotFoundException, RoleNotFoundException, UserNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.orgAdmin, organizationId);
get(organizationId);
users.get(userId);
roles.get(roleId);
MembershipData auditData = new MembershipData();
auditData.setUserId(userId);
try {
storage.beginTx();
storage.deleteMembership(userId, roleId, organizationId);
auditData.addRole(roleId);
storage.createAuditEntry(AuditUtils.membershipRevoked(organizationId, auditData, securityContext));
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Revoked User %s Role %s Org %s", userId, roleId, organizationId));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.SystemErrorException in project apiman by apiman.
the class PolicyDefinitionResourceImpl method create.
/**
* @see IPolicyDefinitionResource#create(io.apiman.manager.api.beans.policies.PolicyDefinitionBean)
*/
@Override
public PolicyDefinitionBean create(PolicyDefinitionBean bean) throws PolicyDefinitionAlreadyExistsException, NotAuthorizedException {
securityContext.checkAdminPermissions();
// Auto-generate an ID if one isn't provided.
if (bean.getId() == null || bean.getId().trim().isEmpty()) {
bean.setId(BeanUtils.idFromName(bean.getName()));
} else {
bean.setId(BeanUtils.idFromName(bean.getId()));
}
try {
storage.beginTx();
if (storage.getPolicyDefinition(bean.getId()) != null) {
throw ExceptionFactory.policyDefAlreadyExistsException(bean.getName());
}
if (bean.getFormType() == null) {
bean.setFormType(PolicyFormType.Default);
}
// Store/persist the new policyDef
storage.createPolicyDefinition(bean);
storage.commitTx();
return bean;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations