use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class PublicAPIs method getRepository.
@GET
@Path("/api/repository/{id}")
@Produces({ "application/json", "application/xml" })
public VXRepository getRepository(@PathParam("id") Long id) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.getRepository(" + id + ")");
}
RangerService service = serviceREST.getService(id);
VXRepository ret = serviceUtil.toVXRepository(service);
if (logger.isDebugEnabled()) {
logger.debug("<= PublicAPIs.getRepository(" + id + ")");
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class PublicAPIsv2 method updateServiceByName.
@PUT
@Path("/api/service/name/{name}")
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPISpnegoAccessible()")
@Produces({ "application/json", "application/xml" })
public RangerService updateServiceByName(RangerService service, @PathParam("name") String name, @Context HttpServletRequest request) {
// ignore service.id - if specified. Retrieve using the given name and use id from the retrieved object
RangerService existingService = getServiceByName(name);
service.setId(existingService.getId());
if (StringUtils.isEmpty(service.getGuid())) {
service.setGuid(existingService.getGuid());
}
if (StringUtils.isEmpty(service.getName())) {
service.setName(existingService.getName());
}
return serviceREST.updateService(service, request);
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceREST method getServices.
public List<RangerService> getServices(SearchFilter filter) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getServices():");
}
List<RangerService> ret = null;
RangerPerfTracer perf = null;
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServices()");
}
ret = svcStore.getServices(filter);
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getServices() failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getServices(): count=" + (ret == null ? 0 : ret.size()));
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceREST method getService.
@GET
@Path("/services/{id}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_SERVICE + "\")")
public RangerService getService(@PathParam("id") Long id) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getService(" + id + ")");
}
RangerService ret = null;
RangerPerfTracer perf = null;
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getService(serviceId=" + id + ")");
}
ret = svcStore.getService(id);
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getService(" + id + ") failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (ret == null) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, "Not found", true);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getService(" + id + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class ServiceREST method getPoliciesForResource.
@GET
@Path("/policies/{serviceDefName}/for-resource")
@Produces({ "application/json", "application/xml" })
public List<RangerPolicy> getPoliciesForResource(@PathParam("serviceDefName") String serviceDefName, @DefaultValue("") @QueryParam("serviceName") String serviceName, @Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getPoliciesForResource(service-type=" + serviceDefName + ", service-name=" + serviceName + ")");
}
List<RangerPolicy> ret = new ArrayList<>();
List<RangerService> services = new ArrayList<>();
Map<String, Object> resource = new HashMap<>();
String validationMessage = validateResourcePoliciesRequest(serviceDefName, serviceName, request, services, resource);
if (StringUtils.isNotEmpty(validationMessage)) {
LOG.error("Invalid request: [" + validationMessage + "]");
throw restErrorUtil.createRESTException(validationMessage, MessageEnums.INVALID_INPUT_DATA);
} else {
RangerService service = services.get(0);
if (LOG.isDebugEnabled()) {
LOG.debug("getServicePolicies with service-name=" + service.getName());
}
RangerPolicyEngine engine = null;
try {
engine = getPolicySearchPolicyEngine(service.getName());
} catch (Exception e) {
LOG.error("Cannot initialize Policy-Engine", e);
throw restErrorUtil.createRESTException("Cannot initialize Policy Engine", MessageEnums.ERROR_SYSTEM);
}
if (engine != null) {
ret = engine.getMatchingPolicies(new RangerAccessResourceImpl(resource));
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getPoliciesForResource(service-type=" + serviceDefName + ", service-name=" + serviceName + ") : " + ret.toString());
}
return ret;
}
Aggregations