/** * <p>validateIPMatch</p> * * @param ip a {@link java.lang.String} object. * @return a boolean. */ public boolean validateIPMatch(String ip){ if(IPLike.matches(m_address, ip)){ return m_isSupported; }else{ return false; } }
private static void validateAddress(String errorContext, String address) { Objects.requireNonNull(errorContext); try { // Matches actually verifies the "pattern" before a match against a concrete ip address is performed // As we are only interesting in the validation, we just use "8.8.8.8". IPLike.matches("8.8.8.8", address); } catch (Exception ex) { throw new ClassificationException(errorContext, Errors.RULE_IP_ADDRESS_INVALID, address); } }
private static void validateAddress(String errorContext, String address) { Objects.requireNonNull(errorContext); try { // Matches actually verifies the "pattern" before a match against a concrete ip address is performed // As we are only interesting in the validation, we just use "8.8.8.8". IPLike.matches("8.8.8.8", address); } catch (Exception ex) { throw new ClassificationException(errorContext, Errors.RULE_IP_ADDRESS_INVALID, address); } }
public static boolean matches(final InetAddress address, final String pattern) { return matches(InetAddressUtils.str(address), pattern); }
@Override public void visitIpMatches(final List<String> ipMatches) { // if we've already matched a specific or range, don't bother with the ipmatches if (!shouldTryToMatch()) return; for (final String ipMatch : ipMatches) { if (IPLike.matches(m_address, ipMatch)) { handleMatch(); return; } } }
@Override public boolean matches(ClassificationRequest request) { if (value.isWildcard()) { return true; } final String currentAddressValue = valueExtractor.apply(request); if (value.hasWildcard()) { return IPLike.matches(currentAddressValue, value.getValue()); } return value.getValue().equals(currentAddressValue); } }
public boolean isProtocolSupported(InetAddress address, Map<String, Object> qualifiers) { if (qualifiers == null) { return false; } String ipMatch = getIpMatch(qualifiers); if (IPLike.matches(InetAddressUtils.str(address), ipMatch)) { return isSupported(qualifiers); } else { return false; } }
protected static void validateIpAddress(String errorContext, String ipAddressValue) throws InvalidRuleException { if (Strings.isNullOrEmpty(ipAddressValue)) { throw new InvalidRuleException(errorContext, Errors.RULE_IP_ADDRESS_INVALID, ipAddressValue); } try { StringValue value = new StringValue(ipAddressValue); if (!value.isWildcard()) { // The matches method parses the pattern (in this case the ipAddressValue) and validates // the address, as we don't care if it actually matches. We only want to know, if it considers the // "pattern" (in this case a concrete address) correct. IPLike.matches("8.8.8.8", ipAddressValue); } } catch (Exception ex) { throw new InvalidRuleException(errorContext, Errors.RULE_IP_ADDRESS_INVALID, ipAddressValue); } }
@Test public void testVerifyIpMatch() { assertTrue(IPLike.matches("192.168.0.1", "*.*.*.*")); assertTrue(IPLike.matches("192.168.0.1", "192.*.*.*")); assertTrue(IPLike.matches("192.168.0.1", "*.168.*.*")); assertTrue(IPLike.matches("192.168.0.1", "*.*.0.*")); assertTrue(IPLike.matches("192.168.0.1", "*.*.*.1")); assertTrue(IPLike.matches("192.168.0.1", "*.*.*.0-7")); assertTrue(IPLike.matches("192.168.0.1", "192.168.0.0-7")); assertTrue(IPLike.matches("192.168.0.1", "192.166,167,168.*.0,1,5-10")); assertFalse(IPLike.matches("192.168.0.1", "10.0.0.1")); assertFalse(IPLike.matches("192.168.0.1", "*.168.*.2")); assertFalse(IPLike.matches("192.168.0.1", "10.168.0.1")); assertTrue(IPLike.matches("10.1.1.1", "10.1.1.1")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd", "*:*:*:*:*:*:*:*")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4", "*:*:*:*:*:*:*:*")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4", "*:*:*:*:*:*:*:*%4")); assertFalse(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd", "*:*:*:*:*:*:*:*%4")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd", "fe80:*:*:*:*:*:*:*")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4", "fe80:*:*:*:*:*:*:*")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4", "fe80:*:*:*:*:*:*:*%4")); assertFalse(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd", "fe80:*:*:*:*:*:*:*%4")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd", "*:*:*:0:*:*:*:*")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4", "*:*:*:0:*:*:*:*")); assertTrue(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4", "*:*:*:0:*:*:*:*%4")); assertFalse(IPLike.matches("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd", "*:*:*:0:*:*:*:*%4"));
@Override public Definition getAgentConfig(InetAddress agentInetAddress) { Objects.requireNonNull(agentInetAddress); for (Definition def : getConfig().getDefinition()) { // Check the specifics first for (String saddr : def.getSpecific()) { InetAddress addr = InetAddressUtils.addr(saddr); if (addr.equals(agentInetAddress)) { return def; } } // Check the ranges for (Range rng : def.getRange()) { if (InetAddressUtils.isInetAddressInRange(InetAddressUtils.str(agentInetAddress), rng.getBegin(), rng.getEnd())) { return def; } } // Check the matching IP expressions for (String ipMatch : def.getIpMatch()) { if (IPLike.matches(InetAddressUtils.str(agentInetAddress), ipMatch)) { return def; } } } // No definition references the given agent address, use the defaults return new Definition(getConfig()); }
@Override public Definition getAgentConfig(InetAddress agentInetAddress) { Objects.requireNonNull(agentInetAddress); for (Definition def : getConfig().getDefinition()) { // Check the specifics first for (String saddr : def.getSpecific()) { InetAddress addr = InetAddressUtils.addr(saddr); if (addr.equals(agentInetAddress)) { return def; } } // Check the ranges for (Range rng : def.getRange()) { if (InetAddressUtils.isInetAddressInRange(InetAddressUtils.str(agentInetAddress), rng.getBegin(), rng.getEnd())) { return def; } } // Check the matching IP expressions for (String ipMatch : def.getIpMatch()) { if (IPLike.matches(InetAddressUtils.str(agentInetAddress), ipMatch)) { return def; } } } // No definition references the given agent address, use the defaults return new Definition(getConfig()); }
if (IPLike.matches(InetAddressUtils.str(agentInetAddress), ipMatch)) { setAmiAgentConfig(agentConfig, def); break DEFLOOP;
if (IPLike.matches(InetAddressUtils.str(agentInetAddress), ipMatch)) { setWmiAgentConfig(agentConfig, def); break DEFLOOP;
if (IPLike.matches(InetAddressUtils.str(agentInetAddress), ipMatch)) { setNSClientAgentConfig(agentConfig, def); break DEFLOOP;
if (IPLike.matches(InetAddressUtils.str(agentInetAddress), ipMatch)) { setNSClientAgentConfig(agentConfig, def); break DEFLOOP;