From f2c0815123c317318d009eb6ef9014406c794882 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 11 Feb 2020 06:08:35 +0100 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20AuthProvider=20=D0=B2=20[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 2 +- .../launchserver/auth/AuthProviderPair.java | 10 ++--- .../command/service/ServerStatusCommand.java | 2 +- .../config/LaunchServerConfig.java | 38 +++++++++---------- .../auth/GetAvailabilityAuthResponse.java | 2 +- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 251d9374..c0a511f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -76,7 +76,7 @@ public interface LaunchServerConfigManager { public void reload(ReloadType type) throws Exception { config.close(type); - AuthProviderPair[] pairs = null; + Map pairs = null; if (type.equals(ReloadType.NO_AUTH)) { pairs = config.auth; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 5af479e3..e9da8e5e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -15,20 +15,20 @@ public class AuthProviderPair { public TextureProvider textureProvider; public HWIDHandler hwid; public Map links; - public final String name; + public transient String name; public String displayName; public final boolean isDefault = true; - public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid, String name) { + public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid) { this.provider = provider; this.handler = handler; this.textureProvider = textureProvider; this.hwid = hwid; - this.name = name; } - public void init(LaunchServer srv) { - if(links != null) link(srv); + public void init(LaunchServer srv, String name) { + this.name = name; + if(links != null) link(srv); if(provider == null) throw new NullPointerException(String.format("Auth %s provider null", name)); if(handler == null) throw new NullPointerException(String.format("Auth %s handler null", name)); if(textureProvider == null) throw new NullPointerException(String.format("Auth %s textureProvider null", name)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java index d5a270e5..f7c1b9cd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java @@ -39,7 +39,7 @@ public void invoke(String... args) { commands += category.category.commandsMap().size(); } LogHelper.info("Sessions: %d | Commands: %d(%d categories)", server.sessionManager.getSessions().size(), commands, server.commandHandler.getCategories().size() + 1); - for (AuthProviderPair pair : server.config.auth) { + for (AuthProviderPair pair : server.config.auth.values()) { if (pair.handler instanceof CachedAuthHandler) { LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size()); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 73b62f03..c405d378 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -47,27 +47,21 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) { // Handlers & Providers - public AuthProviderPair[] auth; + public Map auth; public DaoProvider dao; private transient AuthProviderPair authDefault; - private transient Map authPairs = null; public AuthProviderPair getAuthProviderPair(String name) { - if (authPairs == null) { - Map pairs = new HashMap<>(); - for (AuthProviderPair p : auth) pairs.put(p.name, p); - authPairs = pairs; - } - return authPairs.get(name); + return auth.get(name); } public ProtectHandler protectHandler; public AuthProviderPair getAuthProviderPair() { if (authDefault != null) return authDefault; - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { if (pair.isDefault) { authDefault = pair; return pair; @@ -102,11 +96,12 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) { public void verify() { - if (auth == null || auth[0] == null) { - throw new NullPointerException("AuthHandler must not be null"); + if (auth == null || auth.size() < 1) { + throw new NullPointerException("AuthProviderPair`s count should be at least one"); } + boolean isOneDefault = false; - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { if (pair.isDefault) { isOneDefault = true; break; @@ -128,9 +123,8 @@ public void verify() { public void init(LaunchServer.ReloadType type) { Launcher.applyLauncherEnv(env); - authPairs = null; - for (AuthProviderPair provider : auth) { - provider.init(server); + for (Map.Entry provider : auth.entrySet()) { + provider.getValue().init(server, provider.getKey()); } if (dao != null) dao.init(server); @@ -141,7 +135,7 @@ public void init(LaunchServer.ReloadType type) { components.forEach((k, v) -> server.registerObject("component.".concat(k), v)); } if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); @@ -154,7 +148,7 @@ public void init(LaunchServer.ReloadType type) { public void close(LaunchServer.ReloadType type) { try { if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); @@ -177,7 +171,7 @@ public void close(LaunchServer.ReloadType type) { LogHelper.error(e); } try { - for (AuthProviderPair p : auth) p.close(); + for (AuthProviderPair p : auth.values()) p.close(); } catch (IOException e) { LogHelper.error(e); } @@ -282,11 +276,13 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.launch4j.maxVersion = "1.8.999"; newConfig.env = LauncherConfig.LauncherEnvironment.STD; newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh"; - newConfig.auth = new AuthProviderPair[]{new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), + newConfig.auth = new HashMap<>(); + AuthProviderPair a = new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") - , new AcceptHWIDHandler(), "std")}; - newConfig.auth[0].displayName = "Default"; + , new AcceptHWIDHandler()); + a.displayName = "Default"; + newConfig.auth.put("std", a); newConfig.protectHandler = new StdProtectHandler(); if (env.equals(LaunchServer.LaunchServerEnv.TEST)) newConfig.binaryName = "Launcher"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index 79e63047..f617d67c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -18,7 +18,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { List list = new ArrayList<>(); - for (AuthProviderPair pair : server.config.auth) { + for (AuthProviderPair pair : server.config.auth.values()) { list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType())); } sendResult(new GetAvailabilityAuthRequestEvent(list));