SwapAuthProviderCommand

This commit is contained in:
Gravit 2018-12-26 20:18:06 +07:00
parent b0b2493935
commit 245db2dda5
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 62 additions and 0 deletions

View file

@ -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));
}

View file

@ -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;
}
}
}