diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java index b3c5581a4d..094debd139 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java @@ -126,7 +126,7 @@ protected User authenticate(ContainerRequestContext context) { path = request.getRequestURI(); String remoteIp = request.getRemoteAddr(); - List whiteIpList = manager.authManager().listWhiteIp(); + List whiteIpList = manager.authManager().listWhiteIPs(); boolean whiteIpEnabled = manager.authManager().getWhiteIpStatus(); if (!path.contains(STRING_WHITE_IP_LIST) && whiteIpEnabled && !whiteIpList.contains(remoteIp)) { diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java similarity index 76% rename from hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpAPI.java rename to hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java index ce81bb971b..901b7a5aad 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpAPI.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/WhiteIpListAPI.java @@ -50,7 +50,7 @@ @Path("whiteiplist") @Singleton -public class WhiteIpAPI extends API { +public class WhiteIpListAPI extends API { private static final Logger LOG = Log.logger(RestServer.class); @@ -61,7 +61,7 @@ public class WhiteIpAPI extends API { public Map list(@Context GraphManager manager) { LOG.debug("List white ips"); AuthManager authManager = manager.authManager(); - List whiteIpList = authManager.listWhiteIp(); + List whiteIpList = authManager.listWhiteIPs(); return ImmutableMap.of("whiteIpList", whiteIpList); } @@ -71,52 +71,52 @@ public Map list(@Context GraphManager manager) { @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") - public Map batch(@Context GraphManager manager, + public Map updateWhiteIPs(@Context GraphManager manager, Map actionMap) { E.checkArgument(actionMap != null, "Missing argument: actionMap"); - List whiteIpList = manager.authManager().listWhiteIp(); - Object ips = actionMap.get("ips"); - E.checkArgument(ips instanceof List, - "Invalid ips type '%s', must be list", ips.getClass()); - List ipList = (List) ips; - Object value = actionMap.get("action"); - E.checkArgument(value != null, + List whiteIpList = manager.authManager().listWhiteIPs(); + Object ipListRaw = actionMap.get("ips"); + E.checkArgument(ipListRaw instanceof List, + "Invalid ips type '%s', must be list", ipListRaw.getClass()); + List ipList = (List) ipListRaw; + Object actionRaw = actionMap.get("action"); + E.checkArgument(actionRaw != null, "Missing argument: action"); - E.checkArgument(value instanceof String, + E.checkArgument(actionRaw instanceof String, "Invalid action type '%s', must be string", - value.getClass()); - String action = (String) value; + actionRaw.getClass()); + String action = (String) actionRaw; E.checkArgument(StringUtils.isNotEmpty(action), "Missing argument: action"); - List existed = new ArrayList<>(); - List loaded = new ArrayList<>(); - List illegalIps = new ArrayList<>(); + List existedIPs = new ArrayList<>(); + List loadedIPs = new ArrayList<>(); + List illegalIPs = new ArrayList<>(); Map result = new HashMap<>(); for (String ip : ipList) { if (whiteIpList.contains(ip)) { - existed.add(ip); + existedIPs.add(ip); continue; } if ("load".equals(action)) { - boolean rightIp = checkIp(ip) ? loaded.add(ip) : illegalIps.add(ip); + boolean rightIp = checkIp(ip) ? loadedIPs.add(ip) : illegalIPs.add(ip); } } switch (action) { case "load": LOG.debug("Load to white ip list"); - result.put("existed", existed); - result.put("loaded", loaded); - if (!illegalIps.isEmpty()) { - result.put("illegalIps", illegalIps); + result.put("existed_ips", existedIPs); + result.put("loaded_ips", loadedIPs); + if (!illegalIPs.isEmpty()) { + result.put("illegal_ips", illegalIPs); } - whiteIpList.addAll(loaded); + whiteIpList.addAll(loadedIPs); break; case "remove": LOG.debug("Remove from white ip list"); - result.put("removed", existed); - result.put("nonexistent", loaded); - whiteIpList.removeAll(existed); + result.put("removed", existedIPs); + result.put("nonexistent", loadedIPs); + whiteIpList.removeAll(existedIPs); break; default: throw new AssertionError(String.format("Invalid action '%s', " + @@ -124,7 +124,7 @@ public Map batch(@Context GraphManager manager, "'load' or 'remove'", action)); } - manager.authManager().setWhiteIpList(whiteIpList); + manager.authManager().setWhiteIPs(whiteIpList); return result; } @@ -132,14 +132,14 @@ public Map batch(@Context GraphManager manager, @Timed @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") - public Map update(@Context GraphManager manager, + public Map updateStatus(@Context GraphManager manager, @QueryParam("status") String status) { LOG.debug("Enable or disable white ip list"); E.checkArgument("true".equals(status) || "false".equals(status), "Invalid status, valid status is 'true' or 'false'"); boolean open = Boolean.parseBoolean(status); - manager.authManager().setWhiteIpStatus(open); + manager.authManager().enabledWhiteIpList(open); Map map = new HashMap<>(); map.put("WhiteIpListOpen", open); return map; diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java index c0ce6dbdfa..b418ef49e6 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java @@ -1569,13 +1569,13 @@ public UserWithRole validateUser(String token) { } @Override - public List listWhiteIp() { - return this.authManager.listWhiteIp(); + public List listWhiteIPs() { + return this.authManager.listWhiteIPs(); } @Override - public void setWhiteIpList(List whiteIpList) { - this.authManager.setWhiteIpList(whiteIpList); + public void setWhiteIPs(List whiteIpList) { + this.authManager.setWhiteIPs(whiteIpList); } @Override @@ -1584,8 +1584,8 @@ public boolean getWhiteIpStatus() { } @Override - public void setWhiteIpStatus(boolean status) { - this.authManager.setWhiteIpStatus(status); + public void enabledWhiteIpList(boolean status) { + this.authManager.enabledWhiteIpList(status); } @Override diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/auth/AuthManager.java b/hugegraph-core/src/main/java/org/apache/hugegraph/auth/AuthManager.java index 736747750e..c744900f64 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/auth/AuthManager.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/auth/AuthManager.java @@ -127,11 +127,11 @@ public interface AuthManager { UserWithRole validateUser(String token); - List listWhiteIp(); + List listWhiteIPs(); - void setWhiteIpList(List whiteIpList); + void setWhiteIPs(List whiteIpList); boolean getWhiteIpStatus(); - void setWhiteIpStatus(boolean status); + void enabledWhiteIpList(boolean status); } diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java b/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java index d71cfbd000..05d8a698fa 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/auth/StandardAuthManager.java @@ -78,7 +78,7 @@ public class StandardAuthManager implements AuthManager { private List ipWhiteList; - private Boolean whiteIpStatus; + private Boolean ipWhiteListEnabled; public StandardAuthManager(HugeGraphParams graph) { E.checkNotNull(graph, "graph"); @@ -110,7 +110,7 @@ public StandardAuthManager(HugeGraphParams graph) { this.ipWhiteList = new ArrayList<>(); - this.whiteIpStatus = false; + this.ipWhiteListEnabled = false; } private Cache cache(String prefix, long capacity, @@ -697,23 +697,23 @@ public UserWithRole validateUser(String token) { } @Override - public List listWhiteIp() { + public List listWhiteIPs() { return ipWhiteList; } @Override - public void setWhiteIpList(List ipWhiteList) { + public void setWhiteIPs(List ipWhiteList) { this.ipWhiteList = ipWhiteList; } @Override public boolean getWhiteIpStatus() { - return this.whiteIpStatus; + return this.ipWhiteListEnabled; } @Override - public void setWhiteIpStatus(boolean status) { - this.whiteIpStatus = status; + public void enabledWhiteIpList(boolean status) { + this.ipWhiteListEnabled = status; } /**