Управление whitelist с помощью Reconfigurable

This commit is contained in:
Gravit 2018-12-26 20:01:36 +07:00
parent 56e5874205
commit b0b2493935
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

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