
io.bdrc.auth.rdf.SubscribersLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bdrc-auth-lib Show documentation
Show all versions of bdrc-auth-lib Show documentation
BDRC authorization library based on auth0
package io.bdrc.auth.rdf;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import inet.ipaddr.IPAddress;
import inet.ipaddr.IPAddressString;
public class SubscribersLoader implements IPCache.Loader {
public final static Logger log = LoggerFactory.getLogger(SubscribersLoader.class.getName());
private Map> subscriberToIPs;
public SubscribersLoader(Map> subscriberToIPs) {
this.subscriberToIPs = subscriberToIPs;
}
@Override
public String loadSubscriber(String ipStr) throws IOException {
IPAddressString str = new IPAddressString(ipStr);
IPAddress addr = str.getAddress();
if (addr == null) {
log.error("cannot parse {}", ipStr);
return null;
}
for (final Entry> e : this.subscriberToIPs.entrySet()) {
for (final IPAddress subip : e.getValue()) {
if (subip.contains(addr)) {
log.debug("matched ip {} with subscriber {}", ipStr, e.getKey());
return e.getKey();
}
}
}
log.debug("coun't match ip {} with a subscriber", ipStr);
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy