use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class AbstractPredicateUtil method addPredicateForPolicyName.
private Predicate addPredicateForPolicyName(final String policyName, List<Predicate> predicates) {
if (StringUtils.isEmpty(policyName)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerPolicy) {
RangerPolicy policy = (RangerPolicy) object;
ret = StringUtils.equals(policyName, policy.getName());
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class AbstractPredicateUtil method addPredicateForResources.
private Predicate addPredicateForResources(final Map<String, String> resources, List<Predicate> predicates) {
if (MapUtils.isEmpty(resources)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerPolicy) {
RangerPolicy policy = (RangerPolicy) object;
if (!MapUtils.isEmpty(policy.getResources())) {
int numFound = 0;
for (String name : resources.keySet()) {
boolean isMatch = false;
RangerPolicyResource policyResource = policy.getResources().get(name);
if (policyResource != null && !CollectionUtils.isEmpty(policyResource.getValues())) {
String val = resources.get(name);
if (policyResource.getValues().contains(val)) {
isMatch = true;
} else {
for (String policyResourceValue : policyResource.getValues()) {
if (FilenameUtils.wildcardMatch(val, policyResourceValue)) {
isMatch = true;
break;
}
}
}
}
if (isMatch) {
numFound++;
} else {
break;
}
}
ret = numFound == resources.size();
}
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class AbstractPredicateUtil method addPredicateForPartialPolicyName.
private Predicate addPredicateForPartialPolicyName(final String policyName, List<Predicate> predicates) {
if (StringUtils.isEmpty(policyName)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerPolicy) {
RangerPolicy policy = (RangerPolicy) object;
ret = StringUtils.containsIgnoreCase(policy.getName(), policyName);
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class AbstractPredicateUtil method addPredicateForGroupName.
private Predicate addPredicateForGroupName(final String groupName, List<Predicate> predicates) {
if (StringUtils.isEmpty(groupName)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerPolicy) {
RangerPolicy policy = (RangerPolicy) object;
List<?>[] policyItemsList = new List<?>[] { policy.getPolicyItems(), policy.getDenyPolicyItems(), policy.getAllowExceptions(), policy.getDenyExceptions(), policy.getDataMaskPolicyItems(), policy.getRowFilterPolicyItems() };
for (List<?> policyItemsObj : policyItemsList) {
@SuppressWarnings("unchecked") List<RangerPolicyItem> policyItems = (List<RangerPolicyItem>) policyItemsObj;
for (RangerPolicyItem policyItem : policyItems) {
if (!policyItem.getGroups().isEmpty()) {
for (String group : policyItem.getGroups()) {
if (StringUtils.containsIgnoreCase(group, groupName)) {
ret = true;
break;
}
}
}
}
if (ret) {
break;
}
}
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class ServicePredicateUtil method addPredicateForServiceType.
private Predicate addPredicateForServiceType(final String serviceType, List<Predicate> predicates) {
if (StringUtils.isEmpty(serviceType)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerPolicy) {
RangerPolicy policy = (RangerPolicy) object;
ret = StringUtils.equals(serviceType, getServiceType(policy.getService()));
} else if (object instanceof RangerService) {
RangerService service = (RangerService) object;
ret = StringUtils.equals(serviceType, service.getType());
} else if (object instanceof RangerServiceDef) {
RangerServiceDef serviceDef = (RangerServiceDef) object;
ret = StringUtils.equals(serviceType, serviceDef.getName());
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
Aggregations