diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 1a460e15..6d9eaf82 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -13,6 +13,7 @@ import ru.gravit.launchserver.auth.handler.MemoryAuthHandler; import ru.gravit.launchserver.auth.hwid.AcceptHWIDHandler; import ru.gravit.launchserver.auth.hwid.HWIDHandler; +import ru.gravit.launchserver.auth.permissions.JsonFilePermissionsHandler; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.RejectAuthProvider; import ru.gravit.launchserver.binary.EXEL4JLauncherBinary; @@ -26,10 +27,7 @@ import ru.gravit.launchserver.config.AuthProviderAdapter; import ru.gravit.launchserver.config.HWIDHandlerAdapter; import ru.gravit.launchserver.config.TextureProviderAdapter; -import ru.gravit.launchserver.manangers.BuildHookManager; -import ru.gravit.launchserver.manangers.MirrorManager; -import ru.gravit.launchserver.manangers.ModulesManager; -import ru.gravit.launchserver.manangers.SessionManager; +import ru.gravit.launchserver.manangers.*; import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.texture.RequestTextureProvider; @@ -349,6 +347,8 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { e.printStackTrace(); } }); + JsonFilePermissionsHandler.init(); + PermissionsManager.registerPermissionsFunction(JsonFilePermissionsHandler::getPermissions); // init modules modulesManager.initModules(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java new file mode 100644 index 00000000..ff149487 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -0,0 +1,45 @@ +package ru.gravit.launchserver.auth.permissions; + +import com.google.gson.reflect.TypeToken; +import ru.gravit.launcher.Launcher; +import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.utils.helper.IOHelper; + +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 { + public static String FILE_NAME = "permissions.json"; + public static Map map; + public static class Enity + { + public String username; + public ClientPermissions permissions; + } + public static ClientPermissions getPermissions(String username) + { + return map.getOrDefault(username,ClientPermissions.DEFAULT); + } + public static void init() throws IOException { + Type type = new TypeToken>(){}.getType(); + Path path = Paths.get(FILE_NAME); + if(!IOHelper.exists(path)) + { + map = new HashMap<>(); + try(Writer writer = IOHelper.newWriter(path)) + { + Launcher.gson.toJson(map,writer); + } + } + try(Reader reader = IOHelper.newReader(path)) + { + map = Launcher.gson.fromJson(reader,type); + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java index 53e6d66e..5d7fa638 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java @@ -4,11 +4,10 @@ import ru.gravit.utils.helper.SecurityHelper; public final class AcceptAuthProvider extends AuthProvider { - private boolean isAdminAccess; @Override public AuthProviderResult auth(String login, String password, String ip) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), isAdminAccess ? ClientPermissions.getSuperuserAccount() : ClientPermissions.DEFAULT); // Same as login + return new AuthProviderResult(login, SecurityHelper.randomStringToken()); // Same as login } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java index b80245c2..d34f90c1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProviderResult.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.provider; import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launchserver.manangers.PermissionsManager; public class AuthProviderResult { @@ -11,7 +12,7 @@ public class AuthProviderResult { public AuthProviderResult(String username, String accessToken) { this.username = username; this.accessToken = accessToken; - permissions = ClientPermissions.DEFAULT; + permissions = PermissionsManager.getPermissions(username); } public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java new file mode 100644 index 00000000..ea5c75b7 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/PermissionsManager.java @@ -0,0 +1,24 @@ +package ru.gravit.launchserver.manangers; + +import ru.gravit.launchserver.auth.ClientPermissions; + +public class PermissionsManager { + private static PermissionsFunction function = PermissionsManager::returnDefault; + public static void registerPermissionsFunction(PermissionsFunction function) + { + PermissionsManager.function = function; + } + public static ClientPermissions getPermissions(String username) + { + return function.getPermission(username); + } + @FunctionalInterface + public interface PermissionsFunction + { + ClientPermissions getPermission(String username); + } + public static ClientPermissions returnDefault(String username) + { + return ClientPermissions.DEFAULT; + } +} 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 9987d5a2..c97838af 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 @@ -87,7 +87,7 @@ public void reply() throws Exception { } } if (clientData.profile == null) { - throw new AuthException("You profile not found"); + throw new AuthException("Your profile is not found"); } } server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java index 1d2c8cb4..9fba3686 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java @@ -67,14 +67,15 @@ public void reply() throws Exception { Collection profiles = server.getProfiles(); for (ClientProfile p : profiles) { if (p.getTitle().equals(client)) { - if (!p.isWhitelistContains(login)) { - throw new AuthException(server.config.whitelistRejectString); - } clientData.profile = p; } } if (clientData.profile == null) { - throw new AuthException("You profile not found"); + throw new AuthException("Your profile is not found"); + } + if(!clientData.permissions.canServer) + { + throw new AuthException("Your account cannot be a server"); } clientData.type = Client.Type.SERVER; clientData.username = result.username;