mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Удаление permissionsHandler
This commit is contained in:
parent
93436de104
commit
f81cdf6440
23 changed files with 21 additions and 456 deletions
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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<String, ClientPermissions> map;
|
||||
|
||||
|
||||
public void reload() {
|
||||
map.clear();
|
||||
Path path = Paths.get(filename);
|
||||
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||
}.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<String, Command> getCommands() {
|
||||
Map<String, Command> 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<Map<String, ClientPermissions>>() {
|
||||
}.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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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<String, Long> map;
|
||||
|
||||
|
||||
public void reload() {
|
||||
map.clear();
|
||||
Path path = Paths.get(filename);
|
||||
Type type = new TypeToken<Map<String, Long>>() {
|
||||
}.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<String, Command> getCommands() {
|
||||
Map<String, Command> 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<Map<String, ClientPermissions>>() {
|
||||
}.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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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<PermissionsHandler> 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);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<String, Component> 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 = "Вас нет в белом списке";
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -10,4 +10,5 @@
|
|||
@Target(FIELD)
|
||||
public @interface LauncherInject {
|
||||
public String value(); // target of inject
|
||||
|
||||
}
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit 5f6dc8312dcb91b92ee96040830a914d6038773d
|
||||
Subproject commit e84f2b9f96aab1036cf38c466d2ef3c797a2acfe
|
Loading…
Reference in a new issue