From fe2177151e6134963f44c40c5d68367407669ce4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 31 Dec 2018 14:51:49 +0700 Subject: [PATCH] AuthHookManager --- .../ru/gravit/launchserver/LaunchServer.java | 7 ++- .../manangers/AuthHookManager.java | 45 +++++++++++++++++++ .../response/auth/AuthResponse.java | 20 +++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/manangers/AuthHookManager.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 76bb4ee4..10cdd731 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -277,6 +277,8 @@ public static void main(String... args) throws Throwable { public final SessionManager sessionManager; public final SocketHookManager socketHookManager; + + public final AuthHookManager authHookManager; // Server public final ModulesManager modulesManager; @@ -393,6 +395,7 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { reloadManager = new ReloadManager(); reconfigurableManager = new ReconfigurableManager(); socketHookManager = new SocketHookManager(); + authHookManager = new AuthHookManager(); GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); @@ -538,11 +541,13 @@ private void generateConfigIfNotExists() throws IOException { newConfig.launch4j = new ExeConf(); newConfig.launch4j.copyright = "© GravitLauncher Team"; newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString()); - newConfig.launch4j.fileVer = Launcher.getVersion().getVersionString(); + newConfig.launch4j.fileVer = Launcher.getVersion().getVersionString().concat(".").concat(String.valueOf(Launcher.getVersion().patch)); newConfig.launch4j.internalName = "Launcher"; newConfig.launch4j.trademarks = "This product is licensed under GPLv3"; newConfig.launch4j.txtFileVersion = "%s, build %d"; newConfig.launch4j.txtProductVersion = "%s, build %d"; + newConfig.launch4j.productName = "GravitLauncher"; + newConfig.launch4j.productVer = newConfig.launch4j.fileVer; newConfig.buildPostTransform = new PostBuildTransformConf(); newConfig.env = LauncherConfig.LauncherEnvironment.STD; newConfig.authHandler = new MemoryAuthHandler(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/AuthHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/AuthHookManager.java new file mode 100644 index 00000000..ed6c49a8 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/AuthHookManager.java @@ -0,0 +1,45 @@ +package ru.gravit.launchserver.manangers; + +import ru.gravit.launchserver.response.auth.AuthResponse; +import ru.gravit.launchserver.socket.Client; + +import java.util.HashSet; +import java.util.Set; + +public class AuthHookManager { + private Set PRE_HOOKS = new HashSet<>(); + private Set POST_HOOKS = new HashSet<>(); + @FunctionalInterface + public interface AuthPreHook + { + void preAuthHook(AuthResponse.AuthContext context, Client client); + } + public interface AuthPostHook + { + void postAuthHook(AuthResponse.AuthContext context, Client client); + } + public void registerPostHook(AuthPostHook hook) + { + if(POST_HOOKS == null) POST_HOOKS = new HashSet<>(); + POST_HOOKS.add(hook); + } + public void registerPreHook(AuthPreHook hook) + { + if(PRE_HOOKS == null) PRE_HOOKS = new HashSet<>(); + PRE_HOOKS.add(hook); + } + public void preHook(AuthResponse.AuthContext context, Client client) + { + for(AuthPreHook preHook : PRE_HOOKS) + { + preHook.preAuthHook(context,client); + } + } + public void postHook(AuthResponse.AuthContext context, Client client) + { + for(AuthPostHook postHook : POST_HOOKS) + { + postHook.postAuthHook(context, client); + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index 0d64fa62..4bbf84e9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -35,7 +35,24 @@ private static String echo(int length) { public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { super(server, session, input, output, ip); } + public static class AuthContext + { + public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) { + this.session = session; + this.login = login; + this.password_lenght = password_lenght; + this.client = client; + this.hwid = hwid; + this.isServerAuth = isServerAuth; + } + public long session; + public String login; + public int password_lenght; //Use AuthProvider for get password + public String client; + public String hwid; + public boolean isServerAuth; + } @Override public void reply() throws Exception { String login = input.readString(SerializeLimits.MAX_LOGIN); @@ -63,7 +80,9 @@ public void reply() throws Exception { AuthProvider provider = server.config.authProvider[auth_id]; Client clientData = server.sessionManager.getClient(session); clientData.type = Client.Type.USER; + AuthContext context = new AuthContext(session,login,password.length(),client,hwid_str,false); try { + server.authHookManager.preHook(context,clientData); if (server.limiter.isLimit(ip)) { AuthProvider.authError(server.config.authRejectString); return; @@ -91,6 +110,7 @@ public void reply() throws Exception { } } server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username); + server.authHookManager.postHook(context,clientData); } catch (AuthException | HWIDException e) { if(e.getMessage() == null) LogHelper.error(e); requestError(e.getMessage());