mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Add permissions support to PostgreSQL
This commit adds permissions support to PostgreSQL auth method.
This commit is contained in:
parent
a5b4282037
commit
d11c9e92a5
1 changed files with 27 additions and 1 deletions
|
@ -35,16 +35,22 @@ public class PostgresSQLCoreProvider extends AuthCoreProvider {
|
||||||
public String serverIDColumn;
|
public String serverIDColumn;
|
||||||
public String table;
|
public String table;
|
||||||
|
|
||||||
|
public String permissionsTable;
|
||||||
|
public String permissionsPermissionColumn;
|
||||||
|
public String permissionsUUIDColumn;
|
||||||
|
|
||||||
public PasswordVerifier passwordVerifier;
|
public PasswordVerifier passwordVerifier;
|
||||||
public String customQueryByUUIDSQL;
|
public String customQueryByUUIDSQL;
|
||||||
public String customQueryByUsernameSQL;
|
public String customQueryByUsernameSQL;
|
||||||
public String customQueryByLoginSQL;
|
public String customQueryByLoginSQL;
|
||||||
|
public String customQueryPermissionsByUUIDSQL;
|
||||||
public String customUpdateAuthSQL;
|
public String customUpdateAuthSQL;
|
||||||
public String customUpdateServerIdSQL;
|
public String customUpdateServerIdSQL;
|
||||||
// Prepared SQL queries
|
// Prepared SQL queries
|
||||||
private transient String queryByUUIDSQL;
|
private transient String queryByUUIDSQL;
|
||||||
private transient String queryByUsernameSQL;
|
private transient String queryByUsernameSQL;
|
||||||
private transient String queryByLoginSQL;
|
private transient String queryByLoginSQL;
|
||||||
|
private transient String queryPermissionsByUUIDSQL;
|
||||||
private transient String updateAuthSQL;
|
private transient String updateAuthSQL;
|
||||||
private transient String updateServerIDSQL;
|
private transient String updateServerIDSQL;
|
||||||
|
|
||||||
|
@ -160,6 +166,9 @@ public void init(LaunchServer server) {
|
||||||
userInfoCols, table, usernameColumn);
|
userInfoCols, table, usernameColumn);
|
||||||
queryByLoginSQL = customQueryByLoginSQL != null ? customQueryByLoginSQL : queryByUsernameSQL;
|
queryByLoginSQL = customQueryByLoginSQL != null ? customQueryByLoginSQL : queryByUsernameSQL;
|
||||||
|
|
||||||
|
queryPermissionsByUUIDSQL = customQueryPermissionsByUUIDSQL != null ? customQueryPermissionsByUUIDSQL : String.format("SELECT (%s) FROM %s WHERE %s=?",
|
||||||
|
permissionsPermissionColumn, permissionsTable, permissionsUUIDColumn);
|
||||||
|
|
||||||
updateAuthSQL = customUpdateAuthSQL != null ? customUpdateAuthSQL : String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=?",
|
updateAuthSQL = customUpdateAuthSQL != null ? customUpdateAuthSQL : String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=?",
|
||||||
table, accessTokenColumn, serverIDColumn, uuidColumn);
|
table, accessTokenColumn, serverIDColumn, uuidColumn);
|
||||||
updateServerIDSQL = customUpdateServerIdSQL != null ? customUpdateServerIdSQL : String.format("UPDATE %s SET %s=? WHERE %s=?",
|
updateServerIDSQL = customUpdateServerIdSQL != null ? customUpdateServerIdSQL : String.format("UPDATE %s SET %s=? WHERE %s=?",
|
||||||
|
@ -202,7 +211,24 @@ public void close() throws IOException {
|
||||||
|
|
||||||
private PostgresSQLUser constructUser(ResultSet set) throws SQLException {
|
private PostgresSQLUser constructUser(ResultSet set) throws SQLException {
|
||||||
return set.next() ? new PostgresSQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn),
|
return set.next() ? new PostgresSQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn),
|
||||||
set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), new ClientPermissions()) : null;
|
set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn))) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClientPermissions requestPermissions (String uuid) throws SQLException
|
||||||
|
{
|
||||||
|
try (Connection c = postgresSQLHolder.getConnection()) {
|
||||||
|
PreparedStatement s = c.prepareStatement(queryPermissionsByUUIDSQL);
|
||||||
|
s.setString(1, uuid);
|
||||||
|
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||||
|
ResultSet set = s.executeQuery();
|
||||||
|
ClientPermissions perms = new ClientPermissions();
|
||||||
|
while (set.next()) {
|
||||||
|
perms.addPerm(set.getString(permissionsPermissionColumn));
|
||||||
|
}
|
||||||
|
return perms;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new SQLException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private User query(String sql, String value) throws IOException {
|
private User query(String sql, String value) throws IOException {
|
||||||
|
|
Loading…
Reference in a new issue