use of edazdarevic.commons.net.CIDRUtils in project mxisd by kamax-io.
the class RecursivePriorityLookupStrategy method build.
@PostConstruct
private void build() throws UnknownHostException {
try {
log.info("Found {} providers", providers.size());
providers.forEach(p -> log.info("\t- {}", p.getClass().getName()));
providers.sort((o1, o2) -> Integer.compare(o2.getPriority(), o1.getPriority()));
log.info("Recursive lookup enabled: {}", cfg.isEnabled());
for (String cidr : cfg.getAllowedCidr()) {
log.info("{} is allowed for recursion", cidr);
allowedCidr.add(new CIDRUtils(cidr));
}
} catch (UnknownHostException e) {
throw new ConfigurationException("lookup.recursive.allowedCidrs", "Allowed CIDRs");
}
}
use of edazdarevic.commons.net.CIDRUtils in project mxisd by kamax-io.
the class RecursivePriorityLookupStrategy method isAllowedForRecursive.
private boolean isAllowedForRecursive(String source) {
boolean canRecurse = false;
try {
if (cfg.getRecursive().isEnabled()) {
log.debug("Checking {} CIDRs for recursion", allowedCidr.size());
for (CIDRUtils cidr : allowedCidr) {
if (cidr.isInRange(source)) {
log.debug("{} is in range {}, allowing recursion", source, cidr.getNetworkAddress());
canRecurse = true;
break;
} else {
log.debug("{} is not in range {}", source, cidr.getNetworkAddress());
}
}
}
} catch (UnknownHostException e) {
// this should never happened as we should have only IP ranges!
log.error("Unexpected {} exception: {}", e.getClass().getSimpleName(), e.getMessage());
}
return canRecurse;
}
Aggregations