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 deletePoliciesForResource.
private void deletePoliciesForResource(List<String> sourceServices, List<String> destinationServices, String resource, HttpServletRequest request, List<RangerPolicy> exportPolicies) {
int totalDeletedPilicies = 0;
if (CollectionUtils.isNotEmpty(sourceServices) && CollectionUtils.isNotEmpty(destinationServices)) {
Set<String> exportedPolicyNames = new HashSet<String>();
if (CollectionUtils.isNotEmpty(exportPolicies)) {
for (RangerPolicy rangerPolicy : exportPolicies) {
if (rangerPolicy != null) {
exportedPolicyNames.add(rangerPolicy.getName());
}
}
}
for (int i = 0; i < sourceServices.size(); i++) {
if (!destinationServices.get(i).isEmpty()) {
RangerPolicyList servicePolicies = null;
servicePolicies = getServicePoliciesByName(destinationServices.get(i), request);
if (servicePolicies != null) {
List<RangerPolicy> rangerPolicyList = servicePolicies.getPolicies();
if (CollectionUtils.isNotEmpty(rangerPolicyList)) {
for (RangerPolicy rangerPolicy : rangerPolicyList) {
if (rangerPolicy != null) {
Map<String, RangerPolicy.RangerPolicyResource> rangerPolicyResourceMap = rangerPolicy.getResources();
if (rangerPolicyResourceMap != null) {
RangerPolicy.RangerPolicyResource rangerPolicyResource = null;
if (rangerPolicyResourceMap.containsKey("path")) {
rangerPolicyResource = rangerPolicyResourceMap.get("path");
} else if (rangerPolicyResourceMap.containsKey("database")) {
rangerPolicyResource = rangerPolicyResourceMap.get("database");
}
if (rangerPolicyResource != null) {
if (CollectionUtils.isNotEmpty(rangerPolicyResource.getValues()) && rangerPolicyResource.getValues().size() > 1) {
continue;
}
}
}
if (rangerPolicy.getId() != null) {
if (!exportedPolicyNames.contains(rangerPolicy.getName())) {
deletePolicy(rangerPolicy.getId());
if (LOG.isDebugEnabled()) {
LOG.debug("Policy " + rangerPolicy.getName() + " deleted successfully.");
}
totalDeletedPilicies = totalDeletedPilicies + 1;
}
}
}
}
}
}
}
}
}
}
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 ServiceREST method toRangerPolicyList.
private RangerPolicyList toRangerPolicyList(List<RangerPolicy> policyList, SearchFilter filter) {
RangerPolicyList ret = new RangerPolicyList();
if (CollectionUtils.isNotEmpty(policyList)) {
int totalCount = policyList.size();
int startIndex = filter.getStartIndex();
int pageSize = filter.getMaxRows();
int toIndex = Math.min(startIndex + pageSize, totalCount);
String sortType = filter.getSortType();
String sortBy = filter.getSortBy();
List<RangerPolicy> retList = new ArrayList<RangerPolicy>();
for (int i = startIndex; i < toIndex; i++) {
retList.add(policyList.get(i));
}
ret.setPolicies(retList);
ret.setPageSize(pageSize);
ret.setResultSize(retList.size());
ret.setStartIndex(startIndex);
ret.setTotalCount(totalCount);
ret.setSortBy(sortBy);
ret.setSortType(sortType);
}
return ret;
}
use of org.apache.ranger.view.RangerPolicyList in project ranger by apache.
the class ServiceDBStore method getPaginatedPolicies.
public PList<RangerPolicy> getPaginatedPolicies(SearchFilter filter) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.getPaginatedPolicies(+ " + filter + ")");
}
RangerPolicyList policyList = searchRangerPolicies(filter);
if (LOG.isDebugEnabled()) {
LOG.debug("before filter: count=" + policyList.getListSize());
}
predicateUtil.applyFilter(policyList.getPolicies(), filter);
if (LOG.isDebugEnabled()) {
LOG.debug("after filter: count=" + policyList.getListSize());
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceDBStore.getPaginatedPolicies(" + filter + "): count=" + policyList.getListSize());
}
return new PList<RangerPolicy>(policyList.getPolicies(), policyList.getStartIndex(), policyList.getPageSize(), policyList.getTotalCount(), policyList.getResultSize(), policyList.getSortType(), policyList.getSortBy());
}
Aggregations