+ SecurityHandler now caches data

This commit is contained in:
Johannes Theiner 2016-11-20 09:27:25 +01:00
parent f3f0a116b9
commit ae41aed490
3 changed files with 24 additions and 9 deletions

View File

@ -23,7 +23,7 @@
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" /> <orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.4" level="project" /> <orderEntry type="library" name="Maven: joda-time:joda-time:2.9.4" level="project" />
<orderEntry type="library" name="Maven: com.github.theholywaffle:teamspeak3-api:1.0.14-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: com.github.theholywaffle:teamspeak3-api:1.0.13" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: net.gpedro.integrations.slack:slack-webhook:1.2.1" level="project" /> <orderEntry type="library" name="Maven: net.gpedro.integrations.slack:slack-webhook:1.2.1" level="project" />

View File

@ -70,13 +70,17 @@
</build> </build>
<repositories> <repositories>
<repository> <!--<repository>
<id>TeamSpeak-3-Java-API-mvn-repo</id> <id>TeamSpeak-3-Java-API-mvn-repo</id>
<url>https://raw.githubusercontent.com/TheHolyWaffle/TeamSpeak-3-Java-API/mvn-repo/</url> <url>https://raw.githubusercontent.com/TheHolyWaffle/TeamSpeak-3-Java-API/mvn-repo/</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
<updatePolicy>always</updatePolicy> <updatePolicy>always</updatePolicy>
</snapshots> </snapshots>
</repository>-->
<repository>
<id>univentoEU</id>
<url>http://dev.joethei.de:8081/repository/public/</url>
</repository> </repository>
</repositories> </repositories>
@ -135,7 +139,7 @@
<dependency> <dependency>
<groupId>com.github.theholywaffle</groupId> <groupId>com.github.theholywaffle</groupId>
<artifactId>teamspeak3-api</artifactId> <artifactId>teamspeak3-api</artifactId>
<version>[1.0.0,2.0.0)</version> <version>1.0.13</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>

View File

@ -2,7 +2,9 @@ package eu.univento.commons.security;
import eu.univento.commons.Commons; import eu.univento.commons.Commons;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@ -13,18 +15,27 @@ public class SecurityHandler {
private Commons commons; private Commons commons;
private ArrayList<String> cache = new ArrayList<>();
public SecurityHandler(Commons commons) { public SecurityHandler(Commons commons) {
this.commons = commons; this.commons = commons;
} load(resultSet -> {
public void isValidServer(String ip, Consumer<Boolean> consumer) {
commons.getDatabaseManager().getAsyncMySQL().query("SELECT * FROM Servers WHERE ip='" + ip + "';", resultSet -> {
try { try {
consumer.accept(resultSet.next()); while (resultSet.next()) {
cache.add(resultSet.getString("ip"));
}
resultSet.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
consumer.accept(false);
} }
}); });
} }
public boolean isValidServer(String ip) {
return cache.contains(ip);
}
private void load(Consumer<ResultSet> consumer) {
commons.getDatabaseManager().getAsyncMySQL().query("SELECT * FROM Servers;", consumer);
}
} }