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);
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations