mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
ServerWrapper и лаунчер знает ClientPermissions
This commit is contained in:
parent
ece52dd025
commit
02c82745d0
15 changed files with 41 additions and 22 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Boolean> {
|
||||
public final class AuthServerRequest extends Request<ClientPermissions> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue