mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-06 20:28:06 +02:00
Merge branch 'master' into reload-supp
This commit is contained in:
commit
b66c4983ec
@ -17,7 +17,6 @@ import fr.xephi.authme.command.CommandInitializer;
|
||||
import fr.xephi.authme.command.CommandMapper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.converter.ForceFlatToSqlite;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
@ -43,9 +42,8 @@ import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.security.crypts.SHA256;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.OtherAccounts;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@ -58,9 +56,9 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.MigrationService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -77,6 +75,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
@ -105,7 +104,6 @@ public class AuthMe extends JavaPlugin {
|
||||
// Private Instances
|
||||
private static AuthMe plugin;
|
||||
private static Server server;
|
||||
private static Wrapper wrapper = Wrapper.getInstance();
|
||||
private Management management;
|
||||
private CommandHandler commandHandler = null;
|
||||
private PermissionsManager permsMan = null;
|
||||
@ -117,9 +115,8 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
/*
|
||||
* Public Instances
|
||||
* TODO: Encapsulation
|
||||
* TODO #432: Encapsulation
|
||||
*/
|
||||
|
||||
public NewAPI api;
|
||||
public SendMailSSL mail;
|
||||
public DataManager dataManager;
|
||||
@ -246,7 +243,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Connect to the database and setup tables
|
||||
try {
|
||||
setupDatabase();
|
||||
setupDatabase(newSettings);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Fatal error occurred during database connection! "
|
||||
+ "Authme initialization aborted!", e);
|
||||
@ -254,6 +251,7 @@ public class AuthMe extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
MigrationService.changePlainTextToSha256(newSettings, database, new SHA256());
|
||||
passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH),
|
||||
Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH));
|
||||
|
||||
@ -516,25 +514,42 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void setupDatabase() throws Exception {
|
||||
if (database != null)
|
||||
database.close();
|
||||
// Backend MYSQL - FILE - SQLITE - SQLITEHIKARI
|
||||
boolean isSQLite = false;
|
||||
switch (newSettings.getProperty(DatabaseSettings.BACKEND)) {
|
||||
case FILE:
|
||||
database = new FlatFile();
|
||||
break;
|
||||
case MYSQL:
|
||||
database = new MySQL(newSettings);
|
||||
break;
|
||||
case SQLITE:
|
||||
database = new SQLite(newSettings);
|
||||
isSQLite = true;
|
||||
break;
|
||||
/**
|
||||
* Sets up the data source.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
* @see AuthMe#database
|
||||
*/
|
||||
public void setupDatabase(NewSetting settings) throws ClassNotFoundException, SQLException {
|
||||
if (this.database != null) {
|
||||
this.database.close();
|
||||
}
|
||||
|
||||
if (isSQLite) {
|
||||
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
||||
DataSource dataSource;
|
||||
switch (dataSourceType) {
|
||||
case FILE:
|
||||
dataSource = new FlatFile();
|
||||
break;
|
||||
case MYSQL:
|
||||
dataSource = new MySQL(settings);
|
||||
break;
|
||||
case SQLITE:
|
||||
dataSource = new SQLite(settings);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");
|
||||
}
|
||||
|
||||
DataSource convertedSource = MigrationService.convertFlatfileToSqlite(newSettings, dataSource);
|
||||
dataSource = convertedSource == null ? dataSource : convertedSource;
|
||||
|
||||
if (newSettings.getProperty(DatabaseSettings.USE_CACHING)) {
|
||||
dataSource = new CacheDataSource(dataSource);
|
||||
}
|
||||
|
||||
database = dataSource;
|
||||
if (DataSourceType.SQLITE == dataSourceType) {
|
||||
server.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -546,34 +561,6 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Settings.getDataSource == DataSourceType.FILE) {
|
||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, it will be changed " +
|
||||
"to SQLite... Connection will be impossible until conversion is done!");
|
||||
ForceFlatToSqlite converter = new ForceFlatToSqlite(database, newSettings);
|
||||
DataSource source = converter.run();
|
||||
if (source != null) {
|
||||
database = source;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Move this to another place maybe ?
|
||||
if (HashAlgorithm.PLAINTEXT == newSettings.getProperty(SecuritySettings.PASSWORD_HASH)) {
|
||||
ConsoleLogger.showError("Your HashAlgorithm has been detected as plaintext and is now deprecated; " +
|
||||
"it will be changed and hashed now to the AuthMe default hashing method");
|
||||
for (PlayerAuth auth : database.getAllAuths()) {
|
||||
HashedPassword hashedPassword = passwordSecurity.computeHash(
|
||||
HashAlgorithm.SHA256, auth.getPassword().getHash(), auth.getNickname());
|
||||
auth.setPassword(hashedPassword);
|
||||
database.updatePassword(auth);
|
||||
}
|
||||
newSettings.setProperty(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
|
||||
newSettings.save();
|
||||
}
|
||||
|
||||
if (newSettings.getProperty(DatabaseSettings.USE_CACHING)) {
|
||||
database = new CacheDataSource(database);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -916,7 +903,7 @@ public class AuthMe extends JavaPlugin {
|
||||
String commandLabel, String[] args) {
|
||||
// Make sure the command handler has been initialized
|
||||
if (commandHandler == null) {
|
||||
wrapper.getLogger().severe("AuthMe command handler is not available");
|
||||
getLogger().severe("AuthMe command handler is not available");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,10 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
try {
|
||||
commandService.getSettings().reload();
|
||||
commandService.reloadMessages(commandService.getSettings().getMessagesFile());
|
||||
plugin.setupDatabase();
|
||||
// TODO #432: We should not reload only certain plugin entities but actually reinitialize all elements,
|
||||
// i.e. here in the future we might not have setupDatabase() but Authme.onEnable(), maybe after
|
||||
// a call to some destructor method
|
||||
plugin.setupDatabase(commandService.getSettings());
|
||||
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("Error occurred during reload of AuthMe: aborting");
|
||||
|
@ -14,7 +14,6 @@ public interface DataSource {
|
||||
* Return whether there is a record for the given username.
|
||||
*
|
||||
* @param user The username to look up
|
||||
*
|
||||
* @return True if there is a record, false otherwise
|
||||
*/
|
||||
boolean isAuthAvailable(String user);
|
||||
@ -23,7 +22,6 @@ public interface DataSource {
|
||||
* Return the hashed password of the player.
|
||||
*
|
||||
* @param user The user whose password should be retrieve
|
||||
*
|
||||
* @return The password hash of the player
|
||||
*/
|
||||
HashedPassword getPassword(String user);
|
||||
@ -32,7 +30,6 @@ public interface DataSource {
|
||||
* Retrieve the entire PlayerAuth object associated with the username.
|
||||
*
|
||||
* @param user The user to retrieve
|
||||
*
|
||||
* @return The PlayerAuth object for the given username
|
||||
*/
|
||||
PlayerAuth getAuth(String user);
|
||||
@ -41,7 +38,6 @@ public interface DataSource {
|
||||
* Save a new PlayerAuth object.
|
||||
*
|
||||
* @param auth The new PlayerAuth to persist
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean saveAuth(PlayerAuth auth);
|
||||
@ -50,7 +46,6 @@ public interface DataSource {
|
||||
* Update the session of a record (IP, last login, real name).
|
||||
*
|
||||
* @param auth The PlayerAuth object to update in the database
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean updateSession(PlayerAuth auth);
|
||||
@ -59,7 +54,6 @@ public interface DataSource {
|
||||
* Update the password of the given PlayerAuth object.
|
||||
*
|
||||
* @param auth The PlayerAuth whose password should be updated
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean updatePassword(PlayerAuth auth);
|
||||
@ -67,9 +61,8 @@ public interface DataSource {
|
||||
/**
|
||||
* Update the password of the given player.
|
||||
*
|
||||
* @param user The user whose password should be updated
|
||||
* @param user The user whose password should be updated
|
||||
* @param password The new password
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean updatePassword(String user, HashedPassword password);
|
||||
@ -79,7 +72,6 @@ public interface DataSource {
|
||||
* the given time.
|
||||
*
|
||||
* @param until The minimum last login
|
||||
*
|
||||
* @return The account names that have been removed
|
||||
*/
|
||||
List<String> autoPurgeDatabase(long until);
|
||||
@ -88,7 +80,6 @@ public interface DataSource {
|
||||
* Remove a user record from the database.
|
||||
*
|
||||
* @param user The user to remove
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean removeAuth(String user);
|
||||
@ -97,7 +88,6 @@ public interface DataSource {
|
||||
* Update the quit location of a PlayerAuth.
|
||||
*
|
||||
* @param auth The entry whose quit location should be updated
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean updateQuitLoc(PlayerAuth auth);
|
||||
@ -106,7 +96,6 @@ public interface DataSource {
|
||||
* Return all usernames associated with the given IP address.
|
||||
*
|
||||
* @param ip The IP address to look up
|
||||
*
|
||||
* @return Usernames associated with the given IP address
|
||||
*/
|
||||
List<String> getAllAuthsByIp(String ip);
|
||||
@ -115,7 +104,6 @@ public interface DataSource {
|
||||
* Return all usernames associated with the given email address.
|
||||
*
|
||||
* @param email The email address to look up
|
||||
*
|
||||
* @return Users using the given email address
|
||||
*/
|
||||
List<String> getAllAuthsByEmail(String email);
|
||||
@ -124,7 +112,6 @@ public interface DataSource {
|
||||
* Update the email of the PlayerAuth in the data source.
|
||||
*
|
||||
* @param auth The PlayerAuth whose email should be updated
|
||||
*
|
||||
* @return True upon success, false upon failure
|
||||
*/
|
||||
boolean updateEmail(PlayerAuth auth);
|
||||
|
@ -7,6 +7,7 @@ public enum DataSourceType {
|
||||
|
||||
MYSQL,
|
||||
|
||||
@Deprecated
|
||||
FILE,
|
||||
|
||||
SQLITE
|
||||
|
@ -64,15 +64,16 @@ public class AsynchronousJoin {
|
||||
final String ip = plugin.getIP(player);
|
||||
|
||||
|
||||
if (Settings.isAllowRestrictedIp && !isNameRestricted(name, ip, player.getAddress().getHostName())) {
|
||||
if (Settings.isAllowRestrictedIp && isNameRestricted(name, ip, player.getAddress().getHostName())) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
||||
player.kickPlayer(m.retrieveSingle(MessageKey.NOT_OWNER_ERROR));
|
||||
if (Settings.banUnsafeIp)
|
||||
if (Settings.banUnsafeIp) {
|
||||
plugin.getServer().banIP(ip);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
@ -220,7 +220,7 @@ public class AsynchronousLogin {
|
||||
}
|
||||
}
|
||||
|
||||
public void displayOtherAccounts(PlayerAuth auth) {
|
||||
private void displayOtherAccounts(PlayerAuth auth) {
|
||||
if (!Settings.displayOtherAccounts || auth == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package fr.xephi.authme.process.login;
|
||||
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -92,7 +94,7 @@ public class ProcessSyncPlayerLogin implements Runnable {
|
||||
}
|
||||
|
||||
private void restoreSpeedEffects() {
|
||||
if (Settings.isRemoveSpeedEnabled) {
|
||||
if (settings.getProperty(RestrictionSettings.REMOVE_SPEED)) {
|
||||
player.setWalkSpeed(0.2F);
|
||||
player.setFlySpeed(0.1F);
|
||||
}
|
||||
@ -173,19 +175,19 @@ public class ProcessSyncPlayerLogin implements Runnable {
|
||||
}
|
||||
|
||||
restoreSpeedEffects();
|
||||
if (Settings.applyBlindEffect) {
|
||||
if (settings.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.removePotionEffect(PotionEffectType.BLINDNESS);
|
||||
}
|
||||
|
||||
// The Login event now fires (as intended) after everything is processed
|
||||
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player));
|
||||
player.saveData();
|
||||
if (Settings.bungee) {
|
||||
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
|
||||
sendBungeeMessage();
|
||||
}
|
||||
// Login is finish, display welcome message if we use email registration
|
||||
if (Settings.useWelcomeMessage && Settings.emailRegistration) {
|
||||
if (Settings.broadcastWelcomeMessage) {
|
||||
// Login is done, display welcome message
|
||||
if (settings.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
|
||||
if (settings.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
|
||||
for (String s : settings.getWelcomeMessage()) {
|
||||
Bukkit.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public class PasswordSecurity {
|
||||
*/
|
||||
private static EncryptionMethod initializeEncryptionMethodWithoutEvent(HashAlgorithm algorithm) {
|
||||
try {
|
||||
return HashAlgorithm.CUSTOM.equals(algorithm)
|
||||
return HashAlgorithm.CUSTOM.equals(algorithm) || HashAlgorithm.PLAINTEXT.equals(algorithm)
|
||||
? null
|
||||
: algorithm.getClazz().newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
|
@ -11,7 +11,7 @@ import fr.xephi.authme.security.crypts.description.Usage;
|
||||
* and store the salt with the hash itself.
|
||||
*/
|
||||
@Recommendation(Usage.ACCEPTABLE)
|
||||
@HasSalt(SaltType.TEXT) // See saltLength() for length
|
||||
@HasSalt(SaltType.TEXT) // See getSaltLength() for length
|
||||
public abstract class HexSaltedMethod implements EncryptionMethod {
|
||||
|
||||
public abstract int getSaltLength();
|
||||
|
@ -20,7 +20,7 @@ public class BackupSettings implements SettingsClass {
|
||||
public static final Property<Boolean> ON_SERVER_STOP =
|
||||
newProperty("BackupSystem.OnServerStop", true);
|
||||
|
||||
@Comment(" Windows only mysql installation Path")
|
||||
@Comment("Windows only mysql installation Path")
|
||||
public static final Property<String> MYSQL_WINDOWS_PATH =
|
||||
newProperty("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
||||
|
||||
|
72
src/main/java/fr/xephi/authme/util/MigrationService.java
Normal file
72
src/main/java/fr/xephi/authme/util/MigrationService.java
Normal file
@ -0,0 +1,72 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.converter.ForceFlatToSqlite;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.security.crypts.SHA256;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Migrations to perform during the initialization of AuthMe.
|
||||
*/
|
||||
public final class MigrationService {
|
||||
|
||||
private MigrationService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash all passwords to SHA256 and updated the setting if the password hash is set to the deprecated PLAINTEXT.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
* @param dataSource The data source
|
||||
* @param authmeSha256 Instance to the AuthMe SHA256 encryption method implementation
|
||||
*/
|
||||
public static void changePlainTextToSha256(NewSetting settings, DataSource dataSource,
|
||||
SHA256 authmeSha256) {
|
||||
if (HashAlgorithm.PLAINTEXT == settings.getProperty(SecuritySettings.PASSWORD_HASH)) {
|
||||
ConsoleLogger.showError("Your HashAlgorithm has been detected as plaintext and is now deprecated;"
|
||||
+ " it will be changed and hashed now to the AuthMe default hashing method");
|
||||
List<PlayerAuth> allAuths = dataSource.getAllAuths();
|
||||
for (PlayerAuth auth : allAuths) {
|
||||
HashedPassword hashedPassword = authmeSha256.computeHash(
|
||||
auth.getPassword().getHash(), auth.getNickname());
|
||||
auth.setPassword(hashedPassword);
|
||||
dataSource.updatePassword(auth);
|
||||
}
|
||||
settings.setProperty(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
|
||||
settings.save();
|
||||
ConsoleLogger.info("Migrated " + allAuths.size() + " accounts from plaintext to SHA256");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the data source from the deprecated FLATFILE type to SQLITE.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
* @param dataSource The data source
|
||||
* @return The converted datasource (SQLite), or null if no migration was necessary
|
||||
*/
|
||||
public static DataSource convertFlatfileToSqlite(NewSetting settings, DataSource dataSource) {
|
||||
if (DataSourceType.FILE == settings.getProperty(DatabaseSettings.BACKEND)) {
|
||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated; it will be changed "
|
||||
+ "to SQLite... Connection will be impossible until conversion is done!");
|
||||
ForceFlatToSqlite converter = new ForceFlatToSqlite(dataSource, settings);
|
||||
DataSource result = converter.run();
|
||||
if (result == null) {
|
||||
throw new IllegalStateException("Error during conversion from flatfile to SQLite");
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user