#472 Store recovery codes in memory instead of in data source
This commit is contained in:
@@ -8,9 +8,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.EmailRecoveryData;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
@@ -236,23 +234,6 @@ public class CacheDataSource implements DataSource {
|
||||
return source.getAllAuths();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecoveryCode(String name, String code, long expiration) {
|
||||
source.setRecoveryCode(name, code, expiration);
|
||||
cachedAuths.refresh(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailRecoveryData getEmailRecoveryData(String name) {
|
||||
return source.getEmailRecoveryData(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecoveryCode(String name) {
|
||||
source.removeRecoveryCode(name);
|
||||
cachedAuths.refresh(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getLoggedPlayers() {
|
||||
return new ArrayList<>(PlayerCache.getInstance().getCache().values());
|
||||
|
||||
@@ -22,8 +22,6 @@ public final class Columns {
|
||||
public final String EMAIL;
|
||||
public final String ID;
|
||||
public final String IS_LOGGED;
|
||||
public final String RECOVERY_CODE;
|
||||
public final String RECOVERY_EXPIRATION;
|
||||
|
||||
public Columns(Settings settings) {
|
||||
NAME = settings.getProperty(DatabaseSettings.MYSQL_COL_NAME);
|
||||
@@ -40,8 +38,6 @@ public final class Columns {
|
||||
EMAIL = settings.getProperty(DatabaseSettings.MYSQL_COL_EMAIL);
|
||||
ID = settings.getProperty(DatabaseSettings.MYSQL_COL_ID);
|
||||
IS_LOGGED = settings.getProperty(DatabaseSettings.MYSQL_COL_ISLOGGED);
|
||||
RECOVERY_CODE = settings.getProperty(DatabaseSettings.MYSQL_COL_RECOVERY_CODE);
|
||||
RECOVERY_EXPIRATION = settings.getProperty(DatabaseSettings.MYSQL_COL_RECOVERY_EXPIRATION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.cache.auth.EmailRecoveryData;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
@@ -195,30 +194,6 @@ public interface DataSource extends Reloadable {
|
||||
*/
|
||||
List<PlayerAuth> getAllAuths();
|
||||
|
||||
/**
|
||||
* Set the password recovery code for a user.
|
||||
*
|
||||
* @param name The name of the user
|
||||
* @param code The recovery code
|
||||
* @param expiration Recovery code expiration (milliseconds timestamp)
|
||||
*/
|
||||
void setRecoveryCode(String name, String code, long expiration);
|
||||
|
||||
/**
|
||||
* Get the information necessary for performing a password recovery by email.
|
||||
*
|
||||
* @param name The name of the user
|
||||
* @return The data of the player, or null if player doesn't exist
|
||||
*/
|
||||
EmailRecoveryData getEmailRecoveryData(String name);
|
||||
|
||||
/**
|
||||
* Remove the recovery code of a given user.
|
||||
*
|
||||
* @param name The name of the user
|
||||
*/
|
||||
void removeRecoveryCode(String name);
|
||||
|
||||
/**
|
||||
* Reload the data source.
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.EmailRecoveryData;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
@@ -469,21 +468,6 @@ public class FlatFile implements DataSource {
|
||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecoveryCode(String name, String code, long expiration) {
|
||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailRecoveryData getEmailRecoveryData(String name) {
|
||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecoveryCode(String name) {
|
||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||
}
|
||||
|
||||
private static PlayerAuth buildAuthFromArray(String[] args) {
|
||||
// Format allows 2, 3, 4, 7, 8, 9 fields. Anything else is unknown
|
||||
if (args.length >= 2 && args.length <= 9 && args.length != 5 && args.length != 6) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.EmailRecoveryData;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
@@ -209,14 +208,6 @@ public class MySQL implements DataSource {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0' AFTER " + col.EMAIL);
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.RECOVERY_CODE)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.RECOVERY_CODE + " VARCHAR(20);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.RECOVERY_EXPIRATION)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.RECOVERY_EXPIRATION + " BIGINT;");
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("MySQL setup finished");
|
||||
}
|
||||
@@ -865,55 +856,6 @@ public class MySQL implements DataSource {
|
||||
return auths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecoveryCode(String name, String code, long expiration) {
|
||||
String sql = "UPDATE " + tableName
|
||||
+ " SET " + col.RECOVERY_CODE + " = ?, "
|
||||
+ col.RECOVERY_EXPIRATION + " = ?"
|
||||
+ " WHERE " + col.NAME + " = ?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, code);
|
||||
pst.setLong(2, expiration);
|
||||
pst.setString(3, name.toLowerCase());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailRecoveryData getEmailRecoveryData(String name) {
|
||||
String sql = "SELECT " + col.EMAIL + ", " + col.RECOVERY_CODE + ", " + col.RECOVERY_EXPIRATION
|
||||
+ " FROM " + tableName
|
||||
+ " WHERE " + col.NAME + " = ?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, name.toLowerCase());
|
||||
try (ResultSet rs = pst.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
return new EmailRecoveryData(
|
||||
rs.getString(col.EMAIL), rs.getString(col.RECOVERY_CODE), rs.getLong(col.RECOVERY_EXPIRATION));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecoveryCode(String name) {
|
||||
String sql = "UPDATE " + tableName
|
||||
+ " SET " + col.RECOVERY_CODE + " = NULL, "
|
||||
+ col.RECOVERY_EXPIRATION + " = NULL"
|
||||
+ " WHERE " + col.NAME + " = ?;";
|
||||
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, name.toLowerCase());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
|
||||
String salt = col.SALT.isEmpty() ? null : row.getString(col.SALT);
|
||||
int group = col.GROUP.isEmpty() ? -1 : row.getInt(col.GROUP);
|
||||
|
||||
@@ -2,7 +2,6 @@ package fr.xephi.authme.datasource;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.EmailRecoveryData;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@@ -128,14 +127,6 @@ public class SQLite implements DataSource {
|
||||
if (isColumnMissing(md, col.IS_LOGGED)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.IS_LOGGED + " INT DEFAULT '0';");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.RECOVERY_CODE)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.RECOVERY_CODE + " VARCHAR(20);");
|
||||
}
|
||||
|
||||
if (isColumnMissing(md, col.RECOVERY_EXPIRATION)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.RECOVERY_EXPIRATION + " BIGINT;");
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("SQLite Setup finished");
|
||||
}
|
||||
@@ -595,55 +586,6 @@ public class SQLite implements DataSource {
|
||||
return auths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecoveryCode(String name, String code, long expiration) {
|
||||
String sql = "UPDATE " + tableName
|
||||
+ " SET " + col.RECOVERY_CODE + " = ?, "
|
||||
+ col.RECOVERY_EXPIRATION + " = ?"
|
||||
+ " WHERE " + col.NAME + " = ?;";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, code);
|
||||
pst.setLong(2, expiration);
|
||||
pst.setString(3, name.toLowerCase());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailRecoveryData getEmailRecoveryData(String name) {
|
||||
String sql = "SELECT " + col.EMAIL + ", " + col.RECOVERY_CODE + ", " + col.RECOVERY_EXPIRATION
|
||||
+ " FROM " + tableName
|
||||
+ " WHERE " + col.NAME + " = ?;";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, name.toLowerCase());
|
||||
try (ResultSet rs = pst.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
return new EmailRecoveryData(
|
||||
rs.getString(col.EMAIL), rs.getString(col.RECOVERY_CODE), rs.getLong(col.RECOVERY_EXPIRATION));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecoveryCode(String name) {
|
||||
String sql = "UPDATE " + tableName
|
||||
+ " SET " + col.RECOVERY_CODE + " = NULL, "
|
||||
+ col.RECOVERY_EXPIRATION + " = NULL"
|
||||
+ " WHERE " + col.NAME + " = ?;";
|
||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||
pst.setString(1, name.toLowerCase());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
logSqlException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {
|
||||
String salt = !col.SALT.isEmpty() ? row.getString(col.SALT) : null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user