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

add subnet whitelist filtering #15 #19

Open
wants to merge 2 commits into
base: restaction
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
language: java
language: java
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<artifactId>hawkj</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.net.util.SubnetUtils;

import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
Expand All @@ -19,7 +20,7 @@
//# possible http config
//http.basic.user: admin
//http.basic.password: password
//http.basic.ipwhitelist: ["localhost", "somemoreip"]
//http.basic.ipwhitelist: ["localhost", "somemoreip" , "192.168.1.0/24"]
//http.basic.xforward: "X-Forwarded-For"
//# if you use javascript
//# EITHER $.ajaxSetup({ headers: { 'Authorization': "Basic " + credentials }});
Expand Down Expand Up @@ -110,6 +111,11 @@ protected boolean isInIPWhitelist(RestRequest request) {
// addr, request.path(), request.params());
if (whitelist.isEmpty() || addr.isEmpty())
return false;
// Check if there are CIDR in whitelist configuration and then use it!
if (addr.contains("/")) {
SubnetUtils utils = new SubnetUtils(addr);
return utils.getInfo().isInRange(addr);
}
return whitelist.contains(addr);
}

Expand Down