From bac2ac9d50c098b2a759af8b21f89d2aab236db6 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 19:24:38 +0700 Subject: [PATCH 1/7] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20MySQLAuthHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ru/gravit/launchserver/LaunchServer.java | 5 +++++ .../ru/gravit/launchserver/auth/handler/AuthHandler.java | 5 +++++ .../gravit/launchserver/auth/handler/MySQLAuthHandler.java | 3 ++- .../ru/gravit/launchserver/auth/provider/AuthProvider.java | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 666cab6a..e8d7785c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -354,6 +354,11 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { config = Launcher.gson.fromJson(reader,Config.class); } config.verify(); + for(AuthProvider provider : config.authProvider) + { + provider.init(); + } + config.authHandler.init(); // build hooks, anti-brutforce and other buildHookManager = new BuildHookManager(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 77b568b0..b27f63df 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -65,4 +65,9 @@ public static void registerHandlers() { public abstract String uuidToUsername(UUID uuid) throws IOException; + + public void init() + { + + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java index 9b02b216..b011fba9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java @@ -22,7 +22,8 @@ public final class MySQLAuthHandler extends CachedAuthHandler { private transient String queryByUsernameSQL; private transient String updateAuthSQL; private transient String updateServerIDSQL; - public MySQLAuthHandler() + @Override + public void init() { // Prepare SQL queries queryByUUIDSQL = String.format("SELECT %s, %s, %s, %s FROM %s WHERE %s=? LIMIT 1", diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index 6580cd74..a07fdfac 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -64,4 +64,8 @@ public static String getProviderName(Class clazz) } return null; } + public void init() + { + + } } From 73dfdd1494550198a9fe21565dcc882e60584273 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 19:40:53 +0700 Subject: [PATCH 2/7] =?UTF-8?q?Reconfigurable=20=D0=B8=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20config/configHelp/configList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 4 +++ .../gravit/launchserver/Reconfigurable.java | 6 ++++ .../command/handler/CommandHandler.java | 7 ++-- .../command/service/ConfigCommand.java | 30 +++++++++++++++++ .../command/service/ConfigHelpCommand.java | 28 ++++++++++++++++ .../command/service/ConfigListCommand.java | 25 +++++++++++++++ .../command/service/ReloadInfoCommand.java | 2 -- .../manangers/ReconfigurableManager.java | 32 +++++++++++++++++++ 8 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index e8d7785c..d2d86ce7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -263,6 +263,8 @@ public static void main(String... args) throws Throwable { public final ReloadManager reloadManager; + public final ReconfigurableManager reconfigurableManager; + public final BuildHookManager buildHookManager; @@ -367,6 +369,8 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { sessionManager = new SessionManager(); mirrorManager = new MirrorManager(); reloadManager = new ReloadManager(); + reconfigurableManager = new ReconfigurableManager(); + GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); if(config.permissionsHandler instanceof Reloadable) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java new file mode 100644 index 00000000..0c83c2c8 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java @@ -0,0 +1,6 @@ +package ru.gravit.launchserver; + +public interface Reconfigurable { + void reconfig(String action,String[] args); + void printConfigHelp(); +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 0425987a..bde57a62 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -10,9 +10,7 @@ import ru.gravit.launchserver.command.hash.*; import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.ModulesCommand; -import ru.gravit.launchserver.command.service.ReloadAllCommand; -import ru.gravit.launchserver.command.service.ReloadCommand; -import ru.gravit.launchserver.command.service.ReloadInfoCommand; +import ru.gravit.launchserver.command.service.*; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; @@ -116,6 +114,9 @@ protected CommandHandler(LaunchServer server) { registerCommand("reload",new ReloadCommand(server)); registerCommand("reloadAll",new ReloadAllCommand(server)); registerCommand("reloadInfo",new ReloadInfoCommand(server)); + registerCommand("config", new ConfigCommand(server)); + registerCommand("configHelp", new ConfigHelpCommand(server)); + registerCommand("configList", new ConfigListCommand(server)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java new file mode 100644 index 00000000..137e9895 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java @@ -0,0 +1,30 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class ConfigCommand extends Command { + public ConfigCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name] [action] [more args]"; + } + + @Override + public String getUsageDescription() { + return "call reconfigurable action"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,2); + LogHelper.info("Call %s module % action",args[0],args[1]); + String[] new_args = new String[args.length - 2]; + System.arraycopy(args, 2, new_args, 0, args.length - 2); + server.reconfigurableManager.call(args[0],args[1],new_args); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java new file mode 100644 index 00000000..1e2f3d8c --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java @@ -0,0 +1,28 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class ConfigHelpCommand extends Command { + public ConfigHelpCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name]"; + } + + @Override + public String getUsageDescription() { + return "print help for config command"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,1); + LogHelper.info("Help %s module",args[0]); + server.reconfigurableManager.printHelp(args[0]); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java new file mode 100644 index 00000000..186d0e1e --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java @@ -0,0 +1,25 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; + +public class ConfigListCommand extends Command { + public ConfigListCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name]"; + } + + @Override + public String getUsageDescription() { + return "print help for config command"; + } + + @Override + public void invoke(String... args) throws Exception { + server.reconfigurableManager.printReconfigurables(); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java index ebfa04a1..df6af499 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java @@ -21,8 +21,6 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,1); - LogHelper.info("Reload %s config",args[0]); server.reloadManager.printReloadables(); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java new file mode 100644 index 00000000..45d32a1f --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java @@ -0,0 +1,32 @@ +package ru.gravit.launchserver.manangers; + +import ru.gravit.launchserver.Reconfigurable; +import ru.gravit.launchserver.Reloadable; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.VerifyHelper; + +import java.util.HashMap; +import java.util.Objects; + +public class ReconfigurableManager { + private final HashMap RECONFIGURABLE = new HashMap<>(); + public void registerReconfigurable(String name, Reconfigurable reconfigurable) + { + VerifyHelper.verifyIDName(name); + VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"), + String.format("Reloadable has been already registered: '%s'", name)); + } + public void printHelp(String name) + { + RECONFIGURABLE.get(name).printConfigHelp(); + } + public void call(String name, String action, String[] args) throws Exception { + RECONFIGURABLE.get(name).reconfig(action,args); + } + public void printReconfigurables() + { + LogHelper.info("Print reconfigurables"); + RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k)); + LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size()); + } +} From 40036362f9f8dfbb672a8618c4c40399f235899d Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 19:41:39 +0700 Subject: [PATCH 3/7] =?UTF-8?q?reloadInfo=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=20reloadLis?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/command/handler/CommandHandler.java | 2 +- .../{ReloadInfoCommand.java => ReloadListCommand.java} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename LaunchServer/src/main/java/ru/gravit/launchserver/command/service/{ReloadInfoCommand.java => ReloadListCommand.java} (83%) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index bde57a62..87210525 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -113,7 +113,7 @@ protected CommandHandler(LaunchServer server) { //Register service commands registerCommand("reload",new ReloadCommand(server)); registerCommand("reloadAll",new ReloadAllCommand(server)); - registerCommand("reloadInfo",new ReloadInfoCommand(server)); + registerCommand("reloadList",new ReloadListCommand(server)); registerCommand("config", new ConfigCommand(server)); registerCommand("configHelp", new ConfigHelpCommand(server)); registerCommand("configList", new ConfigListCommand(server)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java similarity index 83% rename from LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java index df6af499..f7e427af 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java @@ -4,8 +4,8 @@ import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; -public class ReloadInfoCommand extends Command { - public ReloadInfoCommand(LaunchServer server) { +public class ReloadListCommand extends Command { + public ReloadListCommand(LaunchServer server) { super(server); } From c64d3b1f42125cde53b421df490199fe762dd393 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 19:51:40 +0700 Subject: [PATCH 4/7] =?UTF-8?q?PermissionsManager=20=D1=83=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=B7=D0=B0=20=D0=BD=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JsonFilePermissionsHandler.java | 1 - .../auth/provider/AuthProviderResult.java | 4 ++-- .../manangers/PermissionsManager.java | 24 ------------------- 3 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index fb15aa7c..a2b837c5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -4,7 +4,6 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launchserver.Reloadable; import ru.gravit.launchserver.auth.ClientPermissions; -import ru.gravit.launchserver.manangers.PermissionsManager; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java index d34f90c1..4432bb8d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java @@ -1,7 +1,7 @@ package ru.gravit.launchserver.auth.provider; +import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.ClientPermissions; -import ru.gravit.launchserver.manangers.PermissionsManager; public class AuthProviderResult { @@ -12,7 +12,7 @@ public class AuthProviderResult { public AuthProviderResult(String username, String accessToken) { this.username = username; this.accessToken = accessToken; - permissions = PermissionsManager.getPermissions(username); + permissions = LaunchServer.server.config.permissionsHandler.getPermissions(username); } public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java deleted file mode 100644 index ea5c75b7..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java +++ /dev/null @@ -1,24 +0,0 @@ -package ru.gravit.launchserver.manangers; - -import ru.gravit.launchserver.auth.ClientPermissions; - -public class PermissionsManager { - private static PermissionsFunction function = PermissionsManager::returnDefault; - public static void registerPermissionsFunction(PermissionsFunction function) - { - PermissionsManager.function = function; - } - public static ClientPermissions getPermissions(String username) - { - return function.getPermission(username); - } - @FunctionalInterface - public interface PermissionsFunction - { - ClientPermissions getPermission(String username); - } - public static ClientPermissions returnDefault(String username) - { - return ClientPermissions.DEFAULT; - } -} From 56e5874205f0f710a0bbb3771742be9c1473a78a Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 19:54:04 +0700 Subject: [PATCH 5/7] =?UTF-8?q?=D0=98=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20Reconfigurable=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=81=D1=82=D0=B0=D1=80=D1=82=D0=B5=20=D0=BB?= =?UTF-8?q?=D0=B0=D1=83=D0=BD=D1=87=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index d2d86ce7..5df0aede 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -394,6 +394,27 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { } }); + if(config.permissionsHandler instanceof Reconfigurable) + reconfigurableManager.registerReconfigurable("permissionsHandler",(Reconfigurable) config.permissionsHandler); + if(config.authHandler instanceof Reconfigurable) + reconfigurableManager.registerReconfigurable("authHandler",(Reconfigurable) config.authHandler); + for(int i=0;i { + try { + mirrorManager.addMirror(s); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + }); + // init modules modulesManager.initModules(); From b0b2493935b89e61e13ea3f3a51418e311970249 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 20:01:36 +0700 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A3=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20whitelist=20=D1=81=20=D0=BF=D0=BE=D0=BC?= =?UTF-8?q?=D0=BE=D1=89=D1=8C=D1=8E=20Reconfigurable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/provider/RejectAuthProvider.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java index 56299bd0..16ca7081 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -1,9 +1,13 @@ package ru.gravit.launchserver.auth.provider; +import ru.gravit.launchserver.Reconfigurable; import ru.gravit.launchserver.auth.AuthException; +import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; -public final class RejectAuthProvider extends AuthProvider { +import java.util.ArrayList; + +public final class RejectAuthProvider extends AuthProvider implements Reconfigurable { public RejectAuthProvider() { } @@ -12,7 +16,7 @@ public RejectAuthProvider(String message) { } private String message; - private String[] whitelist; + private ArrayList whitelist; @Override public AuthProviderResult auth(String login, String password, String ip) throws AuthException { @@ -33,4 +37,35 @@ public AuthProviderResult auth(String login, String password, String ip) throws public void close() { // Do nothing } + + @Override + public void reconfig(String action, String[] args) { + if(action.equals("message")) + { + message = args[0]; + LogHelper.info("New reject message: %s", message); + } + else if(action.equals("whitelist.add")) + { + if(whitelist == null) whitelist = new ArrayList<>(); + whitelist.add(args[0]); + } + else if(action.equals("whitelist.remove")) + { + if(whitelist == null) whitelist = new ArrayList<>(); + whitelist.remove(args[0]); + } + else if(action.equals("whitelist.clear")) + { + whitelist.clear(); + } + } + + @Override + public void printConfigHelp() { + LogHelper.info("message [new message] - set message"); + LogHelper.info("whitelist.add [username] - add username to whitelist"); + LogHelper.info("whitelist.remove [username] - remove username into whitelist"); + LogHelper.info("whitelist.clear - clear whitelist"); + } } From 245db2dda5a4d439cf29589ff8436eabc4e03c0a Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 20:18:06 +0700 Subject: [PATCH 7/7] SwapAuthProviderCommand --- .../command/handler/CommandHandler.java | 1 + .../service/SwapAuthProviderCommand.java | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 87210525..a30f9927 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -117,6 +117,7 @@ protected CommandHandler(LaunchServer server) { registerCommand("config", new ConfigCommand(server)); registerCommand("configHelp", new ConfigHelpCommand(server)); registerCommand("configList", new ConfigListCommand(server)); + registerCommand("swapAuthProvider", new SwapAuthProviderCommand(server)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java new file mode 100644 index 00000000..97fac0b2 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java @@ -0,0 +1,61 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.auth.provider.AcceptAuthProvider; +import ru.gravit.launchserver.auth.provider.AuthProvider; +import ru.gravit.launchserver.auth.provider.RejectAuthProvider; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class SwapAuthProviderCommand extends Command { + public AuthProvider[] providersCache; + public SwapAuthProviderCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[index] [accept/reject/undo] [message(for reject)]"; + } + + @Override + public String getUsageDescription() { + return "Change authProvider"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,2); + if(providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length]; + int index = Integer.valueOf(args[0]); + if(args[1].equals("accept")) + { + if(providersCache[index] == null) + { + AcceptAuthProvider provider = new AcceptAuthProvider(); + providersCache[index] = server.config.authProvider[index]; + server.config.authProvider[index] = provider; + LogHelper.info("AuthProvider[%d] is AcceptAuthProvider",index); + } + else LogHelper.error("Changes detected. Use undo"); + } else if(args[1].equals("reject")) + { + if(providersCache[index] == null) + { + RejectAuthProvider rejectAuthProvider; + if(args.length < 3) rejectAuthProvider = new RejectAuthProvider(); + else rejectAuthProvider = new RejectAuthProvider(args[2]); + providersCache[index] = server.config.authProvider[index]; + server.config.authProvider[index] = rejectAuthProvider; + LogHelper.info("AuthProvider[%d] is RejectAuthProvider",index); + } + else LogHelper.error("Changes detected. Use undo"); + } else if(args[1].equals("undo")) + { + if(providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible"); + server.config.authProvider[index].close(); + server.config.authProvider[index] = providersCache[index]; + providersCache[index] = null; + } + } +}