From 245db2dda5a4d439cf29589ff8436eabc4e03c0a Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 20:18:06 +0700 Subject: [PATCH] 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; + } + } +}