Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.

Implemented CIDR subnet whitelisting in version 1.4 #61

Open
wants to merge 3 commits into
base: 1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- Create a zip file according to elasticsearch naming scheme -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.asquera.elasticsearch.plugins.http.auth;
import org.apache.commons.net.util.SubnetUtils;
import org.elasticsearch.common.logging.Loggers;

import java.util.ArrayList;
Expand Down Expand Up @@ -90,20 +91,40 @@ Set<String> getStringWhitelist() {
*
*/
static Set<InetAddress> toInetAddress(List<String> ips) {
List<InetAddress> listIps = new ArrayList<InetAddress>();
Iterator<String> iterator = ips.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
try {
listIps.add(InetAddress.getByName(next));
} catch (UnknownHostException e) {
String template = "an ip set in the whitelist settings raised an " +
"UnknownHostException: {}, dropping it";
Loggers.getLogger(InetAddressWhitelist.class).info(template, e.getMessage());
}
}
return new HashSet<InetAddress>(listIps);
}
List<InetAddress> listIps = new ArrayList<InetAddress>();
Iterator<String> iterator = ips.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
if (next == null) {
try {
listIps.add(InetAddress.getByName("localhost"));
} catch (UnknownHostException e) {
String template = "an ip set in the whitelist settings raised an "
+ "UnknownHostException: {}, dropping it";
Loggers.getLogger(InetAddressWhitelist.class).info(template, e.getMessage());
}
continue;
}

try {
if (next.contains("/")) {
SubnetUtils subnetUtils = new SubnetUtils(next);
String[] allAddressesInRange = subnetUtils.getInfo().getAllAddresses();
for (String addressInRange : allAddressesInRange) {
listIps.add(InetAddress.getByName(addressInRange));
}
} else {
listIps.add(InetAddress.getByName(next));
}
} catch (UnknownHostException e) {
String template = "an ip set in the whitelist settings raised an "
+ "UnknownHostException: {}, dropping it";
Loggers.getLogger(InetAddressWhitelist.class).info(template, e.getMessage());
}
}

return new HashSet<InetAddress>(listIps);
}

/**
* delegate method
Expand Down