Search in sources :

Example 1 with SearchFilter

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

the class ServiceDBStore method getPaginatedServicePolicies.

public PList<RangerPolicy> getPaginatedServicePolicies(String serviceName, SearchFilter filter) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getPaginatedServicePolicies(" + serviceName + ")");
    }
    if (filter == null) {
        filter = new SearchFilter();
    }
    filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
    PList<RangerPolicy> ret = getPaginatedPolicies(filter);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceDBStore.getPaginatedServicePolicies(" + serviceName + "): count=" + ((ret == null) ? 0 : ret.getListSize()));
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter)

Example 2 with SearchFilter

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

the class TestRangerServiceDefServiceBase method test21searchRangerServiceDefs.

@Test
public void test21searchRangerServiceDefs() {
    setup();
    SearchFilter searchFilter = new SearchFilter();
    searchFilter.setParam(SearchFilter.POLICY_NAME, "policyName");
    searchFilter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    BaseDao baseDao = Mockito.mock(BaseDao.class);
    Mockito.when(daoManager.getDaoForClassName(Mockito.anyString())).thenReturn(baseDao);
    RangerServiceDefList dbRangerServiceDefList = rangerServiceDefService.searchRangerServiceDefs(searchFilter);
    Assert.assertNotNull(dbRangerServiceDefList);
    Mockito.verify(daoManager).getDaoForClassName(Mockito.anyString());
}
Also used : BaseDao(org.apache.ranger.common.db.BaseDao) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Test(org.junit.Test)

Example 3 with SearchFilter

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

the class TestRangerServiceServiceBase method test3searchRangerServices.

@Test
public void test3searchRangerServices() {
    SearchFilter searchFilter = new SearchFilter();
    searchFilter.setParam(SearchFilter.POLICY_NAME, "policyName");
    searchFilter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    BaseDao baseDao = Mockito.mock(BaseDao.class);
    Mockito.when(daoManager.getDaoForClassName(Mockito.anyString())).thenReturn(baseDao);
    RangerServiceList dbRangerServiceList = rangerServiceService.searchRangerServices(searchFilter);
    Assert.assertNotNull(dbRangerServiceList);
    Mockito.verify(daoManager).getDaoForClassName(Mockito.anyString());
}
Also used : BaseDao(org.apache.ranger.common.db.BaseDao) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceList(org.apache.ranger.view.RangerServiceList) Test(org.junit.Test)

Example 4 with SearchFilter

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

the class TestAssetREST method testSearchXAssets.

@Test
public void testSearchXAssets() {
    RangerService rangerService1 = rangerService(Id);
    RangerService rangerService2 = rangerService(9L);
    VXAsset vXAsset1 = vXAsset(Id);
    VXAsset vXAsset2 = vXAsset(9L);
    VXAssetList expectedVXAsset = new VXAssetList();
    List<VXAsset> vXAsset = Arrays.asList(vXAsset1, vXAsset2);
    expectedVXAsset.setVXAssets(vXAsset);
    List<RangerService> services = Arrays.asList(rangerService1, rangerService2);
    SearchFilter searchFilter = new SearchFilter();
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, null)).thenReturn(searchFilter);
    Mockito.when(serviceREST.getServices(searchFilter)).thenReturn(services);
    Mockito.when(serviceUtil.toVXAsset(rangerService1)).thenReturn(vXAsset1);
    Mockito.when(serviceUtil.toVXAsset(rangerService2)).thenReturn(vXAsset2);
    VXAssetList vXAssetList = assetREST.searchXAssets(request);
    Assert.assertNotNull(vXAssetList);
    Assert.assertEquals(expectedVXAsset.getVXAssets(), vXAssetList.getVXAssets());
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequestForRepositorySearch(request, null);
    Mockito.verify(serviceREST).getServices(searchFilter);
    Mockito.verify(serviceUtil, Mockito.times(1)).toVXAsset(rangerService1);
    Mockito.verify(serviceUtil, Mockito.times(1)).toVXAsset(rangerService2);
}
Also used : VXAsset(org.apache.ranger.view.VXAsset) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) VXAssetList(org.apache.ranger.view.VXAssetList) Test(org.junit.Test)

Example 5 with SearchFilter

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

the class TestAssetREST method testCountXResource.

@Test
public void testCountXResource() {
    List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
    List<VXResource> vXResourcesList = new ArrayList<VXResource>();
    RangerService rangerService = rangerService(Id);
    long i;
    for (i = 1; i <= 2; i++) {
        RangerPolicy rangerPolicy = rangerPolicy(i);
        VXResource vXresource = vxResource(i);
        rangerPolicyList.add(rangerPolicy);
        vXResourcesList.add(vXresource);
        Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource);
    }
    VXLong expectedXResouce = new VXLong();
    expectedXResouce.setValue(2l);
    Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService);
    VXResourceList expectedVXResourceList = new VXResourceList();
    expectedVXResourceList.setVXResources(vXResourcesList);
    SearchFilter searchFilter = new SearchFilter();
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter);
    Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList);
    VXLong actualXResource = assetREST.countXResources(request);
    Assert.assertEquals(expectedXResouce.getValue(), actualXResource.getValue());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

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