mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +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;
|
package ru.gravit.launchserver.auth.permissions;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
|
||||||
public class ConfigPermissionsHandler extends PermissionsHandler {
|
public class ConfigPermissionsHandler extends PermissionsHandler {
|
||||||
public boolean isAdmin = false;
|
public boolean isAdmin = false;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package ru.gravit.launchserver.auth.permissions;
|
package ru.gravit.launchserver.auth.permissions;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
|
||||||
public class DefaultPermissionsHandler extends PermissionsHandler {
|
public class DefaultPermissionsHandler extends PermissionsHandler {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launchserver.Reloadable;
|
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.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
public abstract class PermissionsHandler {
|
public abstract class PermissionsHandler {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
|
||||||
|
|
||||||
public class AuthProviderResult {
|
public class AuthProviderResult {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
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.HTTPRequest;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
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.launchserver.auth.MySQLSourceConfig;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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.CommonHelper;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
|
@ -140,5 +140,6 @@ public void reply() throws Exception {
|
||||||
// Write profile and UUID
|
// Write profile and UUID
|
||||||
ProfileByUUIDResponse.getProfile(server, uuid, result.username, client).write(output);
|
ProfileByUUIDResponse.getProfile(server, uuid, result.username, client).write(output);
|
||||||
output.writeASCII(result.accessToken, -SecurityHelper.TOKEN_STRING_LENGTH);
|
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);
|
debug("ServerAuth: '%s' -> '%s', '%s'", login, result.username, result.accessToken);
|
||||||
clientData.isAuth = true;
|
clientData.isAuth = true;
|
||||||
writeNoError(output);
|
writeNoError(output);
|
||||||
|
clientData.permissions.write(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package ru.gravit.launchserver.socket;
|
package ru.gravit.launchserver.socket;
|
||||||
|
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launchserver.auth.ClientPermissions;
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
public long session;
|
public long session;
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package ru.gravit.launcher.request.auth;
|
package ru.gravit.launcher.request.auth;
|
||||||
|
|
||||||
import ru.gravit.launcher.HWID;
|
import ru.gravit.launcher.*;
|
||||||
import ru.gravit.launcher.Launcher;
|
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
import ru.gravit.launcher.request.RequestType;
|
import ru.gravit.launcher.request.RequestType;
|
||||||
|
@ -22,10 +19,13 @@ public static final class Result {
|
||||||
public final PlayerProfile pp;
|
public final PlayerProfile pp;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public final String accessToken;
|
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.pp = pp;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException {
|
||||||
readError(input);
|
readError(input);
|
||||||
PlayerProfile pp = new PlayerProfile(input);
|
PlayerProfile pp = new PlayerProfile(input);
|
||||||
String accessToken = input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH);
|
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;
|
package ru.gravit.launcher.request.auth;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class AuthServerRequest extends Request<Boolean> {
|
public final class AuthServerRequest extends Request<ClientPermissions> {
|
||||||
public static final class Result {
|
public static final class Result {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public final PlayerProfile pp;
|
public final PlayerProfile pp;
|
||||||
|
@ -75,7 +76,7 @@ public Integer getType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(login, SerializeLimits.MAX_LOGIN);
|
||||||
output.writeString(title, SerializeLimits.MAX_CLIENT);
|
output.writeString(title, SerializeLimits.MAX_CLIENT);
|
||||||
output.writeInt(auth_id);
|
output.writeInt(auth_id);
|
||||||
|
@ -84,6 +85,6 @@ protected Boolean requestDo(HInput input, HOutput output) throws IOException {
|
||||||
|
|
||||||
// Read UUID and access token
|
// Read UUID and access token
|
||||||
readError(input);
|
readError(input);
|
||||||
return true;
|
return new ClientPermissions(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
|
@ -29,6 +30,7 @@ public class ServerWrapper {
|
||||||
public static Config config;
|
public static Config config;
|
||||||
public static PublicURLClassLoader ucp;
|
public static PublicURLClassLoader ucp;
|
||||||
public static ClassLoader loader;
|
public static ClassLoader loader;
|
||||||
|
public static ClientPermissions permissions;
|
||||||
private static Gson gson;
|
private static Gson gson;
|
||||||
private static GsonBuilder gsonBuiler;
|
private static GsonBuilder gsonBuiler;
|
||||||
|
|
||||||
|
@ -39,8 +41,7 @@ public class ServerWrapper {
|
||||||
public static boolean auth(ServerWrapper wrapper) {
|
public static boolean auth(ServerWrapper wrapper) {
|
||||||
try {
|
try {
|
||||||
LauncherConfig cfg = Launcher.getConfig();
|
LauncherConfig cfg = Launcher.getConfig();
|
||||||
Boolean auth = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), 0, config.title).request();
|
ServerWrapper.permissions = 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
|
|
||||||
ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
|
ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
|
||||||
for (ClientProfile p : result.profiles) {
|
for (ClientProfile p : result.profiles) {
|
||||||
LogHelper.debug("Get profile: %s", p.getTitle());
|
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 class ClientPermissions {
|
||||||
public static final ClientPermissions DEFAULT = new ClientPermissions();
|
public static final ClientPermissions DEFAULT = new ClientPermissions();
|
||||||
|
@LauncherAPI
|
||||||
public boolean canAdmin;
|
public boolean canAdmin;
|
||||||
|
@LauncherAPI
|
||||||
public boolean canServer;
|
public boolean canServer;
|
||||||
|
public ClientPermissions(HInput input) throws IOException {
|
||||||
|
canAdmin = input.readBoolean();
|
||||||
|
canServer = input.readBoolean();
|
||||||
|
}
|
||||||
public ClientPermissions() {
|
public ClientPermissions() {
|
||||||
canAdmin = false;
|
canAdmin = false;
|
||||||
canServer = false;
|
canServer = false;
|
||||||
|
@ -21,4 +31,8 @@ public static ClientPermissions getSuperuserAccount() {
|
||||||
perm.canAdmin = true;
|
perm.canAdmin = true;
|
||||||
return perm;
|
return perm;
|
||||||
}
|
}
|
||||||
|
public void write(HOutput output) throws IOException {
|
||||||
|
output.writeBoolean(canAdmin);
|
||||||
|
output.writeBoolean(canServer);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue