Search in sources :

Example 36 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter 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 37 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter 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 38 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class ServiceREST method getServices.

@GET
@Path("/services")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_SERVICES + "\")")
public RangerServiceList getServices(@Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getServices()");
    }
    RangerServiceList ret = null;
    RangerPerfTracer perf = null;
    PList<RangerService> paginatedSvcs = null;
    SearchFilter filter = searchUtil.getSearchFilter(request, svcService.sortFields);
    try {
        if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServices()");
        }
        paginatedSvcs = svcStore.getPaginatedServices(filter);
        if (paginatedSvcs != null) {
            ret = new RangerServiceList();
            ret.setServices(paginatedSvcs.getList());
            ret.setPageSize(paginatedSvcs.getPageSize());
            ret.setResultSize(paginatedSvcs.getResultSize());
            ret.setStartIndex(paginatedSvcs.getStartIndex());
            ret.setTotalCount(paginatedSvcs.getTotalCount());
            ret.setSortBy(paginatedSvcs.getSortBy());
            ret.setSortType(paginatedSvcs.getSortType());
        }
    } 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.getListSize()));
    }
    return ret;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) RangerServiceList(org.apache.ranger.view.RangerServiceList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) 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 39 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class ServiceREST method getPolicyByName.

private RangerPolicy getPolicyByName(String serviceName, String policyName) {
    RangerPolicy ret = null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getPolicyByName(" + serviceName + "," + policyName + ")");
    }
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
    filter.setParam(SearchFilter.POLICY_NAME, policyName);
    List<RangerPolicy> policies = getPolicies(filter);
    if (CollectionUtils.isNotEmpty(policies)) {
        ret = policies.get(0);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceREST.getPolicyByName(" + serviceName + "," + policyName + ")" + ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter)

Example 40 with SearchFilter

use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.

the class ServiceREST method getPluginsInfo.

@GET
@Path("/plugins/info")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_PLUGINS_INFO + "\")")
public RangerPluginInfoList getPluginsInfo(@Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getPluginsInfo()");
    }
    RangerPluginInfoList ret = null;
    SearchFilter filter = searchUtil.getSearchFilter(request, pluginInfoService.getSortFields());
    try {
        PList<RangerPluginInfo> paginatedPluginsInfo = pluginInfoService.searchRangerPluginInfo(filter);
        if (paginatedPluginsInfo != null) {
            ret = new RangerPluginInfoList();
            ret.setPluginInfoList(paginatedPluginsInfo.getList());
            ret.setPageSize(paginatedPluginsInfo.getPageSize());
            ret.setResultSize(paginatedPluginsInfo.getResultSize());
            ret.setStartIndex(paginatedPluginsInfo.getStartIndex());
            ret.setTotalCount(paginatedPluginsInfo.getTotalCount());
            ret.setSortBy(paginatedPluginsInfo.getSortBy());
            ret.setSortType(paginatedPluginsInfo.getSortType());
        }
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("getPluginsInfo() failed", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceREST.getPluginsInfo()");
    }
    return ret;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerPluginInfoList(org.apache.ranger.view.RangerPluginInfoList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

SearchFilter (org.apache.ranger.plugin.util.SearchFilter)61 Test (org.junit.Test)32 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)30 ArrayList (java.util.ArrayList)27 RangerService (org.apache.ranger.plugin.model.RangerService)24 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 GET (javax.ws.rs.GET)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 RangerPolicyList (org.apache.ranger.view.RangerPolicyList)11 VXString (org.apache.ranger.view.VXString)10 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)9 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)7 RangerServiceDefList (org.apache.ranger.view.RangerServiceDefList)6 RangerServiceList (org.apache.ranger.view.RangerServiceList)6 HashMap (java.util.HashMap)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 XXTrxLog (org.apache.ranger.entity.XXTrxLog)4 RangerExportPolicyList (org.apache.ranger.view.RangerExportPolicyList)4