@Test public void testIsMatch() throws Exception { for (Object[] row : data) { String resource = (String)row[0]; String policyValue = (String)row[1]; boolean excludes = (boolean)row[2]; boolean result = (boolean)row[3]; String user = (String) row[4]; Map<String, Object> evalContext = new HashMap<>(); RangerAccessRequestUtil.setCurrentUserInContext(evalContext, user); MatcherWrapper matcher = new MatcherWrapper(policyValue, excludes); assertEquals(getMessage(row), result, matcher.isMatch(resource, evalContext)); } }
@Override public boolean isMatch(Object resource, Map<String, Object> evalContext) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + ")"); } boolean ret = false; boolean allValuesRequested = isAllValuesRequested(resource); if(allValuesRequested || isMatchAny) { ret = isMatchAny; } else { if (resource instanceof String) { String strValue = (String) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatch(strValue, evalContext); if (ret) { break; } } } else if (resource instanceof Collection) { @SuppressWarnings("unchecked") Collection<String> collValue = (Collection<String>) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatchAny(collValue, evalContext); if (ret) { break; } } } } ret = applyExcludes(allValuesRequested, ret); if (ret == false) { if(LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue: policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("RangerDefaultResourceMatcher.isMatch returns FALSE, (resource=" + resource + ", policyValues=" + sb.toString() + ")"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + "): " + ret); } return ret; }
RangerDefaultResourceMatcher extends RangerAbstractResourceMatcher { @Override public boolean isMatch(Object resource, Map<String, Object> evalContext) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + ")"); } boolean ret = false; boolean allValuesRequested = isAllValuesRequested(resource); if(allValuesRequested || isMatchAny) { ret = isMatchAny; } else { if (resource instanceof String) { String strValue = (String) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatch(strValue, evalContext); if (ret) { break; } } } else if (resource instanceof Collection) { @SuppressWarnings("unchecked") Collection<String> collValue = (Collection<String>) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatchAny(collValue, evalContext); if (ret) { break; } } } } ret = applyExcludes(allValuesRequested, ret); if (ret == false) { if(LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue: policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("RangerDefaultResourceMatcher.isMatch returns FALSE, (resource=" + resource + ", policyValues=" + sb.toString() + ")"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + "): " + ret); } return ret; } }
RangerDefaultResourceMatcher extends RangerAbstractResourceMatcher { @Override public boolean isMatch(Object resource, Map<String, Object> evalContext) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + ")"); } boolean ret = false; boolean allValuesRequested = isAllValuesRequested(resource); if(allValuesRequested || isMatchAny) { ret = isMatchAny; } else { if (resource instanceof String) { String strValue = (String) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatch(strValue, evalContext); if (ret) { break; } } } else if (resource instanceof Collection) { @SuppressWarnings("unchecked") Collection<String> collValue = (Collection<String>) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatchAny(collValue, evalContext); if (ret) { break; } } } } ret = applyExcludes(allValuesRequested, ret); if (ret == false) { if(LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue: policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("RangerDefaultResourceMatcher.isMatch returns FALSE, (resource=" + resource + ", policyValues=" + sb.toString() + ")"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + "): " + ret); } return ret; }  }
RangerDefaultResourceMatcher extends RangerAbstractResourceMatcher { @Override public boolean isMatch(Object resource, Map<String, Object> evalContext) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + ")"); } boolean ret = false; boolean allValuesRequested = isAllValuesRequested(resource); if(allValuesRequested || isMatchAny) { ret = isMatchAny; } else { if (resource instanceof String) { String strValue = (String) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatch(strValue, evalContext); if (ret) { break; } } } else if (resource instanceof Collection) { @SuppressWarnings("unchecked") Collection<String> collValue = (Collection<String>) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatchAny(collValue, evalContext); if (ret) { break; } } } } ret = applyExcludes(allValuesRequested, ret); if (ret == false) { if(LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue: policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("RangerDefaultResourceMatcher.isMatch returns FALSE, (resource=" + resource + ", policyValues=" + sb.toString() + ")"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + "): " + ret); } return ret; }  @Override boolean isMatch(Object resource, Map<String, Object> evalContext); StringBuilder toString(StringBuilder sb); }
RangerDefaultResourceMatcher extends RangerAbstractResourceMatcher { @Override public boolean isMatch(Object resource, Map<String, Object> evalContext) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + ")"); } boolean ret = false; boolean allValuesRequested = isAllValuesRequested(resource); if(allValuesRequested || isMatchAny) { ret = isMatchAny; } else { if (resource instanceof String) { String strValue = (String) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatch(strValue, evalContext); if (ret) { break; } } } else if (resource instanceof Collection) { @SuppressWarnings("unchecked") Collection<String> collValue = (Collection<String>) resource; for (ResourceMatcher resourceMatcher : resourceMatchers.getResourceMatchers()) { ret = resourceMatcher.isMatchAny(collValue, evalContext); if (ret) { break; } } } } ret = applyExcludes(allValuesRequested, ret); if (ret == false) { if(LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue: policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("RangerDefaultResourceMatcher.isMatch returns FALSE, (resource=" + resource + ", policyValues=" + sb.toString() + ")"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultResourceMatcher.isMatch(" + resource + ", " + evalContext + "): " + ret); } return ret; }  @Override boolean isMatch(Object resource, Map<String, Object> evalContext); StringBuilder toString(StringBuilder sb);  }