diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 767a3fc5..aea7aa86 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -51,8 +51,6 @@ public abstract class AbstractSQLCoreProvider extends AuthCoreProvider { public String customQueryByUsernameSQL; public String customQueryByLoginSQL; public String customQueryPermissionsByUUIDSQL; - //public String customQueryRoleByUUIDSQL; - //public String customQueryRoleByNameSQL; public String customQueryRolesByUserUUID; public String customUpdateAuthSQL; public String customUpdateServerIdSQL; @@ -61,8 +59,6 @@ public abstract class AbstractSQLCoreProvider extends AuthCoreProvider { public transient String queryByUsernameSQL; public transient String queryByLoginSQL; public transient String queryPermissionsByUUIDSQL; - //public transient String queryRoleByUUIDSQL; - //public transient String queryRoleByNameSQL; public transient String queryRolesByUserUUID; public transient String updateAuthSQL; @@ -179,10 +175,6 @@ public void init(LaunchServer server) { queryByUsernameSQL = customQueryByUsernameSQL != null ? customQueryByUsernameSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1", userInfoCols, table, usernameColumn); queryByLoginSQL = customQueryByLoginSQL != null ? customQueryByLoginSQL : queryByUsernameSQL; -/* - queryPermissionsByUUIDSQL = customQueryPermissionsByUUIDSQL != null ? customQueryPermissionsByUUIDSQL : String.format("SELECT (%s) FROM %s WHERE %s=?", - permissionsPermissionColumn, permissionsTable, permissionsUUIDColumn); -*/ queryPermissionsByUUIDSQL = customQueryPermissionsByUUIDSQL != null ? customQueryPermissionsByUUIDSQL : "WITH RECURSIVE req AS (\n" + @@ -196,13 +188,7 @@ public void init(LaunchServer server) { queryRolesByUserUUID = customQueryRolesByUserUUID != null ? customQueryRolesByUserUUID : String.format("SELECT r.%s FROM %s r\n" + "INNER JOIN %s pr ON r.%s=substring(pr.%s from 6) or r.%s=substring(pr.%s from 6)\n" + "WHERE pr.%s = ?",rolesNameColumn,rolesTable,permissionsTable,rolesUUIDColumn,permissionsPermissionColumn,rolesNameColumn,permissionsPermissionColumn,permissionsUUIDColumn); -/* - queryRoleByUUIDSQL = customQueryRoleByUUIDSQL != null ? customQueryRoleByUUIDSQL : String.format("SELECT %s, %s FROM %s WHERE %s=? LIMIT 1", - rolesUUIDColumn, rolesNameColumn,rolesTable,rolesUUIDColumn); - queryRoleByNameSQL = customQueryRoleByNameSQL != null ? customQueryRoleByNameSQL : String.format("SELECT %s, %s FROM %s WHERE %s=? LIMIT 1", - rolesUUIDColumn, rolesNameColumn,rolesTable,rolesNameColumn); -*/ updateAuthSQL = customUpdateAuthSQL != null ? customUpdateAuthSQL : String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=?", table, accessTokenColumn, serverIDColumn, uuidColumn); updateServerIDSQL = customUpdateServerIdSQL != null ? customUpdateServerIdSQL : String.format("UPDATE %s SET %s=? WHERE %s=?", @@ -245,7 +231,6 @@ public void close() throws IOException { private SQLUser constructUser(ResultSet set) throws SQLException { return set.next() ? new SQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn), - //set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn))) : null; set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn))) : null; } @@ -253,40 +238,7 @@ public ClientPermissions requestPermissions (String uuid) throws SQLException { return new ClientPermissions(queryRolesNames(queryRolesByUserUUID,uuid),queryPermissions(queryPermissionsByUUIDSQL,uuid)); } - /* - public ClientPermissions requestPermissions (String uuid) throws SQLException - { - try{ - ClientPermissions perms = new ClientPermissions(); - for(String perm : queryPermissions(queryPermissionsByUUIDSQL,uuid)) - perms.addPerm(perm); - - List groupPerms = new ArrayList<>(perms.getPerms()); - groupPerms.removeIf(s->!s.startsWith("role.")); - - for(String groupPerm : groupPerms) - { - String role = groupPerm.substring(5); - if(processRole(queryRole(queryRoleByUUIDSQL,role),perms)) continue; - if(processRole(queryRole(queryRoleByNameSQL,role),perms)) continue; - logger.warn(String.format( "Role not found: %s",role)); - } - - return perms; - } catch (SQLException e) { - throw new SQLException(e); - } - } - - private boolean processRole(SQLRole role, ClientPermissions perms) throws SQLException { - if(role == null) return false; - perms.addRole(role.name); - for(String perm : queryPermissions(queryPermissionsByUUIDSQL,role.uuid)) - perms.addPerm(perm); - return true; - } -*/ private SQLUser queryUser(String sql, String value) throws SQLException { try (Connection c = getSQLConfig().getConnection()) { PreparedStatement s = c.prepareStatement(sql); @@ -330,33 +282,6 @@ private List queryRolesNames(String sql, String value) throws SQLExcepti } } - -/* - private SQLRole queryRole(String sql, String value) throws SQLException { - try (Connection c = getSQLConfig().getConnection()) { - PreparedStatement s = c.prepareStatement(sql); - s.setString(1, value); - s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - ResultSet set = s.executeQuery(); - if(!set.next()) return null; - return new SQLRole(set.getString(rolesNameColumn), set.getString(rolesUUIDColumn)); - } catch (SQLException e) { - throw new SQLException(e); - } - } - - private class SQLRole - { - public String name; - public String uuid; - - SQLRole(String name, String uuid) - { - this.name = name; - this.uuid = uuid; - } - }*/ - public static class SQLUser implements User { protected UUID uuid; protected String username;