mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-21 23:04:45 +03:00
[FEATURE][EXPERIMENTAL] Flags in AuthProvider
This commit is contained in:
parent
0692fe367f
commit
56e1920a8d
7 changed files with 28 additions and 8 deletions
|
@ -21,6 +21,7 @@ public static class authResult {
|
|||
String username;
|
||||
String error;
|
||||
long permissions;
|
||||
long flags;
|
||||
}
|
||||
|
||||
public static class authRequest {
|
||||
|
@ -54,7 +55,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p
|
|||
|
||||
authResult result = gson.fromJson(content, authResult.class);
|
||||
if (result.username != null)
|
||||
return new AuthProviderResult(result.username, SecurityHelper.randomStringToken(), new ClientPermissions(result.permissions));
|
||||
return new AuthProviderResult(result.username, SecurityHelper.randomStringToken(), new ClientPermissions(result.permissions, result.flags));
|
||||
else if (result.error != null)
|
||||
return authError(result.error);
|
||||
else
|
||||
|
|
|
@ -20,6 +20,7 @@ public final class MySQLAuthProvider extends AuthProvider {
|
|||
private String query;
|
||||
private String message;
|
||||
private String[] queryParams;
|
||||
private boolean flagsEnabled;
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer srv) {
|
||||
|
@ -41,7 +42,8 @@ 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(), new ClientPermissions(set.getLong(2))) : authError(message);
|
||||
return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), new ClientPermissions(
|
||||
set.getLong(2), flagsEnabled ? set.getLong(3) : 0)) : authError(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public final class PostgreSQLAuthProvider extends AuthProvider {
|
|||
private String query;
|
||||
private String message;
|
||||
private String[] queryParams;
|
||||
private boolean flagsEnabled;
|
||||
|
||||
@Override
|
||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException {
|
||||
|
@ -32,7 +33,8 @@ 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(), new ClientPermissions(set.getLong(2))) : authError(message);
|
||||
return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), new ClientPermissions(
|
||||
set.getLong(2), flagsEnabled ? set.getLong(3) : 0)) : authError(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public RejectAuthProvider(String message) {
|
|||
}
|
||||
|
||||
private String message;
|
||||
private ArrayList<String> whitelist;
|
||||
private ArrayList<String> whitelist = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws AuthException {
|
||||
|
@ -46,11 +46,20 @@ public Map<String, Command> getCommands() {
|
|||
Map<String, Command> commands = new HashMap<>();
|
||||
commands.put("message", new SubCommand() {
|
||||
@Override
|
||||
public void invoke(String... args) {
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
message = args[0];
|
||||
LogHelper.info("New reject message: %s", message);
|
||||
}
|
||||
});
|
||||
commands.put("whirelist.add", new SubCommand() {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
whitelist.add(args[0]);
|
||||
LogHelper.info("%s added to whitelist", args[0]);
|
||||
}
|
||||
});
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public final class RequestAuthProvider extends AuthProvider {
|
|||
private String url;
|
||||
private transient Pattern pattern;
|
||||
private String response;
|
||||
private boolean flagsEnabled;
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer srv) {
|
||||
|
@ -36,7 +37,8 @@ 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(), new ClientPermissions(Long.parseLong(matcher.group("permission")))) :
|
||||
new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), new ClientPermissions(
|
||||
Long.parseLong(matcher.group("permissions")), flagsEnabled ? Long.parseLong(matcher.group("flags")) : 0)) :
|
||||
authError(currentResponse);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ public class UserHibernateImpl implements User {
|
|||
public String serverID;
|
||||
private String password_salt;
|
||||
public long permissions;
|
||||
public long flags;
|
||||
|
||||
public void setPassword(String password) {
|
||||
password_salt = SecurityHelper.randomStringAESKey();
|
||||
|
@ -55,11 +56,12 @@ public boolean verifyPassword(String password) {
|
|||
}
|
||||
|
||||
public ClientPermissions getPermissions() {
|
||||
return new ClientPermissions(permissions);
|
||||
return new ClientPermissions(permissions, flags);
|
||||
}
|
||||
|
||||
public void setPermissions(ClientPermissions permissions) {
|
||||
this.permissions = permissions.toLong();
|
||||
this.permissions = permissions.permissions;
|
||||
this.flags = permissions.flags;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
|
|
|
@ -90,6 +90,7 @@ public void invoke(String... args) throws Exception {
|
|||
long perm = Long.parseLong(args[1]);
|
||||
boolean value = Boolean.parseBoolean(args[2]);
|
||||
permissions.setPermission(perm, value);
|
||||
user.setPermissions(permissions);
|
||||
userDAO.update(user);
|
||||
}
|
||||
});
|
||||
|
@ -106,6 +107,7 @@ public void invoke(String... args) throws Exception {
|
|||
long perm = Long.parseLong(args[1]);
|
||||
boolean value = Boolean.parseBoolean(args[2]);
|
||||
permissions.setFlag(perm, value);
|
||||
user.setPermissions(permissions);
|
||||
userDAO.update(user);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue