@Test public void test_isWildcardMatched() { List<String> ips = Arrays.asList("1.2.3.", "1.3.", "2.", "a0:b0:c0:", "a0:b1:", "a2:"); RangerIpMatcher matcher = new RangerIpMatcher(); Assert.assertTrue(matcher.isWildcardMatched(ips, "1.2.3.4")); Assert.assertTrue(matcher.isWildcardMatched(ips, "1.3.3.4")); Assert.assertTrue(matcher.isWildcardMatched(ips, "2.3.3.4")); Assert.assertTrue(matcher.isWildcardMatched(ips, "A0:B0:C0:D0:E0:F0")); Assert.assertTrue(matcher.isWildcardMatched(ips, "A0:B1:C0:D0:E0:F0")); Assert.assertTrue(matcher.isWildcardMatched(ips, "A2:B0:C1:D2:E3:F4")); Assert.assertFalse(matcher.isWildcardMatched(ips, "1.2.33.4")); Assert.assertFalse(matcher.isWildcardMatched(ips, "1.33.3.4")); Assert.assertFalse(matcher.isWildcardMatched(ips, "22.3.3.4")); Assert.assertFalse(matcher.isWildcardMatched(ips, "A0:B0:00:D0:E0:F0")); Assert.assertFalse(matcher.isWildcardMatched(ips, "A0:B2:C0:D0:E0:F0")); Assert.assertFalse(matcher.isWildcardMatched(ips, "22:B0:C1:D2:E3:F4")); }
boolean isWildcardMatched(final List<String> ips, final String requestIp) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + ")"); } boolean matchFound = false; Iterator<String> iterator = ips.iterator(); while (iterator.hasNext() && !matchFound) { String ip = iterator.next(); if (requestIp.contains(".") && requestIp.startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv4[" + requestIp + "]."); } matchFound = true; } else if (requestIp.toLowerCase().startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv6[" + requestIp + "]."); } matchFound = true; } else { LOG.debug("Wildcard policy IP[" + ip + "] did not match request IP[" + requestIp + "]."); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + "): " + matchFound); } return matchFound; }
RangerIpMatcher extends RangerAbstractConditionEvaluator { boolean isWildcardMatched(final List<String> ips, final String requestIp) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + ")"); } boolean matchFound = false; Iterator<String> iterator = ips.iterator(); while (iterator.hasNext() && !matchFound) { String ip = iterator.next(); if (requestIp.contains(".") && requestIp.startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv4[" + requestIp + "]."); } matchFound = true; } else if (requestIp.toLowerCase().startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv6[" + requestIp + "]."); } matchFound = true; } else { LOG.debug("Wildcard policy IP[" + ip + "] did not match request IP[" + requestIp + "]."); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + "): " + matchFound); } return matchFound; } }
RangerIpMatcher extends RangerAbstractConditionEvaluator { boolean isWildcardMatched(final List<String> ips, final String requestIp) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + ")"); } boolean matchFound = false; Iterator<String> iterator = ips.iterator(); while (iterator.hasNext() && !matchFound) { String ip = iterator.next(); if (requestIp.contains(".") && requestIp.startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv4[" + requestIp + "]."); } matchFound = true; } else if (requestIp.toLowerCase().startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv6[" + requestIp + "]."); } matchFound = true; } else { LOG.debug("Wildcard policy IP[" + ip + "] did not match request IP[" + requestIp + "]."); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + "): " + matchFound); } return matchFound; }  }
RangerIpMatcher extends RangerAbstractConditionEvaluator { boolean isWildcardMatched(final List<String> ips, final String requestIp) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + ")"); } boolean matchFound = false; Iterator<String> iterator = ips.iterator(); while (iterator.hasNext() && !matchFound) { String ip = iterator.next(); if (requestIp.contains(".") && requestIp.startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv4[" + requestIp + "]."); } matchFound = true; } else if (requestIp.toLowerCase().startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv6[" + requestIp + "]."); } matchFound = true; } else { LOG.debug("Wildcard policy IP[" + ip + "] did not match request IP[" + requestIp + "]."); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + "): " + matchFound); } return matchFound; }  @Override void init(); @Override boolean isMatched(final RangerAccessRequest request); }
RangerIpMatcher extends RangerAbstractConditionEvaluator { boolean isWildcardMatched(final List<String> ips, final String requestIp) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + ")"); } boolean matchFound = false; Iterator<String> iterator = ips.iterator(); while (iterator.hasNext() && !matchFound) { String ip = iterator.next(); if (requestIp.contains(".") && requestIp.startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv4[" + requestIp + "]."); } matchFound = true; } else if (requestIp.toLowerCase().startsWith(ip)) { if (LOG.isDebugEnabled()) { LOG.debug("Wildcard Policy IP[" + ip + "] matches request IPv6[" + requestIp + "]."); } matchFound = true; } else { LOG.debug("Wildcard policy IP[" + ip + "] did not match request IP[" + requestIp + "]."); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.isWildcardMatched(" + ips+ ", " + requestIp + "): " + matchFound); } return matchFound; }  @Override void init(); @Override boolean isMatched(final RangerAccessRequest request);  }