Search in sources :

Example 11 with SearchFilter

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

the class TestServiceREST method test34countServices.

@Test
public void test34countServices() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    PList<RangerService> ret = Mockito.mock(PList.class);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(svcStore.getPaginatedServices(filter)).thenReturn(ret);
    Long data = serviceREST.countServices(request);
    Assert.assertNotNull(data);
    Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
    Mockito.verify(svcStore).getPaginatedServices(filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 12 with SearchFilter

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

the class TestServiceREST method test22getServicePoliciesById.

@Test
public void test22getServicePoliciesById() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerPolicy rangerPolicy = rangerPolicy();
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
    RangerPolicyList dbRangerPolicy = serviceREST.getServicePolicies(rangerPolicy.getId(), request);
    Assert.assertNotNull(dbRangerPolicy);
    Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
    Mockito.verify(svcStore).getServicePolicies(Id, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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 13 with SearchFilter

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

the class TestServiceREST method test26getServices.

@Test
public void test26getServices() throws Exception {
    List<RangerService> ret = new ArrayList<RangerService>();
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(svcStore.getServices(filter)).thenReturn(ret);
    List<RangerService> dbRangerService = serviceREST.getServices(filter);
    Assert.assertNotNull(dbRangerService);
    Mockito.verify(svcStore).getServices(filter);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 14 with SearchFilter

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

the class MetricUtil method getAuditsCount.

private VXMetricServiceCount getAuditsCount(int accessResult, Date startDate, Date endDate) throws Exception {
    long totalCountOfAudits = 0;
    SearchFilter filter = new SearchFilter();
    filter.setStartIndex(0);
    Map<String, Long> servicesRepoType = new HashMap<String, Long>();
    VXMetricServiceCount vXMetricServiceCount = new VXMetricServiceCount();
    PList<RangerServiceDef> paginatedSvcDefs = svcStore.getPaginatedServiceDefs(filter);
    Iterable<RangerServiceDef> repoTypeGet = paginatedSvcDefs.getList();
    for (Object repo : repoTypeGet) {
        RangerServiceDef rangerServiceDefObj = (RangerServiceDef) repo;
        long id = rangerServiceDefObj.getId();
        String serviceRepoName = rangerServiceDefObj.getName();
        SearchCriteria searchCriteriaWithType = new SearchCriteria();
        searchCriteriaWithType.getParamList().put("repoType", id);
        searchCriteriaWithType.getParamList().put("accessResult", accessResult);
        searchCriteriaWithType.addParam("startDate", startDate);
        searchCriteriaWithType.addParam("endDate", endDate);
        VXAccessAuditList vXAccessAuditListwithType = assetMgr.getAccessLogs(searchCriteriaWithType);
        long toltalCountOfRepo = vXAccessAuditListwithType.getTotalCount();
        if (toltalCountOfRepo != 0) {
            servicesRepoType.put(serviceRepoName, toltalCountOfRepo);
            totalCountOfAudits += toltalCountOfRepo;
        }
    }
    vXMetricServiceCount.setServiceBasedCountList(servicesRepoType);
    vXMetricServiceCount.setTotalCount(totalCountOfAudits);
    return vXMetricServiceCount;
}
Also used : HashMap(java.util.HashMap) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList) SearchCriteria(org.apache.ranger.common.SearchCriteria) VXMetricServiceCount(org.apache.ranger.view.VXMetricServiceCount) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 15 with SearchFilter

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

the class AssetREST method searchXResources.

@GET
@Path("/resources")
@Produces({ "application/xml", "application/json" })
public VXResourceList searchXResources(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.searchXResources()");
    }
    VXResourceList ret = new VXResourceList();
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields);
    List<RangerPolicy> policies = serviceREST.getPolicies(filter);
    if (policies != null) {
        List<VXResource> resources = new ArrayList<VXResource>();
        for (RangerPolicy policy : policies) {
            RangerService service = serviceREST.getServiceByName(policy.getService());
            VXResource resource = serviceUtil.toVXResource(policy, service);
            if (resource != null) {
                resources.add(resource);
            }
        }
        ret.setVXResources(resources);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize());
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) 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)

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