@Test public void test_digestIp() { RangerIpMatcher matcher = new RangerIpMatcher(); Assert.assertEquals("", matcher.digestPolicyIp("*")); Assert.assertEquals("", matcher.digestPolicyIp("*.*")); Assert.assertEquals("", matcher.digestPolicyIp("*.*.*")); Assert.assertEquals("", matcher.digestPolicyIp("*.*.*.*")); Assert.assertEquals("", matcher.digestPolicyIp("*:*:*:*")); Assert.assertEquals("", matcher.digestPolicyIp("*:*:*:*:*:*")); Assert.assertEquals("10.", matcher.digestPolicyIp("10.*")); Assert.assertEquals("10.", matcher.digestPolicyIp("10.*.*")); Assert.assertEquals("10.", matcher.digestPolicyIp("10.*.*.*")); Assert.assertEquals("10.20.", matcher.digestPolicyIp("10.20.*")); Assert.assertEquals("10.20.", matcher.digestPolicyIp("10.20.*.*")); Assert.assertEquals("10.20.30.", matcher.digestPolicyIp("10.20.30.*")); Assert.assertEquals("a0:", matcher.digestPolicyIp("A0:*")); Assert.assertEquals("a0:", matcher.digestPolicyIp("a0:*:*")); Assert.assertEquals("a0:", matcher.digestPolicyIp("A0:*:*:*")); Assert.assertEquals("a0:b0:c0:", matcher.digestPolicyIp("A0:B0:C0:*")); }
String digestPolicyIp(final String policyIp) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.digestPolicyIp(" + policyIp + ")"); } String result; Matcher matcher = allWildcards.matcher(policyIp); if (matcher.matches()) { if (LOG.isDebugEnabled()) { LOG.debug("digestPolicyIp: policyIP[" + policyIp +"] all wildcards."); } result = ""; } else if (policyIp.contains(".")) { matcher = trailingWildcardsIp4.matcher(policyIp); result = matcher.replaceFirst("."); } else { matcher = trailingWildcardsIp6.matcher(policyIp); result = matcher.replaceFirst(":").toLowerCase(); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.digestPolicyIp(" + policyIp + "): " + policyIp); } return result; }
RangerIpMatcher extends RangerAbstractConditionEvaluator { String digestPolicyIp(final String policyIp) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.digestPolicyIp(" + policyIp + ")"); } String result; Matcher matcher = allWildcards.matcher(policyIp); if (matcher.matches()) { if (LOG.isDebugEnabled()) { LOG.debug("digestPolicyIp: policyIP[" + policyIp +"] all wildcards."); } result = ""; } else if (policyIp.contains(".")) { matcher = trailingWildcardsIp4.matcher(policyIp); result = matcher.replaceFirst("."); } else { matcher = trailingWildcardsIp6.matcher(policyIp); result = matcher.replaceFirst(":").toLowerCase(); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.digestPolicyIp(" + policyIp + "): " + policyIp); } return result; } }
RangerIpMatcher extends RangerAbstractConditionEvaluator { String digestPolicyIp(final String policyIp) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.digestPolicyIp(" + policyIp + ")"); } String result; Matcher matcher = allWildcards.matcher(policyIp); if (matcher.matches()) { if (LOG.isDebugEnabled()) { LOG.debug("digestPolicyIp: policyIP[" + policyIp +"] all wildcards."); } result = ""; } else if (policyIp.contains(".")) { matcher = trailingWildcardsIp4.matcher(policyIp); result = matcher.replaceFirst("."); } else { matcher = trailingWildcardsIp6.matcher(policyIp); result = matcher.replaceFirst(":").toLowerCase(); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.digestPolicyIp(" + policyIp + "): " + policyIp); } return result; }  }
RangerIpMatcher extends RangerAbstractConditionEvaluator { String digestPolicyIp(final String policyIp) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.digestPolicyIp(" + policyIp + ")"); } String result; Matcher matcher = allWildcards.matcher(policyIp); if (matcher.matches()) { if (LOG.isDebugEnabled()) { LOG.debug("digestPolicyIp: policyIP[" + policyIp +"] all wildcards."); } result = ""; } else if (policyIp.contains(".")) { matcher = trailingWildcardsIp4.matcher(policyIp); result = matcher.replaceFirst("."); } else { matcher = trailingWildcardsIp6.matcher(policyIp); result = matcher.replaceFirst(":").toLowerCase(); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.digestPolicyIp(" + policyIp + "): " + policyIp); } return result; }  @Override void init(); @Override boolean isMatched(final RangerAccessRequest request); }
RangerIpMatcher extends RangerAbstractConditionEvaluator { String digestPolicyIp(final String policyIp) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerIpMatcher.digestPolicyIp(" + policyIp + ")"); } String result; Matcher matcher = allWildcards.matcher(policyIp); if (matcher.matches()) { if (LOG.isDebugEnabled()) { LOG.debug("digestPolicyIp: policyIP[" + policyIp +"] all wildcards."); } result = ""; } else if (policyIp.contains(".")) { matcher = trailingWildcardsIp4.matcher(policyIp); result = matcher.replaceFirst("."); } else { matcher = trailingWildcardsIp6.matcher(policyIp); result = matcher.replaceFirst(":").toLowerCase(); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerIpMatcher.digestPolicyIp(" + policyIp + "): " + policyIp); } return result; }  @Override void init(); @Override boolean isMatched(final RangerAccessRequest request);  }