Add AuthLimiter IP exclusions.

* Add AuthLimiter IP exclusions #63.
This commit is contained in:
Zaxar163 2018-11-20 20:18:18 +03:00 committed by GitHub
parent 591bdea6f4
commit 3c960eb501
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View file

@ -93,6 +93,8 @@ public static final class Config extends ConfigObject {
public final int authRateLimitMilis;
public final ListConfigEntry authLimitExclusions;
public final String authRejectString;
public final String projectName;
@ -122,6 +124,7 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
VerifyHelper.range(0, 1000000), "Illegal authRateLimit");
authRateLimitMilis = VerifyHelper.verifyInt(block.getEntryValue("authRateLimitMilis", IntegerConfigEntry.class),
VerifyHelper.range(10, 10000000), "Illegal authRateLimitMillis");
authLimitExclusions = block.hasEntry("authLimitExclusions") ? block.getEntry("authLimitExclusions", ListConfigEntry.class) : null;
bindAddress = block.hasEntry("bindAddress") ?
block.getEntryValue("bindAddress", StringConfigEntry.class) : getAddress();
authRejectString = block.hasEntry("authRejectString") ?
@ -129,7 +132,6 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
whitelistRejectString = block.hasEntry("whitelistRejectString") ?
block.getEntryValue("whitelistRejectString", StringConfigEntry.class) : "Вас нет в белом списке";
// Set handlers & providers
authHandler = new AuthHandler[1];
authHandler[0] = AuthHandler.newHandler(block.getEntryValue("authHandler", StringConfigEntry.class),

View file

@ -1,8 +1,11 @@
package ru.gravit.launchserver.auth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import ru.gravit.launcher.NeedGarbageCollection;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.launchserver.LaunchServer;
public class AuthLimiter implements NeedGarbageCollection {
@ -50,10 +53,13 @@ public String toString() {
public final int rateLimit;
public final int rateLimitMilis;
private HashMap<String, AuthEntry> map;
private final HashMap<String, AuthEntry> map;
private final List<String> excludeIps;
public AuthLimiter(LaunchServer srv) {
map = new HashMap<>();
excludeIps = new ArrayList<>();
if (srv.config.authLimitExclusions != null) srv.config.authLimitExclusions.stream(StringConfigEntry.class).forEach(excludeIps::add);
rateLimit = srv.config.authRateLimit;
rateLimitMilis = srv.config.authRateLimitMilis;
}
@ -66,6 +72,7 @@ public void garbageCollection() {
}
public boolean isLimit(String ip) {
if (excludeIps.contains(ip)) return false;
if (map.containsKey(ip)) {
AuthEntry rate = map.get(ip);
long currenttime = System.currentTimeMillis();

View file

@ -54,10 +54,8 @@ protected AuthHandler(BlockConfigEntry block) {
super(block);
}
public abstract UUID auth(AuthProviderResult authResult) throws IOException;
public abstract UUID checkServer(String username, String serverID) throws IOException;
@Override

View file

@ -11,7 +11,6 @@
import javafx.scene.shape.Arc;
import javafx.scene.shape.Circle;
import javafx.util.Duration;
import ru.gravit.launcher.LauncherAPI;
/**
* Skin of the ring progress indicator where an arc grows and by the progress value up to 100% where the arc becomes a ring.