use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class RangerServiceDefService method getAllServiceDefs.
public List<RangerServiceDef> getAllServiceDefs() {
List<XXServiceDef> xxServiceDefList = daoMgr.getXXServiceDef().getAll();
List<RangerServiceDef> serviceDefList = new ArrayList<RangerServiceDef>();
for (XXServiceDef xxServiceDef : xxServiceDefList) {
RangerServiceDef serviceDef = populateViewBean(xxServiceDef);
serviceDefList.add(serviceDef);
}
return serviceDefList;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceHBase method setup.
@Before
public void setup() {
configs = new HashMap<String, String>();
lookupContext = new ResourceLookupContext();
buildHbaseConnectionConfig();
buildLookupContext();
sd = new RangerServiceDef(sdName, "org.apache.ranger.services.hbase.RangerServiceHBase", "TestService", "test servicedef description", null, null, null, null, null, null, null);
svc = new RangerService(sdName, serviceName, "unit test hbase resource lookup and validateConfig", null, configs);
svcHBase = new RangerServiceHBase();
svcHBase.init(sd, svc);
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class RangerOptimizedPolicyEvaluator method computeEvalOrder.
public int computeEvalOrder() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerOptimizedPolicyEvaluator.computeEvalOrder()");
}
int evalOrder = RANGER_POLICY_EVAL_SCORE_DEFAULT;
RangerServiceDef serviceDef = getServiceDef();
List<RangerServiceDef.RangerResourceDef> resourceDefs = serviceDef.getResources();
RangerPolicy policy = getPolicy();
List<LevelResourceNames> tmpList = new ArrayList<>();
for (Map.Entry<String, RangerPolicy.RangerPolicyResource> kv : policy.getResources().entrySet()) {
String resourceName = kv.getKey();
RangerPolicy.RangerPolicyResource policyResource = kv.getValue();
List<String> resourceValues = policyResource.getValues();
if (CollectionUtils.isNotEmpty(resourceValues)) {
for (RangerServiceDef.RangerResourceDef resourceDef : resourceDefs) {
if (resourceName.equals(resourceDef.getName())) {
tmpList.add(new LevelResourceNames(resourceDef.getLevel(), policyResource));
break;
}
}
}
}
// Sort in ascending order of levels
Collections.sort(tmpList);
int resourceDiscount = 0;
for (LevelResourceNames item : tmpList) {
// Expect lowest level first
boolean foundStarWildcard = false;
boolean foundQuestionWildcard = false;
boolean foundMatchAny = false;
for (String resourceName : item.policyResource.getValues()) {
if (resourceName.isEmpty() || RANGER_POLICY_EVAL_MATCH_ANY_PATTERN_STRING.equals(resourceName)) {
foundMatchAny = true;
break;
} else if (resourceName.contains(RANGER_POLICY_EVAL_MATCH_ANY_PATTERN_STRING)) {
foundStarWildcard = true;
} else if (resourceName.contains(RANGER_POLICY_EVAL_MATCH_ONE_CHARACTER_STRING)) {
foundQuestionWildcard = true;
}
}
if (foundMatchAny) {
resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_MATCH_ANY_WILDCARD;
} else {
if (foundStarWildcard) {
resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_HAS_MATCH_ANY_WILDCARD;
} else if (foundQuestionWildcard) {
resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_HAS_MATCH_ONE_CHARACTER_WILDCARD;
}
RangerPolicy.RangerPolicyResource resource = item.policyResource;
if (resource.getIsExcludes()) {
resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_IS_EXCLUDES;
}
if (resource.getIsRecursive()) {
resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESORUCE_DISCOUNT_IS_RECURSIVE;
}
}
}
if (needsDynamicEval()) {
evalOrder += RANGER_POLICY_EVAL_SCORE_DYNAMIC_RESOURCE_EVAL_PENALTY;
}
evalOrder -= Math.min(RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_RESOURCE, resourceDiscount);
if (hasPublicGroup || hasCurrentUser) {
evalOrder -= RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_USERSGROUPS;
} else {
evalOrder -= Math.min(groups.size() + users.size(), RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_USERSGROUPS);
}
evalOrder -= Math.round(((float) RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_ACCESS_TYPES * accessPerms.size()) / serviceDef.getAccessTypes().size());
int customConditionsDiscount = RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_CUSTOM_CONDITIONS - (RANGER_POLICY_EVAL_SCORE_CUSTOM_CONDITION_PENALTY * this.getCustomConditionsCount());
if (customConditionsDiscount > 0) {
evalOrder -= customConditionsDiscount;
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerOptimizedPolicyEvaluator.computeEvalOrder(), policyName:" + policy.getName() + ", priority:" + evalOrder);
}
return evalOrder;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class RangerBasePlugin method getDefaultSvcPolicies.
private ServicePolicies getDefaultSvcPolicies() {
ServicePolicies ret = null;
RangerServiceDef serviceDef = getServiceDef();
if (serviceDef == null) {
serviceDef = getDefaultServiceDef();
}
if (serviceDef != null) {
ret = new ServicePolicies();
ret.setServiceDef(serviceDef);
ret.setServiceName(serviceName);
ret.setPolicies(new ArrayList<RangerPolicy>());
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class AbstractPredicateUtil 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 RangerServiceDef) {
RangerServiceDef serviceDef = (RangerServiceDef) object;
String svcType = serviceDef.getName();
ret = StringUtils.equals(svcType, serviceType);
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
Aggregations