From 18c31e3a42b6e62f12875e6378ea24e54c7405f1 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 21 Aug 2021 22:54:36 +0200 Subject: [PATCH] Update MySQL driver class name + implement fallback to the legacy driver --- docs/config.md | 8 ++++---- src/main/java/fr/xephi/authme/datasource/MySQL.java | 8 +++++++- .../xephi/authme/settings/SettingsMigrationService.java | 5 +++++ .../authme/settings/properties/DatabaseSettings.java | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/config.md b/docs/config.md index f2fbb87e..bd4275ec 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,5 +1,5 @@ - + ## AuthMe Configuration The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder, @@ -29,7 +29,7 @@ DataSource: # Password to connect to the MySQL database mySQLPassword: '12345' # Driver Name of the MySQL database - mySQLDriverClassName: com.mysql.jdbc.Driver + mySQLDriverClassName: com.mysql.cj.jdbc.Driver # Database Name, use with converters or as SQLITE database name mySQLDatabase: authme # Table of the database @@ -89,7 +89,7 @@ ExternalBoardOptions: # Other MySQL columns where we need to put the username (case-sensitive) mySQLOtherUsernameColumns: [] # How much log2 rounds needed in BCrypt (do not change if you do not know what it does) - bCryptLog2Round: 10 + bCryptLog2Round: 12 # phpBB table prefix defined during the phpBB installation process phpbbTablePrefix: phpbb_ # phpBB activated group ID; 2 is the default registered group defined by phpBB @@ -587,4 +587,4 @@ To change settings on a running server, save your changes to config.yml and use --- -This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sun Apr 04 21:31:43 CEST 2021 +This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Aug 21 22:53:23 CEST 2021 diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index be90bfc8..9591d8b5 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -101,6 +101,12 @@ public class MySQL extends AbstractSqlDataSource { this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME); this.password = settings.getProperty(DatabaseSettings.MYSQL_PASSWORD); this.className = settings.getProperty(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME); + try { + Class.forName(this.className); + } catch (ClassNotFoundException e) { + logger.info("Driver class '" + this.className + "' not found! Falling back to legacy MySQL driver (com.mysql.jdbc.Driver)"); + this.className = "com.mysql.jdbc.Driver"; + } this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE); this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE); this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS); @@ -122,7 +128,7 @@ public class MySQL extends AbstractSqlDataSource { // Pool Settings ds.setMaximumPoolSize(poolSize); - ds.setMaxLifetime(maxLifetime * 1000); + ds.setMaxLifetime(maxLifetime * 1000L); // Database URL ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); diff --git a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java index 29dfe7e5..84a0fdff 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java @@ -60,10 +60,15 @@ public class SettingsMigrationService extends PlainMigrationService { @SuppressWarnings("checkstyle:BooleanExpressionComplexity") protected boolean performMigrations(PropertyReader reader, ConfigurationData configurationData) { boolean changes = false; + if ("[a-zA-Z0-9_?]*".equals(reader.getString(ALLOWED_NICKNAME_CHARACTERS.getPath()))) { configurationData.setValue(ALLOWED_NICKNAME_CHARACTERS, "[a-zA-Z0-9_]*"); changes = true; } + if ("com.mysql.jdbc.Driver".equals(reader.getString(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getPath()))) { + configurationData.setValue(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME, "com.mysql.cj.jdbc.Driver"); + changes = true; + } setOldOtherAccountsCommandFieldsIfSet(reader); diff --git a/src/main/java/fr/xephi/authme/settings/properties/DatabaseSettings.java b/src/main/java/fr/xephi/authme/settings/properties/DatabaseSettings.java index be5a2aca..35c69484 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/DatabaseSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/DatabaseSettings.java @@ -47,7 +47,7 @@ public final class DatabaseSettings implements SettingsHolder { @Comment("Driver Name of the MySQL database") public static final Property MYSQL_DRIVER_CLASS_NAME = - newProperty("DataSource.mySQLDriverClassName", "com.mysql.jdbc.Driver"); + newProperty("DataSource.mySQLDriverClassName", "com.mysql.cj.jdbc.Driver"); @Comment("Database Name, use with converters or as SQLITE database name") public static final Property MYSQL_DATABASE =