Search in sources :

Example 1 with CIDRUtils

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");
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) CIDRUtils(edazdarevic.commons.net.CIDRUtils) ConfigurationException(io.kamax.mxisd.exception.ConfigurationException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with CIDRUtils

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) CIDRUtils(edazdarevic.commons.net.CIDRUtils)

Aggregations

CIDRUtils (edazdarevic.commons.net.CIDRUtils)2 UnknownHostException (java.net.UnknownHostException)2 ConfigurationException (io.kamax.mxisd.exception.ConfigurationException)1 PostConstruct (javax.annotation.PostConstruct)1