Search in sources :

Example 61 with RangerService

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;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService)

Example 62 with RangerService

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);
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 63 with RangerService

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 64 with RangerService

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 65 with RangerService

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;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerAccessResourceImpl(org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RangerPolicyEngine(org.apache.ranger.plugin.policyengine.RangerPolicyEngine) RangerService(org.apache.ranger.plugin.model.RangerService) VXString(org.apache.ranger.view.VXString) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12