Search in sources :

Example 11 with RangerPolicyList

use of org.apache.ranger.view.RangerPolicyList in project ranger by apache.

the class TestServiceDBStore method test31getPaginatedPolicies.

@Test
public void test31getPaginatedPolicies() throws Exception {
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    RangerPolicyList policyListObj = new RangerPolicyList();
    policyListObj.setPageSize(0);
    policyListObj.setResultSize(1);
    policyListObj.setSortBy("asc");
    policyListObj.setSortType("1");
    policyListObj.setStartIndex(0);
    policyListObj.setTotalCount(10);
    PList<RangerPolicy> dbRangerPolicyList = serviceDBStore.getPaginatedPolicies(filter);
    Assert.assertNotNull(dbRangerPolicyList);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Test(org.junit.Test)

Example 12 with RangerPolicyList

use of org.apache.ranger.view.RangerPolicyList in project ranger by apache.

the class ServiceDBStore method getPolicies.

@Override
public List<RangerPolicy> getPolicies(SearchFilter filter) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getPolicies()");
    }
    RangerPolicyList policyList = searchRangerPolicies(filter);
    List<RangerPolicy> ret = policyList.getPolicies();
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceDBStore.getPolicies()");
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPolicyList(org.apache.ranger.view.RangerPolicyList)

Example 13 with RangerPolicyList

use of org.apache.ranger.view.RangerPolicyList in project ranger by apache.

the class ServiceREST method getPolicies.

@GET
@Path("/policies")
@Produces({ "application/json", "application/xml" })
public RangerPolicyList getPolicies(@Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getPolicies()");
    }
    RangerPolicyList ret = new RangerPolicyList();
    RangerPerfTracer perf = null;
    SearchFilter filter = searchUtil.getSearchFilter(request, policyService.sortFields);
    try {
        if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getPolicies()");
        }
        if (isAdminUserWithNoFilterParams(filter)) {
            PList<RangerPolicy> policies = svcStore.getPaginatedPolicies(filter);
            ret = toRangerPolicyList(policies);
        } else {
            // get all policies from the store; pick the page to return after applying filter
            final int savedStartIndex = filter.getStartIndex();
            final int savedMaxRows = filter.getMaxRows();
            filter.setStartIndex(0);
            filter.setMaxRows(Integer.MAX_VALUE);
            List<RangerPolicy> policies = svcStore.getPolicies(filter);
            filter.setStartIndex(savedStartIndex);
            filter.setMaxRows(savedMaxRows);
            policies = applyAdminAccessFilter(policies);
            ret = toRangerPolicyList(policies, filter);
        }
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("getPolicies() failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    } finally {
        RangerPerfTracer.log(perf);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceREST.getPolicies(): count=" + (ret == null ? 0 : ret.getListSize()));
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with RangerPolicyList

use of org.apache.ranger.view.RangerPolicyList in project ranger by apache.

the class ServiceREST method getServicePoliciesByName.

@GET
@Path("/policies/service/name/{name}")
@Produces({ "application/json", "application/xml" })
public RangerPolicyList getServicePoliciesByName(@PathParam("name") String serviceName, @Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getServicePolicies(" + serviceName + ")");
    }
    SearchFilter filter = searchUtil.getSearchFilter(request, policyService.sortFields);
    RangerPolicyList ret = getServicePolicies(serviceName, filter);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceREST.getServicePolicies(" + serviceName + "): count=" + (ret == null ? 0 : ret.getListSize()));
    }
    return ret;
}
Also used : SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with RangerPolicyList

use of org.apache.ranger.view.RangerPolicyList in project ranger by apache.

the class ServiceREST method getServicePolicies.

@GET
@Path("/policies/service/{id}")
@Produces({ "application/json", "application/xml" })
public RangerPolicyList getServicePolicies(@PathParam("id") Long serviceId, @Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getServicePolicies(" + serviceId + ")");
    }
    RangerPolicyList ret = new RangerPolicyList();
    RangerPerfTracer perf = null;
    SearchFilter filter = searchUtil.getSearchFilter(request, policyService.sortFields);
    try {
        if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServicePolicies(serviceId=" + serviceId + ")");
        }
        if (isAdminUserWithNoFilterParams(filter)) {
            PList<RangerPolicy> policies = svcStore.getPaginatedServicePolicies(serviceId, filter);
            ret = toRangerPolicyList(policies);
        } else {
            // get all policies from the store; pick the page to return after applying filter
            int savedStartIndex = filter == null ? 0 : filter.getStartIndex();
            int savedMaxRows = filter == null ? Integer.MAX_VALUE : filter.getMaxRows();
            if (filter != null) {
                filter.setStartIndex(0);
                filter.setMaxRows(Integer.MAX_VALUE);
            }
            List<RangerPolicy> servicePolicies = svcStore.getServicePolicies(serviceId, filter);
            if (filter != null) {
                filter.setStartIndex(savedStartIndex);
                filter.setMaxRows(savedMaxRows);
            }
            servicePolicies = applyAdminAccessFilter(servicePolicies);
            ret = toRangerPolicyList(servicePolicies, filter);
        }
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("getServicePolicies(" + serviceId + ") failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    } finally {
        RangerPerfTracer.log(perf);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceREST.getServicePolicies(" + serviceId + "): count=" + (ret == null ? 0 : ret.getListSize()));
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RangerPolicyList (org.apache.ranger.view.RangerPolicyList)18 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)14 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)10 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 VXString (org.apache.ranger.view.VXString)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 HashSet (java.util.HashSet)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 PList (org.apache.ranger.plugin.store.PList)2 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1