From f81cdf6440f3adafb22cdb3bddc35f998c6be05e Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 19 Jan 2020 12:22:35 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20permissionsHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/LaunchServerStarter.java | 2 - .../launchserver/auth/AuthProviderPair.java | 6 +- .../permissions/ConfigPermissionsHandler.java | 26 ----- .../DefaultPermissionsHandler.java | 21 ---- .../HibernatePermissionsHandler.java | 27 ----- .../JsonFilePermissionsHandler.java | 109 ----------------- .../JsonLongFilePermissionsHandler.java | 110 ------------------ .../auth/permissions/PermissionsHandler.java | 30 ----- .../auth/provider/AcceptAuthProvider.java | 3 +- .../auth/provider/AuthProviderResult.java | 5 +- .../auth/provider/HibernateAuthProvider.java | 2 +- .../auth/provider/MySQLAuthProvider.java | 3 +- .../auth/provider/PostgreSQLAuthProvider.java | 2 +- .../auth/provider/RejectAuthProvider.java | 3 +- .../auth/provider/RequestAuthProvider.java | 3 +- .../command/handler/CommandHandler.java | 2 - .../service/GetPermissionsCommand.java | 30 ----- .../service/GivePermissionsCommand.java | 51 -------- .../config/LaunchServerConfig.java | 35 +----- .../manangers/LaunchServerGsonManager.java | 2 - .../socket/response/auth/AuthResponse.java | 2 +- .../pro/gravit/launcher/LauncherInject.java | 1 + modules | 2 +- 23 files changed, 21 insertions(+), 456 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 202b9787..9dfe712f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.hwid.HWIDHandler; -import pro.gravit.launchserver.auth.permissions.PermissionsHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -211,7 +210,6 @@ public static void registerAll() { AuthProvider.registerProviders(); TextureProvider.registerProviders(); HWIDHandler.registerHandlers(); - PermissionsHandler.registerHandlers(); Component.registerComponents(); ProtectHandler.registerHandlers(); WebSocketService.registerResponses(); 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 908c2f29..f3d136d7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -2,6 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.handler.AuthHandler; +import pro.gravit.launchserver.auth.hwid.HWIDHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -11,20 +12,23 @@ public class AuthProviderPair { public final AuthProvider provider; public final AuthHandler handler; public final TextureProvider textureProvider; + public final HWIDHandler hwid; public final String name; public String displayName; public final boolean isDefault = true; - public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, String name) { + public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid, String name) { this.provider = provider; this.handler = handler; this.textureProvider = textureProvider; + this.hwid = hwid; this.name = name; } public void init(LaunchServer srv) { provider.init(srv); handler.init(srv); + hwid.init(); } public void close() throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java deleted file mode 100644 index c5b1772e..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; - -public class ConfigPermissionsHandler extends PermissionsHandler { - public final boolean isAdmin = false; - public final boolean isServer = false; - - @Override - public ClientPermissions getPermissions(String username) { - ClientPermissions permissions = new ClientPermissions(); - permissions.canServer = isServer; - permissions.canAdmin = isAdmin; - return permissions; - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - //Unsupported - } - - @Override - public void close() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java deleted file mode 100644 index cca7fc72..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; - -public class DefaultPermissionsHandler extends PermissionsHandler { - - @Override - public ClientPermissions getPermissions(String username) { - return ClientPermissions.DEFAULT; - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - //Unsupported - } - - @Override - public void close() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java deleted file mode 100644 index 15702db5..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.dao.User; - -public class HibernatePermissionsHandler extends PermissionsHandler { - - @Override - public ClientPermissions getPermissions(String username) { - User user = srv.config.dao.userDAO.findByUsername(username); - if (user == null) return ClientPermissions.DEFAULT; - return user.getPermissions(); - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - User user = srv.config.dao.userDAO.findByUsername(username); - if (user == null) return; - user.setPermissions(permissions); - srv.config.dao.userDAO.update(user); - } - - @Override - public void close() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java deleted file mode 100644 index 1ca4227e..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ /dev/null @@ -1,109 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import com.google.gson.reflect.TypeToken; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.lang.reflect.Type; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -public class JsonFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { - public final String filename = "permissions.json"; - public static Map map; - - - public void reload() { - map.clear(); - Path path = Paths.get(filename); - Type type = new TypeToken>() { - }.getType(); - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public void close() { - - } - - @Override - public Map getCommands() { - Map commands = new HashMap<>(); - SubCommand reload = new SubCommand() { - @Override - public void invoke(String... args) { - reload(); - } - }; - commands.put("reload", reload); - commands.put("save", new SubCommand() { - @Override - public void invoke(String... args) { - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - } - }); - return commands; - } - - public static class Enity { - public String username; - public ClientPermissions permissions; - } - - @Override - public void init(LaunchServer server) { - super.init(server); - Type type = new TypeToken>() { - }.getType(); - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - map = new HashMap<>(); - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public ClientPermissions getPermissions(String username) { - return map.getOrDefault(username, ClientPermissions.DEFAULT); - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - map.put(username, permissions); - } - - public JsonFilePermissionsHandler() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java deleted file mode 100644 index c908777c..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ /dev/null @@ -1,110 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import com.google.gson.reflect.TypeToken; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.lang.reflect.Type; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -public class JsonLongFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { - public final String filename = "permissions.json"; - public final long defaultPerms = 0L; - public static Map map; - - - public void reload() { - map.clear(); - Path path = Paths.get(filename); - Type type = new TypeToken>() { - }.getType(); - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public void close() { - - } - - @Override - public Map getCommands() { - Map commands = new HashMap<>(); - SubCommand reload = new SubCommand() { - @Override - public void invoke(String... args) { - reload(); - } - }; - commands.put("reload", reload); - commands.put("save", new SubCommand() { - @Override - public void invoke(String... args) { - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - } - }); - return commands; - } - - public static class Enity { - public String username; - public ClientPermissions permissions; - } - - @Override - public void init(LaunchServer server) { - super.init(server); - Type type = new TypeToken>() { - }.getType(); - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - map = new HashMap<>(); - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public ClientPermissions getPermissions(String username) { - return new ClientPermissions(map.getOrDefault(username, defaultPerms)); - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - map.put(username, permissions.toLong()); - } - - public JsonLongFilePermissionsHandler() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java deleted file mode 100644 index 0ab6c4ae..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.ProviderMap; - -public abstract class PermissionsHandler implements AutoCloseable { - public static final ProviderMap providers = new ProviderMap<>("PermissionsHandler"); - protected transient LaunchServer srv; - private static boolean registredHandl = false; - - public static void registerHandlers() { - if (!registredHandl) { - providers.register("json", JsonFilePermissionsHandler.class); - providers.register("json-long", JsonLongFilePermissionsHandler.class); - providers.register("config", ConfigPermissionsHandler.class); - providers.register("default", DefaultPermissionsHandler.class); - providers.register("hibernate", HibernatePermissionsHandler.class); - registredHandl = true; - } - } - - public void init(LaunchServer server) { - this.srv = server; - } - - public abstract ClientPermissions getPermissions(String username); - - public abstract void setPermissions(String username, ClientPermissions permissions); -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java index 6a820208..d5d9c7e2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java @@ -1,5 +1,6 @@ package pro.gravit.launchserver.auth.provider; +import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.utils.helper.SecurityHelper; @@ -7,7 +8,7 @@ public final class AcceptAuthProvider extends AuthProvider { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); // Same as login + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), ClientPermissions.DEFAULT); // Same as login } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java index 291835a1..630ddb1e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.auth.provider; import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; public class AuthProviderResult { @@ -9,10 +8,10 @@ public class AuthProviderResult { public final String accessToken; public final ClientPermissions permissions; - public AuthProviderResult(String username, String accessToken, LaunchServer server) { + public AuthProviderResult(String username, String accessToken) { this.username = username; this.accessToken = accessToken; - permissions = server.config.permissionsHandler.getPermissions(username); + permissions = ClientPermissions.DEFAULT; } public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index 4f9e19f2..8ce22cef 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -26,7 +26,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p if (user == null) throw new AuthException("Username incorrect"); else throw new AuthException("Username or password incorrect"); } - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), user.getPermissions()); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java index a5979f28..aae966bf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -20,7 +20,6 @@ public final class MySQLAuthProvider extends AuthProvider { private String query; private String message; private String[] queryParams; - private boolean usePermission; @Override public void init(LaunchServer srv) { @@ -42,7 +41,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p // Execute SQL query s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : srv.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message); + return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), new ClientPermissions(set.getLong(2))) : authError(message); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java index 09390a3f..f85ea7ea 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java @@ -33,7 +33,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p // Execute SQL query s.setQueryTimeout(PostgreSQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : srv.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message); + return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), new ClientPermissions(set.getLong(2))) : authError(message); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java index 75882753..aaf60d3b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -1,5 +1,6 @@ package pro.gravit.launchserver.auth.provider; +import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.Reconfigurable; import pro.gravit.launchserver.auth.AuthException; @@ -28,7 +29,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p if (whitelist != null) { for (String username : whitelist) { if (login.equals(username)) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), ClientPermissions.DEFAULT); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java index 09ce4cbf..e0f489bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -19,7 +19,6 @@ public final class RequestAuthProvider extends AuthProvider { private String url; private transient Pattern pattern; private String response; - private boolean usePermission; @Override public void init(LaunchServer srv) { @@ -37,7 +36,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p // Match username Matcher matcher = pattern.matcher(currentResponse); return matcher.matches() && matcher.groupCount() >= 1 ? - new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(Long.parseLong(matcher.group("permission"))) : srv.config.permissionsHandler.getPermissions(login)) : + new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), new ClientPermissions(Long.parseLong(matcher.group("permission")))) : authError(currentResponse); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index ab917f10..8a6c032e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -86,8 +86,6 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand service.registerCommand("multi", new MultiCommand(server)); service.registerCommand("notify", new NotifyCommand(server)); service.registerCommand("component", new ComponentCommand(server)); - service.registerCommand("givePermission", new GivePermissionsCommand(server)); - service.registerCommand("getPermissions", new GetPermissionsCommand(server)); service.registerCommand("clients", new ClientsCommand(server)); service.registerCommand("signJar", new SignJarCommand(server)); service.registerCommand("signDir", new SignDirCommand(server)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java deleted file mode 100644 index 05302816..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package pro.gravit.launchserver.command.service; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class GetPermissionsCommand extends Command { - public GetPermissionsCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return "[username]"; - } - - @Override - public String getUsageDescription() { - return "print username permissions"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - String username = args[0]; - ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); - LogHelper.info("Permissions %s: %s (long: %d)", username, permissions.toString(), permissions.toLong()); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java deleted file mode 100644 index 6539617d..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launchserver.command.service; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class GivePermissionsCommand extends Command { - public GivePermissionsCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return "[username] [permission] [true/false]"; - } - - @Override - public String getUsageDescription() { - return "give permissions"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 3); - String username = args[0]; - ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); - String permission = args[1]; - boolean isEnabled = Boolean.parseBoolean(args[2]); - switch (permission) { - case "admin": { - permissions.canAdmin = isEnabled; - break; - } - case "server": { - permissions.canServer = isEnabled; - break; - } - case "bot": { - permissions.canBot = isEnabled; - break; - } - default: { - LogHelper.error("Unknown permission: %s", permission); - return; - } - } - LogHelper.info("Write new permissions for %s", username); - server.config.permissionsHandler.setPermissions(username, permissions); - } -} 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 a8d77215..cc43b9e7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -8,10 +8,6 @@ import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.handler.MemoryAuthHandler; import pro.gravit.launchserver.auth.hwid.AcceptHWIDHandler; -import pro.gravit.launchserver.auth.hwid.HWIDHandler; -import pro.gravit.launchserver.auth.permissions.DefaultPermissionsHandler; -import pro.gravit.launchserver.auth.permissions.JsonFilePermissionsHandler; -import pro.gravit.launchserver.auth.permissions.PermissionsHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.protect.StdProtectHandler; import pro.gravit.launchserver.auth.provider.RejectAuthProvider; @@ -66,8 +62,6 @@ public AuthProviderPair getAuthProviderPair(String name) { public ProtectHandler protectHandler; - public PermissionsHandler permissionsHandler; - public AuthProviderPair getAuthProviderPair() { if (authDefault != null) return authDefault; for (AuthProviderPair pair : auth) { @@ -79,8 +73,6 @@ public AuthProviderPair getAuthProviderPair() { throw new IllegalStateException("Default AuthProviderPair not found"); } - public HWIDHandler hwidHandler; - public Map components; public ExeConf launch4j; @@ -123,9 +115,6 @@ public void verify() { if (!isOneDefault) { throw new IllegalStateException("No auth pairs declared by default."); } - if (permissionsHandler == null) { - throw new NullPointerException("PermissionsHandler must not be null"); - } if (env == null) { throw new NullPointerException("Env must not be null"); } @@ -139,8 +128,6 @@ public void init(LaunchServer.ReloadType type) { for (AuthProviderPair provider : auth) { provider.init(server); } - permissionsHandler.init(server); - hwidHandler.init(); if (dao != null) dao.init(server); if (protectHandler != null) { @@ -149,13 +136,12 @@ public void init(LaunchServer.ReloadType type) { if (components != null) { components.forEach((k, v) -> server.registerObject("component.".concat(k), v)); } - server.registerObject("permissionsHandler", permissionsHandler); - server.registerObject("hwidHandler", hwidHandler); if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { for (AuthProviderPair pair : auth) { 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); + server.registerObject("auth.".concat(pair.name).concat(".hwid"), pair.hwid); } } @@ -165,13 +151,12 @@ public void init(LaunchServer.ReloadType type) { public void close(LaunchServer.ReloadType type) { try { - server.unregisterObject("permissionsHandler", permissionsHandler); - server.unregisterObject("hwidHandler", hwidHandler); if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { for (AuthProviderPair pair : auth) { 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); + server.unregisterObject("auth.".concat(pair.name).concat(".hwid"), pair.hwid); } } if (type.equals(LaunchServer.ReloadType.FULL)) { @@ -194,16 +179,6 @@ public void close(LaunchServer.ReloadType type) { } catch (IOException e) { LogHelper.error(e); } - try { - hwidHandler.close(); - } catch (Exception e) { - LogHelper.error(e); - } - try { - permissionsHandler.close(); - } catch (Exception e) { - LogHelper.error(e); - } } public static class ExeConf { @@ -305,17 +280,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.hwidHandler = new AcceptHWIDHandler(); newConfig.auth = new AuthProviderPair[]{new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") - , "std")}; + , new AcceptHWIDHandler(), "std")}; newConfig.auth[0].displayName = "Default"; newConfig.protectHandler = new StdProtectHandler(); if (env.equals(LaunchServer.LaunchServerEnv.TEST)) - newConfig.permissionsHandler = new DefaultPermissionsHandler(); - else - newConfig.permissionsHandler = new JsonFilePermissionsHandler(); newConfig.binaryName = "Launcher"; newConfig.whitelistRejectString = "Вас нет в белом списке"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index bf39128f..13693bfe 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -10,7 +10,6 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.hwid.HWIDHandler; -import pro.gravit.launchserver.auth.permissions.PermissionsHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -34,7 +33,6 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(AuthProvider.class, new UniversalJsonAdapter<>(AuthProvider.providers)); builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers)); builder.registerTypeAdapter(AuthHandler.class, new UniversalJsonAdapter<>(AuthHandler.providers)); - builder.registerTypeAdapter(PermissionsHandler.class, new UniversalJsonAdapter<>(PermissionsHandler.providers)); builder.registerTypeAdapter(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers)); builder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); builder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index f50fc1fc..31832e91 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -97,7 +97,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti // throw new AuthException("You profile not found"); //} if (authType == ConnectTypes.CLIENT) - server.config.hwidHandler.check(hwid, aresult.username); + pair.hwid.check(hwid, aresult.username); server.authHookManager.postHook.hook(context, clientData); clientData.isAuth = true; clientData.permissions = aresult.permissions; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java index b11647c1..cee89fe0 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java @@ -10,4 +10,5 @@ @Target(FIELD) public @interface LauncherInject { public String value(); // target of inject + } diff --git a/modules b/modules index 5f6dc831..e84f2b9f 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 5f6dc8312dcb91b92ee96040830a914d6038773d +Subproject commit e84f2b9f96aab1036cf38c466d2ef3c797a2acfe