From ae41aed490d32808a654266eb5a3f4f3fedd91d6 Mon Sep 17 00:00:00 2001 From: joethei Date: Sun, 20 Nov 2016 09:27:25 +0100 Subject: [PATCH] + SecurityHandler now caches data --- Commons.iml | 2 +- pom.xml | 8 +++++-- .../commons/security/SecurityHandler.java | 23 ++++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Commons.iml b/Commons.iml index bcd242c..a4fff0e 100644 --- a/Commons.iml +++ b/Commons.iml @@ -23,7 +23,7 @@ - + diff --git a/pom.xml b/pom.xml index 337d1f0..46de0d1 100644 --- a/pom.xml +++ b/pom.xml @@ -70,13 +70,17 @@ - + + + univentoEU + http://dev.joethei.de:8081/repository/public/ @@ -135,7 +139,7 @@ com.github.theholywaffle teamspeak3-api - [1.0.0,2.0.0) + 1.0.13 org.apache.logging.log4j diff --git a/src/main/java/eu/univento/commons/security/SecurityHandler.java b/src/main/java/eu/univento/commons/security/SecurityHandler.java index 575d64b..6271057 100644 --- a/src/main/java/eu/univento/commons/security/SecurityHandler.java +++ b/src/main/java/eu/univento/commons/security/SecurityHandler.java @@ -2,7 +2,9 @@ package eu.univento.commons.security; import eu.univento.commons.Commons; +import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.function.Consumer; /** @@ -13,18 +15,27 @@ public class SecurityHandler { private Commons commons; + private ArrayList cache = new ArrayList<>(); + public SecurityHandler(Commons commons) { this.commons = commons; - } - - public void isValidServer(String ip, Consumer consumer) { - commons.getDatabaseManager().getAsyncMySQL().query("SELECT * FROM Servers WHERE ip='" + ip + "';", resultSet -> { + load(resultSet -> { try { - consumer.accept(resultSet.next()); + while (resultSet.next()) { + cache.add(resultSet.getString("ip")); + } + resultSet.close(); } catch (SQLException e) { e.printStackTrace(); - consumer.accept(false); } }); } + + public boolean isValidServer(String ip) { + return cache.contains(ip); + } + + private void load(Consumer consumer) { + commons.getDatabaseManager().getAsyncMySQL().query("SELECT * FROM Servers;", consumer); + } } \ No newline at end of file