Search in sources :

Example 1 with VXResourceList

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

the class TestAssetREST method testSearchXResource.

@Test
public void testSearchXResource() {
    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);
    }
    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);
    VXResourceList actualVXResourceList = assetREST.searchXResources(request);
    Assert.assertNotNull(actualVXResourceList);
    Assert.assertEquals(expectedVXResourceList.getVXResources(), actualVXResourceList.getVXResources());
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, null);
    Mockito.verify(serviceREST).getPolicies(searchFilter);
    for (i = 0; i < 2; i++) {
        Mockito.verify(serviceUtil, Mockito.times(1)).toVXResource(rangerPolicyList.get((int) i), rangerService);
    }
    Mockito.verify(serviceREST, Mockito.times(2)).getServiceByName(rangerPolicyList.get(0).getService());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) 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)

Example 2 with VXResourceList

use of org.apache.ranger.view.VXResourceList 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)

Example 3 with VXResourceList

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

the class XResourceServiceBase method searchXResources.

/**
 * @param searchCriteria
 * @return
 */
public VXResourceList searchXResources(SearchCriteria searchCriteria) {
    VXResourceList returnList = new VXResourceList();
    List<VXResource> xResourceList = new ArrayList<VXResource>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXResource : resultList) {
        VXResource vXResource = populateViewBean(gjXResource);
        xResourceList.add(vXResource);
    }
    returnList.setVXResources(xResourceList);
    return returnList;
}
Also used : VXResourceList(org.apache.ranger.view.VXResourceList) VXResource(org.apache.ranger.view.VXResource) ArrayList(java.util.ArrayList)

Example 4 with VXResourceList

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

the class XResourceService method searchXResources.

@Override
public VXResourceList searchXResources(SearchCriteria searchCriteria) {
    VXResourceList returnList;
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    // If user is system admin
    if (currentUserSession != null && currentUserSession.isUserAdmin()) {
        returnList = super.searchXResources(searchCriteria);
    } else {
        // need to be optimize
        returnList = new VXResourceList();
        int startIndex = searchCriteria.getStartIndex();
        int pageSize = searchCriteria.getMaxRows();
        searchCriteria.setStartIndex(0);
        searchCriteria.setMaxRows(Integer.MAX_VALUE);
        List<XXResource> resultList = (List<XXResource>) searchResources(searchCriteria, searchFields, sortFields, returnList);
        List<XXResource> adminPermResourceList = new ArrayList<XXResource>();
        for (XXResource xXResource : resultList) {
            VXResponse vXResponse = xaBizUtil.hasPermission(populateViewBean(xXResource), AppConstants.XA_PERM_TYPE_ADMIN);
            if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
                adminPermResourceList.add(xXResource);
            }
        }
        if (!adminPermResourceList.isEmpty()) {
            populatePageList(adminPermResourceList, startIndex, pageSize, returnList);
        }
    }
    if (returnList != null && returnList.getResultSize() > 0) {
        for (VXResource vXResource : returnList.getVXResources()) {
            populateAuditList(vXResource);
        }
    }
    return returnList;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) VXResourceList(org.apache.ranger.view.VXResourceList) XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) List(java.util.List) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Aggregations

ArrayList (java.util.ArrayList)4 VXResource (org.apache.ranger.view.VXResource)4 VXResourceList (org.apache.ranger.view.VXResourceList)4 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 RangerService (org.apache.ranger.plugin.model.RangerService)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 Test (org.junit.Test)2 List (java.util.List)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXResource (org.apache.ranger.entity.XXResource)1 VXLong (org.apache.ranger.view.VXLong)1 VXResponse (org.apache.ranger.view.VXResponse)1