mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Configurable query MySQL AuthCoreProvider
This commit is contained in:
parent
c1f1dae7f2
commit
7133727edd
2 changed files with 29 additions and 12 deletions
|
@ -56,9 +56,16 @@ public class MySQLCoreProvider extends AuthCoreProvider implements AuthSupportHa
|
||||||
// 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 updateAuthSQL;
|
private transient String updateAuthSQL;
|
||||||
private transient String updateServerIDSQL;
|
private transient String updateServerIDSQL;
|
||||||
|
|
||||||
|
public String defaultQueryByUUIDSQL;
|
||||||
|
public String defaultQueryByUsernameSQL;
|
||||||
|
public String defaultQueryByLoginSQL;
|
||||||
|
public String defaultUpdateAuthSQL;
|
||||||
|
public String defaultUpdateServerIdSQL;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getUserByUsername(String username) {
|
public User getUserByUsername(String username) {
|
||||||
try {
|
try {
|
||||||
|
@ -79,6 +86,16 @@ public User getUserByUUID(UUID uuid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User getUserByLogin(String login) {
|
||||||
|
try {
|
||||||
|
return query(queryByLoginSQL, login);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("SQL error", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
||||||
return null;
|
return null;
|
||||||
|
@ -125,23 +142,24 @@ public void init(LaunchServer server) {
|
||||||
if (table == null) logger.error("table cannot be null");
|
if (table == null) logger.error("table cannot be null");
|
||||||
// Prepare SQL queries
|
// Prepare SQL queries
|
||||||
String userInfoCols = String.format("%s, %s, %s, %s, %s, %s", uuidColumn, usernameColumn, accessTokenColumn, serverIDColumn, passwordColumn, hardwareIdColumn);
|
String userInfoCols = String.format("%s, %s, %s, %s, %s, %s", uuidColumn, usernameColumn, accessTokenColumn, serverIDColumn, passwordColumn, hardwareIdColumn);
|
||||||
queryByUUIDSQL = String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1", userInfoCols,
|
queryByUUIDSQL = defaultQueryByUUIDSQL != null ? defaultQueryByUUIDSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1", userInfoCols,
|
||||||
table, uuidColumn);
|
table, uuidColumn);
|
||||||
queryByUsernameSQL = String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1",
|
queryByUsernameSQL = defaultQueryByUsernameSQL != null ? defaultQueryByUsernameSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1",
|
||||||
userInfoCols, table, usernameColumn);
|
userInfoCols, table, usernameColumn);
|
||||||
|
queryByLoginSQL = defaultQueryByLoginSQL != null ? defaultQueryByLoginSQL : queryByUsernameSQL;
|
||||||
|
|
||||||
updateAuthSQL = String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=? LIMIT 1",
|
updateAuthSQL = defaultUpdateAuthSQL != null ? defaultUpdateAuthSQL : String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=? LIMIT 1",
|
||||||
table, accessTokenColumn, serverIDColumn, uuidColumn);
|
table, accessTokenColumn, serverIDColumn, uuidColumn);
|
||||||
updateServerIDSQL = String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
|
updateServerIDSQL = defaultUpdateServerIdSQL != null ? defaultUpdateServerIdSQL : String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
|
||||||
table, serverIDColumn, uuidColumn);
|
table, serverIDColumn, uuidColumn);
|
||||||
String hardwareInfoCols = "id, hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, graphicCard, banned";
|
String hardwareInfoCols = "id, hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, graphicCard, banned";
|
||||||
sqlFindHardwareByPublicKey = String.format("SELECT %s FROM %s WHERE `publicKey` = ?", hardwareInfoCols, tableHWID);
|
if(sqlFindHardwareByPublicKey == null) sqlFindHardwareByPublicKey = String.format("SELECT %s FROM %s WHERE `publicKey` = ?", hardwareInfoCols, tableHWID);
|
||||||
sqlFindHardwareById = String.format("SELECT %s FROM %s WHERE `id` = ?", hardwareInfoCols, tableHWID);
|
if(sqlFindHardwareById == null) sqlFindHardwareById = String.format("SELECT %s FROM %s WHERE `id` = ?", hardwareInfoCols, tableHWID);
|
||||||
sqlUsersByHwidId = String.format("SELECT %s FROM %s WHERE `%s` = ?", userInfoCols, table, hardwareIdColumn);
|
if(sqlUsersByHwidId == null) sqlUsersByHwidId = String.format("SELECT %s FROM %s WHERE `%s` = ?", userInfoCols, table, hardwareIdColumn);
|
||||||
sqlFindHardwareByData = String.format("SELECT %s FROM %s", hardwareInfoCols, tableHWID);
|
if(sqlFindHardwareByData == null) sqlFindHardwareByData = String.format("SELECT %s FROM %s", hardwareInfoCols, tableHWID);
|
||||||
sqlCreateHardware = String.format("INSERT INTO `%s` (`publickey`, `hwDiskId`, `baseboardSerialNumber`, `displayId`, `bitness`, `totalMemory`, `logicalProcessors`, `physicalProcessors`, `processorMaxFreq`, `battery`, `graphicCard`, `banned`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '0')", tableHWID);
|
if(sqlCreateHardware == null) sqlCreateHardware = String.format("INSERT INTO `%s` (`publickey`, `hwDiskId`, `baseboardSerialNumber`, `displayId`, `bitness`, `totalMemory`, `logicalProcessors`, `physicalProcessors`, `processorMaxFreq`, `battery`, `graphicCard`, `banned`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '0')", tableHWID);
|
||||||
sqlCreateHWIDLog = String.format("INSERT INTO %s (`hwidId`, `newPublicKey`) VALUES (?, ?)", tableHWIDLog);
|
if(sqlCreateHWIDLog == null) sqlCreateHWIDLog = String.format("INSERT INTO %s (`hwidId`, `newPublicKey`) VALUES (?, ?)", tableHWIDLog);
|
||||||
sqlUpdateHardwarePublicKey = String.format("UPDATE %s SET `publicKey` = ? WHERE `id` = ?", tableHWID);
|
if(sqlUpdateHardwarePublicKey == null) sqlUpdateHardwarePublicKey = String.format("UPDATE %s SET `publicKey` = ? WHERE `id` = ?", tableHWID);
|
||||||
sqlUpdateHardwareBanned = String.format("UPDATE %s SET `banned` = ? WHERE `id` = ?", tableHWID);
|
sqlUpdateHardwareBanned = String.format("UPDATE %s SET `banned` = ? WHERE `id` = ?", tableHWID);
|
||||||
sqlUpdateUsers = String.format("UPDATE %s SET `%s` = ? WHERE `%s` = ?", table, hardwareIdColumn, uuidColumn);
|
sqlUpdateUsers = String.format("UPDATE %s SET `%s` = ? WHERE `%s` = ?", table, hardwareIdColumn, uuidColumn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ public class DoubleDigestPasswordVerifier extends PasswordVerifier {
|
||||||
private byte[] digest(String text) throws NoSuchAlgorithmException {
|
private byte[] digest(String text) throws NoSuchAlgorithmException {
|
||||||
MessageDigest digest = MessageDigest.getInstance(algo);
|
MessageDigest digest = MessageDigest.getInstance(algo);
|
||||||
byte[] firstDigest = digest.digest(text.getBytes(StandardCharsets.UTF_8));
|
byte[] firstDigest = digest.digest(text.getBytes(StandardCharsets.UTF_8));
|
||||||
LogHelper.info("HEX %s", SecurityHelper.toHex(firstDigest));
|
|
||||||
return toHexMode ? digest.digest(SecurityHelper.toHex(firstDigest).getBytes(StandardCharsets.UTF_8)) : digest.digest(firstDigest);
|
return toHexMode ? digest.digest(SecurityHelper.toHex(firstDigest).getBytes(StandardCharsets.UTF_8)) : digest.digest(firstDigest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue