|
25 | 25 | import com.maxmind.geoip2.model.AsnResponse;
|
26 | 26 | import com.maxmind.geoip2.model.CityResponse;
|
27 | 27 | import com.maxmind.geoip2.model.CountryResponse;
|
| 28 | +import com.maxmind.geoip2.model.DomainResponse; |
28 | 29 | import com.maxmind.geoip2.model.IspResponse;
|
29 | 30 | import com.maxmind.geoip2.record.*;
|
30 | 31 | import org.apache.logging.log4j.LogManager;
|
@@ -56,6 +57,7 @@ public class GeoIPFilter {
|
56 | 57 | private static final String CITY_SOUTH_AMERICA_DB_TYPE = "GeoIP2-City-South-America";
|
57 | 58 | private static final String COUNTRY_DB_TYPE = "GeoIP2-Country";
|
58 | 59 | private static final String ISP_DB_TYPE = "GeoIP2-ISP";
|
| 60 | + private static final String DOMAIN_DB_TYPE = "GeoIP2-Domain"; |
59 | 61 |
|
60 | 62 | private final String sourceField;
|
61 | 63 | private final String targetField;
|
@@ -99,6 +101,8 @@ private Set<Fields> createDesiredFields(List<String> fields) {
|
99 | 101 | case ASN_LITE_DB_TYPE:
|
100 | 102 | desiredFields = Fields.DEFAULT_ASN_LITE_FIELDS;
|
101 | 103 | break;
|
| 104 | + case DOMAIN_DB_TYPE: |
| 105 | + desiredFields = Fields.DEFAULT_DOMAIN_FIELDS; |
102 | 106 | }
|
103 | 107 | } else {
|
104 | 108 | for (String fieldName : fields) {
|
@@ -153,6 +157,9 @@ public boolean handleEvent(RubyEvent rubyEvent) {
|
153 | 157 | case ISP_DB_TYPE:
|
154 | 158 | geoData = retrieveIspGeoData(ipAddress);
|
155 | 159 | break;
|
| 160 | + case DOMAIN_DB_TYPE: |
| 161 | + geoData = retrieveDomainGeoData(ipAddress); |
| 162 | + break; |
156 | 163 | default:
|
157 | 164 | throw new IllegalStateException("Unsupported database type " + databaseReader.getMetadata().getDatabaseType() + "");
|
158 | 165 | }
|
@@ -401,4 +408,19 @@ private Map<String, Object> retrieveAsnGeoData(InetAddress ipAddress) throws Geo
|
401 | 408 |
|
402 | 409 | return geoData;
|
403 | 410 | }
|
| 411 | + |
| 412 | + private Map<String, Object> retrieveDomainGeoData(InetAddress ipAddress) throws GeoIp2Exception, IOException { |
| 413 | + DomainResponse response = databaseReader.domain(ipAddress); |
| 414 | + Map<String, Object> geoData = new HashMap<>(); |
| 415 | + for (Fields desiredField : this.desiredFields) { |
| 416 | + switch (desiredField) { |
| 417 | + case DOMAIN: |
| 418 | + String domain = response.getDomain(); |
| 419 | + geoData.put(Fields.DOMAIN.fieldName(), domain); |
| 420 | + break; |
| 421 | + } |
| 422 | + } |
| 423 | + |
| 424 | + return geoData; |
| 425 | + } |
404 | 426 | }
|
0 commit comments