diff --git a/src/main/java/io/servertap/ServerTapMain.java b/src/main/java/io/servertap/ServerTapMain.java index b28944c3..9af858b7 100644 --- a/src/main/java/io/servertap/ServerTapMain.java +++ b/src/main/java/io/servertap/ServerTapMain.java @@ -2,6 +2,7 @@ import io.servertap.api.v1.models.ConsoleLine; import io.servertap.auth.RequestAuthProvider; +import io.servertap.auth.UselessAuthProvider; import io.servertap.commands.ServerTapCommand; import io.servertap.metrics.Metrics; import io.servertap.plugin.api.ServerTapWebserverService; @@ -22,6 +23,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -29,6 +31,7 @@ public class ServerTapMain extends JavaPlugin { private static final java.util.logging.Logger log = Bukkit.getLogger(); private final Logger rootLogger = (Logger) LogManager.getRootLogger(); + private static final String defaultAuthProviderName = "io.servertap.auth.UselessAuthProvider"; private final List consoleBuffer = new ArrayList<>(); private ExternalPluginWrapperRepo externalPluginWrapperRepo; private WebhookEventListener webhookEventListener; @@ -87,6 +90,26 @@ private void setupWebServer(FileConfiguration bukkitConfig) { app = new WebServer(this, bukkitConfig, log); app.start(bukkitConfig.getInt("port", 4567)); WebServerRoutes.addV1Routes(this, log, lagDetector, app, consoleListener, externalPluginWrapperRepo); + + try { + String providerName = bukkitConfig.getString("auth.provider", defaultAuthProviderName); + Class provider = Class.forName(providerName); + RequestAuthProvider requestAuthProvider = (RequestAuthProvider) provider.getDeclaredConstructor().newInstance(); + setAuthProvider(requestAuthProvider); + + log.info(String.format("Using auth provider: %s", providerName)); + } + catch (ClassNotFoundException cex) { + throw new RuntimeException(cex); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } } public void reload() { diff --git a/src/main/java/io/servertap/auth/UselessAuthProvider.java b/src/main/java/io/servertap/auth/UselessAuthProvider.java index bf07ecae..3cd96082 100644 --- a/src/main/java/io/servertap/auth/UselessAuthProvider.java +++ b/src/main/java/io/servertap/auth/UselessAuthProvider.java @@ -2,12 +2,16 @@ import io.javalin.http.Context; import io.javalin.http.Handler; +import org.bukkit.Bukkit; public class UselessAuthProvider implements RequestAuthProvider { + private static final java.util.logging.Logger log = Bukkit.getLogger(); + @Override public void authenticateRequest(Handler handler, Context ctx) throws Exception { // do nothing, just allow the request lol! + log.info("USELESSLY HANDLING A REQUEST!"); handler.handle(ctx); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1848dcd4..6be30e37 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,6 +4,9 @@ useKeyAuth: true key: 'change_me' normalizeMessages: true +auth: + provider: io.servertap.auth.UselessAuthProvider + # TLS (a.k.a. SSL) options tls: # Set to true to enable TLS