mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE][FIX] Исправлена сериализация ClientPermissions и добавлен HibernatePermissionsHandler
This commit is contained in:
parent
1f10bab874
commit
57da09dee9
9 changed files with 58 additions and 20 deletions
|
@ -241,7 +241,7 @@ public void init() {
|
|||
for (AuthProviderPair provider : auth) {
|
||||
provider.init(server);
|
||||
}
|
||||
permissionsHandler.init();
|
||||
permissionsHandler.init(server);
|
||||
hwidHandler.init();
|
||||
if (protectHandler != null) {
|
||||
protectHandler.checkLaunchServerLicense();
|
||||
|
@ -590,7 +590,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
for (AuthProviderPair provider : config.auth) {
|
||||
provider.init(this);
|
||||
}
|
||||
config.permissionsHandler.init();
|
||||
config.permissionsHandler.init(this);
|
||||
config.hwidHandler.init();
|
||||
if (config.protectHandler != null) {
|
||||
config.protectHandler.checkLaunchServerLicense();
|
||||
|
|
|
@ -6,11 +6,6 @@ public class ConfigPermissionsHandler extends PermissionsHandler {
|
|||
public boolean isAdmin = false;
|
||||
public boolean isServer = false;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
ClientPermissions permissions = new ClientPermissions();
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
import pro.gravit.launcher.ClientPermissions;
|
||||
|
||||
public class DefaultPermissionsHandler extends PermissionsHandler {
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
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.userService.findUserByUsername(username);
|
||||
if(user == null) return ClientPermissions.DEFAULT;
|
||||
return user.getPermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermissions(String username, ClientPermissions permissions) {
|
||||
User user = srv.userService.findUserByUsername(username);
|
||||
if(user == null) return;
|
||||
user.setPermissions(permissions);
|
||||
srv.userService.updateUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
import pro.gravit.launcher.ClientPermissions;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.Reloadable;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -45,7 +46,8 @@ public static class Enity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
public void init(LaunchServer server) {
|
||||
super.init(server);
|
||||
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||
}.getType();
|
||||
Path path = Paths.get(filename);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
import pro.gravit.launcher.ClientPermissions;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.Reloadable;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -46,7 +47,8 @@ public static class Enity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
public void init(LaunchServer server) {
|
||||
super.init(server);
|
||||
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||
}.getType();
|
||||
Path path = Paths.get(filename);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
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 ProviderMap<PermissionsHandler> providers = new ProviderMap<>("PermissionsHandler");
|
||||
protected transient LaunchServer srv;
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
public static void registerHandlers() {
|
||||
|
@ -13,11 +15,15 @@ public static void registerHandlers() {
|
|||
providers.register("json-long", JsonLongFilePermissionsHandler.class);
|
||||
providers.register("config", ConfigPermissionsHandler.class);
|
||||
providers.register("default", DefaultPermissionsHandler.class);
|
||||
providers.register("hibernate", HibernatePermissionsHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
public void init(LaunchServer server)
|
||||
{
|
||||
this.srv = server;
|
||||
}
|
||||
|
||||
public abstract ClientPermissions getPermissions(String username);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import pro.gravit.launcher.ClientPermissions;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
|
@ -31,6 +32,7 @@ public class User {
|
|||
private String accessToken;
|
||||
public String serverID;
|
||||
private String password_salt;
|
||||
public long permissions;
|
||||
public void setPassword(String password)
|
||||
{
|
||||
password_salt = SecurityHelper.randomStringAESKey();
|
||||
|
@ -57,6 +59,14 @@ public boolean verifyPassword(String password)
|
|||
LogHelper.info(Arrays.toString(this.password));
|
||||
return Arrays.equals(enpassword, this.password);
|
||||
}
|
||||
public ClientPermissions getPermissions()
|
||||
{
|
||||
return new ClientPermissions(permissions);
|
||||
}
|
||||
public void setPermissions(ClientPermissions permissions)
|
||||
{
|
||||
this.permissions = permissions.toLong();
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
|
|
|
@ -48,12 +48,12 @@ public ClientPermissions(long data) {
|
|||
@LauncherAPI
|
||||
public long toLong() {
|
||||
long result = 0;
|
||||
result |= canAdmin ? 0 : 1;
|
||||
result |= canServer ? 0 : (1 << 1);
|
||||
result |= canUSR1 ? 0 : (1 << 2);
|
||||
result |= canUSR2 ? 0 : (1 << 3);
|
||||
result |= canUSR3 ? 0 : (1 << 4);
|
||||
result |= canBot ? 0 : (1 << 5);
|
||||
result |= !canAdmin ? 0 : 1;
|
||||
result |= !canServer ? 0 : (1 << 1);
|
||||
result |= !canUSR1 ? 0 : (1 << 2);
|
||||
result |= !canUSR2 ? 0 : (1 << 3);
|
||||
result |= !canUSR3 ? 0 : (1 << 4);
|
||||
result |= !canBot ? 0 : (1 << 5);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue