Skip to content

Commit

Permalink
new auth provider setup
Browse files Browse the repository at this point in the history
  • Loading branch information
phybros committed Sep 28, 2023
1 parent 397f6dd commit 1109d50
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/io/servertap/ServerTapMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,13 +23,15 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

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<ConsoleLine> consoleBuffer = new ArrayList<>();
private ExternalPluginWrapperRepo externalPluginWrapperRepo;
private WebhookEventListener webhookEventListener;
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/servertap/auth/UselessAuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1109d50

Please sign in to comment.