Search in sources :

Example 16 with SearchFilter

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

the class PublicAPIs method searchRepositories.

@GET
@Path("/api/repository/")
@Produces({ "application/json", "application/xml" })
public VXRepositoryList searchRepositories(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.searchRepositories()");
    }
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields);
    List<RangerService> serviceList = serviceREST.getServices(filter);
    VXRepositoryList ret = null;
    if (serviceList != null) {
        ret = serviceUtil.rangerServiceListToPublicObjectList(serviceList);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.searchRepositories(): count=" + (ret == null ? 0 : ret.getListSize()));
    }
    return ret;
}
Also used : SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 17 with SearchFilter

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

the class PublicAPIs method searchPolicies.

@GET
@Path("/api/policy")
@Produces({ "application/json", "application/xml" })
public VXPolicyList searchPolicies(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIs.searchPolicies(): ");
    }
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    // get all policies from the store; pick the page to return after applying filter
    int savedStartIndex = filter.getStartIndex();
    int savedMaxRows = filter.getMaxRows();
    filter.setStartIndex(0);
    filter.setMaxRows(Integer.MAX_VALUE);
    List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter);
    filter.setStartIndex(savedStartIndex);
    filter.setMaxRows(savedMaxRows);
    VXPolicyList vXPolicyList = null;
    if (rangerPolicyList != null) {
        vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList, filter);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList);
    }
    return vXPolicyList;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter)

Example 18 with SearchFilter

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

the class PublicAPIsv2 method getPolicyByName.

@GET
@Path("/api/service/{servicename}/policy/{policyname}")
@Produces({ "application/json", "application/xml" })
public RangerPolicy getPolicyByName(@PathParam("servicename") String serviceName, @PathParam("policyname") String policyName, @Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> PublicAPIsv2.getPolicyByName(" + serviceName + "," + policyName + ")");
    }
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
    filter.setParam(SearchFilter.POLICY_NAME, policyName);
    List<RangerPolicy> policies = serviceREST.getPolicies(filter);
    if (policies.size() != 1) {
        throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, "Not found", true);
    }
    RangerPolicy policy = policies.get(0);
    if (logger.isDebugEnabled()) {
        logger.debug("<== PublicAPIsv2.getPolicyByName(" + serviceName + "," + policyName + ")" + policy);
    }
    return policy;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter)

Example 19 with SearchFilter

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

the class ServiceREST method getPolicyByGuid.

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

Example 20 with SearchFilter

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

the class ServiceREST method getPoliciesInJson.

@GET
@Path("/policies/exportJson")
@Produces("text/json")
public void getPoliciesInJson(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("checkPoliciesExists") Boolean checkPoliciesExists) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceREST.getPoliciesInJson()");
    }
    RangerPerfTracer perf = null;
    SearchFilter filter = searchUtil.getSearchFilter(request, policyService.sortFields);
    try {
        if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getPoliciesInJson()");
        }
        if (checkPoliciesExists == null) {
            checkPoliciesExists = false;
        }
        List<RangerPolicy> policyLists = new ArrayList<RangerPolicy>();
        policyLists = getAllFilteredPolicyList(filter, request, policyLists);
        if (CollectionUtils.isNotEmpty(policyLists)) {
            for (RangerPolicy rangerPolicy : policyLists) {
                if (rangerPolicy != null) {
                    ensureAdminAndAuditAccess(rangerPolicy);
                }
            }
            bizUtil.blockAuditorRoleUser();
            svcStore.getPoliciesInJson(policyLists, response);
        } else {
            checkPoliciesExists = true;
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            LOG.error("There is no Policy to Export!!");
        }
        if (!checkPoliciesExists) {
            RangerExportPolicyList rangerExportPolicyList = new RangerExportPolicyList();
            svcStore.putMetaDataInfo(rangerExportPolicyList);
            String metaDataInfo = new ObjectMapper().writeValueAsString(rangerExportPolicyList.getMetaDataInfo());
            List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
            XXTrxLog xxTrxLog = new XXTrxLog();
            xxTrxLog.setAction("EXPORT JSON");
            xxTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_RANGER_POLICY);
            xxTrxLog.setPreviousValue(metaDataInfo);
            trxLogList.add(xxTrxLog);
            bizUtil.createTrxLog(trxLogList);
        }
    } catch (WebApplicationException excp) {
        throw excp;
    } catch (Throwable excp) {
        LOG.error("Error while exporting policy file!!", excp);
        throw restErrorUtil.createRESTException(excp.getMessage());
    } finally {
        RangerPerfTracer.log(perf);
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) RangerExportPolicyList(org.apache.ranger.view.RangerExportPolicyList) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) XXTrxLog(org.apache.ranger.entity.XXTrxLog) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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