From 02c82745d01f6bcce8f248d500077bc070ce8238 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 4 Jan 2019 22:45:11 +0700 Subject: [PATCH] =?UTF-8?q?ServerWrapper=20=D0=B8=20=D0=BB=D0=B0=D1=83?= =?UTF-8?q?=D0=BD=D1=87=D0=B5=D1=80=20=D0=B7=D0=BD=D0=B0=D0=B5=D1=82=20Cli?= =?UTF-8?q?entPermissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permissions/ConfigPermissionsHandler.java | 2 +- .../permissions/DefaultPermissionsHandler.java | 2 +- .../JsonFilePermissionsHandler.java | 2 +- .../auth/permissions/PermissionsHandler.java | 2 +- .../auth/provider/AuthProviderResult.java | 2 +- .../auth/provider/JsonAuthProvider.java | 2 +- .../auth/provider/MySQLAuthProvider.java | 2 +- .../auth/provider/RequestAuthProvider.java | 2 +- .../response/auth/AuthResponse.java | 1 + .../response/auth/AuthServerResponse.java | 1 + .../ru/gravit/launchserver/socket/Client.java | 2 +- .../launcher/request/auth/AuthRequest.java | 13 +++++++------ .../request/auth/AuthServerRequest.java | 7 ++++--- .../gravit/launcher/server/ServerWrapper.java | 5 +++-- .../ru/gravit/launcher}/ClientPermissions.java | 18 ++++++++++++++++-- 15 files changed, 41 insertions(+), 22 deletions(-) rename {LaunchServer/src/main/java/ru/gravit/launchserver/auth => libLauncher/src/main/java/ru/gravit/launcher}/ClientPermissions.java (55%) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java index 6cf5a1de..f7ff9ba4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java @@ -1,6 +1,6 @@ package ru.gravit.launchserver.auth.permissions; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; public class ConfigPermissionsHandler extends PermissionsHandler { public boolean isAdmin = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java index 39c32310..7b81d70d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java @@ -1,6 +1,6 @@ package ru.gravit.launchserver.auth.permissions; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; public class DefaultPermissionsHandler extends PermissionsHandler { @Override 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 index bfad14ee..b779b882 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -13,7 +13,7 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launchserver.Reloadable; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java index c4333414..92d7a883 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -4,7 +4,7 @@ import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.utils.helper.VerifyHelper; public abstract class PermissionsHandler { 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 4432bb8d..f89f3c33 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,7 +1,7 @@ package ru.gravit.launchserver.auth.provider; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; public class AuthProviderResult { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java index bca1e034..26bd7a24 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -6,7 +6,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.utils.HTTPRequest; import ru.gravit.utils.helper.SecurityHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java index 465c09cb..48be4086 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -6,7 +6,7 @@ import java.sql.SQLException; import ru.gravit.launchserver.auth.AuthException; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.launchserver.auth.MySQLSourceConfig; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.SecurityHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java index a0e5fb78..0d5a10c2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -5,7 +5,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; 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 756751ce..5a0dfa35 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 @@ -140,5 +140,6 @@ public void reply() throws Exception { // Write profile and UUID ProfileByUUIDResponse.getProfile(server, uuid, result.username, client).write(output); output.writeASCII(result.accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); + clientData.permissions.write(output); } } 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 43f344a3..1423faba 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 @@ -91,5 +91,6 @@ public void reply() throws Exception { debug("ServerAuth: '%s' -> '%s', '%s'", login, result.username, result.accessToken); clientData.isAuth = true; writeNoError(output); + clientData.permissions.write(output); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java index 38bb27f5..8799e3e9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java @@ -1,7 +1,7 @@ package ru.gravit.launchserver.socket; import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launchserver.auth.ClientPermissions; +import ru.gravit.launcher.ClientPermissions; public class Client { public long session; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index 761ac1c9..578bd659 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -1,9 +1,6 @@ package ru.gravit.launcher.request.auth; -import ru.gravit.launcher.HWID; -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.*; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestType; @@ -22,10 +19,13 @@ public static final class Result { public final PlayerProfile pp; @LauncherAPI public final String accessToken; + @LauncherAPI + public final ClientPermissions permissions; - private Result(PlayerProfile pp, String accessToken) { + private Result(PlayerProfile pp, String accessToken, ClientPermissions permissions) { this.pp = pp; this.accessToken = accessToken; + this.permissions = permissions; } } @@ -86,6 +86,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException { readError(input); PlayerProfile pp = new PlayerProfile(input); String accessToken = input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH); - return new Result(pp, accessToken); + ClientPermissions permissions = new ClientPermissions(input); + return new Result(pp, accessToken,permissions); } } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java index 7a83ab9a..49113e5a 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java @@ -1,5 +1,6 @@ package ru.gravit.launcher.request.auth; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.profiles.PlayerProfile; @@ -13,7 +14,7 @@ import java.io.IOException; -public final class AuthServerRequest extends Request { +public final class AuthServerRequest extends Request { public static final class Result { @LauncherAPI public final PlayerProfile pp; @@ -75,7 +76,7 @@ public Integer getType() { } @Override - protected Boolean requestDo(HInput input, HOutput output) throws IOException { + protected ClientPermissions requestDo(HInput input, HOutput output) throws IOException { output.writeString(login, SerializeLimits.MAX_LOGIN); output.writeString(title, SerializeLimits.MAX_CLIENT); output.writeInt(auth_id); @@ -84,6 +85,6 @@ protected Boolean requestDo(HInput input, HOutput output) throws IOException { // Read UUID and access token readError(input); - return true; + return new ClientPermissions(input); } } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 206757cd..9e8e84a8 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.profiles.ClientProfile; @@ -29,6 +30,7 @@ public class ServerWrapper { public static Config config; public static PublicURLClassLoader ucp; public static ClassLoader loader; + public static ClientPermissions permissions; private static Gson gson; private static GsonBuilder gsonBuiler; @@ -39,8 +41,7 @@ public class ServerWrapper { public static boolean auth(ServerWrapper wrapper) { try { LauncherConfig cfg = Launcher.getConfig(); - Boolean auth = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request(); - if (auth == null) throw new Exception("Non auth!"); // security check + ServerWrapper.permissions = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request(); ProfilesRequest.Result result = new ProfilesRequest(cfg).request(); for (ClientProfile p : result.profiles) { LogHelper.debug("Get profile: %s", p.getTitle()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java similarity index 55% rename from LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java rename to libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java index 2b3921b7..36118532 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java @@ -1,10 +1,20 @@ -package ru.gravit.launchserver.auth; +package ru.gravit.launcher; + +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; + +import java.io.IOException; public class ClientPermissions { public static final ClientPermissions DEFAULT = new ClientPermissions(); + @LauncherAPI public boolean canAdmin; + @LauncherAPI public boolean canServer; - + public ClientPermissions(HInput input) throws IOException { + canAdmin = input.readBoolean(); + canServer = input.readBoolean(); + } public ClientPermissions() { canAdmin = false; canServer = false; @@ -21,4 +31,8 @@ public static ClientPermissions getSuperuserAccount() { perm.canAdmin = true; return perm; } + public void write(HOutput output) throws IOException { + output.writeBoolean(canAdmin); + output.writeBoolean(canServer); + } }