Search in sources :

Example 1 with RangerPolicyList

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

the class ServiceREST method deletePoliciesProvidedInServiceMap.

private void deletePoliciesProvidedInServiceMap(List<String> sourceServices, List<String> destinationServices) {
    int totalDeletedPilicies = 0;
    if (CollectionUtils.isNotEmpty(sourceServices) && CollectionUtils.isNotEmpty(destinationServices)) {
        RangerPolicyValidator validator = validatorFactory.getPolicyValidator(svcStore);
        for (int i = 0; i < sourceServices.size(); i++) {
            if (!destinationServices.get(i).isEmpty()) {
                final RangerPolicyList servicePolicies = getServicePolicies(destinationServices.get(i), new SearchFilter());
                if (servicePolicies != null) {
                    List<RangerPolicy> rangerPolicyList = servicePolicies.getPolicies();
                    if (CollectionUtils.isNotEmpty(rangerPolicyList)) {
                        for (RangerPolicy rangerPolicy : rangerPolicyList) {
                            if (rangerPolicy != null) {
                                try {
                                    validator.validate(rangerPolicy.getId(), Action.DELETE);
                                    ensureAdminAccess(rangerPolicy);
                                    bizUtil.blockAuditorRoleUser();
                                    svcStore.deletePolicy(rangerPolicy);
                                    totalDeletedPilicies = totalDeletedPilicies + 1;
                                    if (LOG.isDebugEnabled()) {
                                        LOG.debug("Policy " + rangerPolicy.getName() + " deleted successfully.");
                                        LOG.debug("TotalDeletedPilicies: " + totalDeletedPilicies);
                                    }
                                } catch (Throwable excp) {
                                    LOG.error("deletePolicy(" + rangerPolicy.getId() + ") failed", excp);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Total Deleted Policy : " + totalDeletedPilicies);
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) RangerPolicyValidator(org.apache.ranger.plugin.model.validation.RangerPolicyValidator)

Example 2 with RangerPolicyList

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

the class ServiceREST method toRangerPolicyList.

private RangerPolicyList toRangerPolicyList(PList<RangerPolicy> policyList) {
    RangerPolicyList ret = new RangerPolicyList();
    if (policyList != null) {
        ret.setPolicies(policyList.getList());
        ret.setPageSize(policyList.getPageSize());
        ret.setResultSize(policyList.getResultSize());
        ret.setStartIndex(policyList.getStartIndex());
        ret.setTotalCount(policyList.getTotalCount());
        ret.setSortBy(policyList.getSortBy());
        ret.setSortType(policyList.getSortType());
    }
    return ret;
}
Also used : RangerPolicyList(org.apache.ranger.view.RangerPolicyList)

Example 3 with RangerPolicyList

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

the class TestPublicAPIsv2 method test19searchPolicies.

@Test
public void test19searchPolicies() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    List<RangerPolicy> policiesList = new ArrayList<RangerPolicy>();
    RangerService service = rangerService();
    String serviceName = service.getName();
    RangerPolicy rangerPolicy = rangerPolicy();
    policiesList.add(rangerPolicy);
    RangerPolicyList policyList = new RangerPolicyList(policiesList);
    Mockito.when(serviceREST.getServicePoliciesByName(serviceName, request)).thenReturn(policyList);
    List<RangerPolicy> dbRangerPolicyList = publicAPIsv2.searchPolicies(serviceName, request);
    Assert.assertNotNull(dbRangerPolicyList);
    Assert.assertEquals(dbRangerPolicyList.size(), policiesList.size());
    Mockito.verify(serviceREST).getServicePoliciesByName(serviceName, request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Test(org.junit.Test)

Example 4 with RangerPolicyList

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

the class TestPublicAPIsv2 method test26getPolicies.

@Test
public void test26getPolicies() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerPolicyList policyList = Mockito.mock(RangerPolicyList.class);
    List<RangerPolicy> rangerPolicies = new ArrayList<RangerPolicy>();
    RangerPolicy rangerpolicy1 = rangerPolicy();
    RangerPolicy rangerpolicy2 = rangerPolicy1();
    rangerPolicies.add(rangerpolicy1);
    rangerPolicies.add(rangerpolicy2);
    Mockito.when(serviceREST.getPolicies(request)).thenReturn(policyList);
    Mockito.when(policyList.getPolicies()).thenReturn(rangerPolicies);
    List<RangerPolicy> dbRangerPolicies = publicAPIsv2.getPolicies(request);
    Assert.assertNotNull(dbRangerPolicies);
    Assert.assertEquals(dbRangerPolicies.size(), rangerPolicies.size());
    Mockito.verify(serviceREST).getPolicies(request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) Test(org.junit.Test)

Example 5 with RangerPolicyList

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

Aggregations

RangerPolicyList (org.apache.ranger.view.RangerPolicyList)21 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)17 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)14 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 VXString (org.apache.ranger.view.VXString)5 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 RangerService (org.apache.ranger.plugin.model.RangerService)3 HashSet (java.util.HashSet)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 RangerPolicyValidator (org.apache.ranger.plugin.model.validation.RangerPolicyValidator)2 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 XXPolicy (org.apache.ranger.entity.XXPolicy)1 XXService (org.apache.ranger.entity.XXService)1