mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-16 11:51:56 +01:00
Merge branch 'HarvelsX-mariadb'
This commit is contained in:
commit
053519faa4
@ -1,5 +1,5 @@
|
||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||
<!-- File auto-generated on Mon Jul 18 13:02:11 CEST 2022. See docs/config/config.tpl.md -->
|
||||
<!-- File auto-generated on Thu Jul 28 18:11:22 CEST 2022. See docs/config/config.tpl.md -->
|
||||
|
||||
## AuthMe Configuration
|
||||
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
||||
@ -9,7 +9,7 @@ the generated config.yml file.
|
||||
```yml
|
||||
DataSource:
|
||||
# What type of database do you want to use?
|
||||
# Valid values: SQLITE, MYSQL, POSTGRESQL
|
||||
# Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL
|
||||
backend: SQLITE
|
||||
# Enable the database caching system, should be disabled on bungeecord environments
|
||||
# or when a website integration is being used.
|
||||
@ -31,11 +31,6 @@ DataSource:
|
||||
mySQLUsername: authme
|
||||
# Password to connect to the MySQL database
|
||||
mySQLPassword: '12345'
|
||||
# Driver Name of the MySQL database.
|
||||
# Built-in drivers:
|
||||
# MySQL: 'fr.xephi.authme.libs.com.mysql.cj.jdbc.Driver'
|
||||
# MariaDB: 'fr.xephi.authme.libs.org.mariadb.jdbc.Driver'
|
||||
mySQLDriverClassName: fr.xephi.authme.libs.com.mysql.cj.jdbc.Driver
|
||||
# Database Name, use with converters or as SQLITE database name
|
||||
mySQLDatabase: authme
|
||||
# Table of the database
|
||||
@ -593,4 +588,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 Mon Jul 18 13:02:11 CEST 2022
|
||||
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Thu Jul 28 18:11:22 CEST 2022
|
||||
|
@ -167,4 +167,6 @@ public abstract class AbstractSqlDataSource implements DataSource {
|
||||
return DataSourceValueImpl.unknownRow();
|
||||
}
|
||||
}
|
||||
|
||||
abstract String getJdbcUrl(String host, String port, String database);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ public enum DataSourceType {
|
||||
|
||||
MYSQL,
|
||||
|
||||
MARIADB,
|
||||
|
||||
POSTGRESQL,
|
||||
|
||||
SQLITE
|
||||
|
27
src/main/java/fr/xephi/authme/datasource/MariaDB.java
Normal file
27
src/main/java/fr/xephi/authme/datasource/MariaDB.java
Normal file
@ -0,0 +1,27 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import fr.xephi.authme.datasource.mysqlextensions.MySqlExtensionsFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MariaDB extends MySQL {
|
||||
public MariaDB(Settings settings, MySqlExtensionsFactory extensionsFactory) throws SQLException {
|
||||
super(settings, extensionsFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getJdbcUrl(String host, String port, String database) {
|
||||
return "jdbc:mariadb://" + host + ":" + port + "/" + database;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDriverClassName() {
|
||||
return "org.mariadb.jdbc.Driver";
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
return DataSourceType.MARIADB;
|
||||
}
|
||||
}
|
@ -44,7 +44,6 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
private String port;
|
||||
private String username;
|
||||
private String password;
|
||||
private String className;
|
||||
private String database;
|
||||
private String tableName;
|
||||
private int poolSize;
|
||||
@ -90,6 +89,15 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
setParameters(settings, extensionsFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of the Driver class to use when connecting to the database.
|
||||
*
|
||||
* @return the dotted path of the SQL driver class to be used
|
||||
*/
|
||||
protected String getDriverClassName() {
|
||||
return "com.mysql.cj.jdbc.Driver";
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves various settings.
|
||||
*
|
||||
@ -101,14 +109,6 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT);
|
||||
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) {
|
||||
this.className = DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getDefaultValue();
|
||||
logger.info("Driver class '" + this.className + "' not found! Falling back to the built-in MySQL driver ("
|
||||
+ this.className + ")");
|
||||
}
|
||||
this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||
this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS);
|
||||
@ -134,14 +134,14 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
ds.setMaxLifetime(maxLifetime * 1000L);
|
||||
|
||||
// Database URL
|
||||
ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||
ds.setJdbcUrl(this.getJdbcUrl(this.host, this.port, this.database));
|
||||
|
||||
// Auth
|
||||
ds.setUsername(this.username);
|
||||
ds.setPassword(this.password);
|
||||
|
||||
// Driver
|
||||
ds.setDriverClassName(this.className);
|
||||
ds.setDriverClassName(this.getDriverClassName());
|
||||
|
||||
// Request mysql over SSL
|
||||
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
|
||||
@ -299,7 +299,7 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
}
|
||||
|
||||
private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
||||
try (ResultSet rs = metaData.getColumns(database, null, tableName, columnName)) {
|
||||
return !rs.next();
|
||||
}
|
||||
}
|
||||
@ -348,6 +348,11 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getJdbcUrl(String host, String port, String database) {
|
||||
return "jdbc:mysql://" + host + ":" + port + "/" + database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
Set<String> list = new HashSet<>();
|
||||
|
@ -119,7 +119,7 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource {
|
||||
|
||||
// Database URL
|
||||
ds.setDriverClassName("org.postgresql.Driver");
|
||||
ds.setJdbcUrl("jdbc:postgresql://" + this.host + ":" + this.port + "/" + this.database);
|
||||
ds.setJdbcUrl(this.getJdbcUrl(this.host, this.port, this.database));
|
||||
|
||||
// Auth
|
||||
ds.setUsername(this.username);
|
||||
@ -306,6 +306,11 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getJdbcUrl(String host, String port, String database) {
|
||||
return "jdbc:postgresql://" + host + ":" + port + "/" + database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRecordsToPurge(long until) {
|
||||
Set<String> list = new HashSet<>();
|
||||
|
@ -88,7 +88,7 @@ public class SQLite extends AbstractSqlDataSource {
|
||||
}
|
||||
|
||||
logger.debug("SQLite driver loaded");
|
||||
this.con = DriverManager.getConnection("jdbc:sqlite:" + this.dataFolder + File.separator + database + ".db");
|
||||
this.con = DriverManager.getConnection(this.getJdbcUrl(this.dataFolder.getAbsolutePath(), "", this.database));
|
||||
this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings);
|
||||
}
|
||||
|
||||
@ -405,6 +405,11 @@ public class SQLite extends AbstractSqlDataSource {
|
||||
+ currentTimestamp + ", to all " + updatedRows + " rows");
|
||||
}
|
||||
|
||||
@Override
|
||||
String getJdbcUrl(String dataPath, String ignored, String database) {
|
||||
return "jdbc:sqlite:" + dataPath + File.separator + database + ".db";
|
||||
}
|
||||
|
||||
private static void close(Connection con) {
|
||||
if (con != null) {
|
||||
try {
|
||||
|
@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.datasource.MariaDB;
|
||||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.datasource.PostgreSqlDataSource;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
@ -66,6 +67,9 @@ public class DataSourceProvider implements Provider<DataSource> {
|
||||
case MYSQL:
|
||||
dataSource = new MySQL(settings, mySqlExtensionsFactory);
|
||||
break;
|
||||
case MARIADB:
|
||||
dataSource = new MariaDB(settings, mySqlExtensionsFactory);
|
||||
break;
|
||||
case POSTGRESQL:
|
||||
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
|
||||
break;
|
||||
|
@ -6,6 +6,7 @@ import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.properties.convertresult.PropertyValue;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.output.LogLevel;
|
||||
@ -65,10 +66,10 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
configurationData.setValue(ALLOWED_NICKNAME_CHARACTERS, "[a-zA-Z0-9_]*");
|
||||
changes = true;
|
||||
}
|
||||
String driverClass = reader.getString(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getPath());
|
||||
if ("com.mysql.jdbc.Driver".equals(driverClass) || "com.mysql.cj.jdbc.Driver".equals(driverClass)) {
|
||||
configurationData.setValue(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME,
|
||||
DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getDefaultValue());
|
||||
|
||||
String driverClass = reader.getString("DataSource.mySQLDriverClassName");
|
||||
if ("fr.xephi.authme.libs.org.mariadb.jdbc.Driver".equals(driverClass)) {
|
||||
configurationData.setValue(DatabaseSettings.BACKEND, DataSourceType.MARIADB);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
@ -100,7 +101,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
"settings.restrictions.keepCollisionsDisabled", "settings.forceCommands", "settings.forceCommandsAsConsole",
|
||||
"settings.forceRegisterCommands", "settings.forceRegisterCommandsAsConsole",
|
||||
"settings.sessions.sessionExpireOnIpChange", "settings.restrictions.otherAccountsCmd",
|
||||
"settings.restrictions.otherAccountsCmdThreshold"};
|
||||
"settings.restrictions.otherAccountsCmdThreshold, DataSource.mySQLDriverClassName"};
|
||||
for (String deprecatedPath : deprecatedProperties) {
|
||||
if (reader.contains(deprecatedPath)) {
|
||||
return true;
|
||||
|
@ -10,7 +10,7 @@ import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
public final class DatabaseSettings implements SettingsHolder {
|
||||
|
||||
@Comment({"What type of database do you want to use?",
|
||||
"Valid values: SQLITE, MYSQL, POSTGRESQL"})
|
||||
"Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL"})
|
||||
public static final Property<DataSourceType> BACKEND =
|
||||
newProperty(DataSourceType.class, "DataSource.backend", DataSourceType.SQLITE);
|
||||
|
||||
@ -49,13 +49,6 @@ public final class DatabaseSettings implements SettingsHolder {
|
||||
@Comment("Password to connect to the MySQL database")
|
||||
public static final Property<String> MYSQL_PASSWORD =
|
||||
newProperty("DataSource.mySQLPassword", "12345");
|
||||
|
||||
@Comment({"Driver Name of the MySQL database.",
|
||||
"Built-in drivers:",
|
||||
" MySQL: 'fr.xephi.authme.libs.com.mysql.cj.jdbc.Driver'",
|
||||
" MariaDB: 'fr.xephi.authme.libs.org.mariadb.jdbc.Driver'"})
|
||||
public static final Property<String> MYSQL_DRIVER_CLASS_NAME =
|
||||
newProperty("DataSource.mySQLDriverClassName", "fr.xephi.authme.libs.com.mysql.cj.jdbc.Driver");
|
||||
|
||||
@Comment("Database Name, use with converters or as SQLITE database name")
|
||||
public static final Property<String> MYSQL_DATABASE =
|
||||
|
Loading…
Reference in New Issue
Block a user