mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-19 13:21:36 +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 -->
|
<!-- 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
|
## AuthMe Configuration
|
||||||
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
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
|
```yml
|
||||||
DataSource:
|
DataSource:
|
||||||
# What type of database do you want to use?
|
# What type of database do you want to use?
|
||||||
# Valid values: SQLITE, MYSQL, POSTGRESQL
|
# Valid values: SQLITE, MARIADB, MYSQL, POSTGRESQL
|
||||||
backend: SQLITE
|
backend: SQLITE
|
||||||
# Enable the database caching system, should be disabled on bungeecord environments
|
# Enable the database caching system, should be disabled on bungeecord environments
|
||||||
# or when a website integration is being used.
|
# or when a website integration is being used.
|
||||||
@ -31,11 +31,6 @@ DataSource:
|
|||||||
mySQLUsername: authme
|
mySQLUsername: authme
|
||||||
# Password to connect to the MySQL database
|
# Password to connect to the MySQL database
|
||||||
mySQLPassword: '12345'
|
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
|
# Database Name, use with converters or as SQLITE database name
|
||||||
mySQLDatabase: authme
|
mySQLDatabase: authme
|
||||||
# Table of the database
|
# 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();
|
return DataSourceValueImpl.unknownRow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract String getJdbcUrl(String host, String port, String database);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ public enum DataSourceType {
|
|||||||
|
|
||||||
MYSQL,
|
MYSQL,
|
||||||
|
|
||||||
|
MARIADB,
|
||||||
|
|
||||||
POSTGRESQL,
|
POSTGRESQL,
|
||||||
|
|
||||||
SQLITE
|
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 port;
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
private String className;
|
|
||||||
private String database;
|
private String database;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
private int poolSize;
|
private int poolSize;
|
||||||
@ -90,6 +89,15 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
setParameters(settings, extensionsFactory);
|
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.
|
* Retrieves various settings.
|
||||||
*
|
*
|
||||||
@ -101,14 +109,6 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT);
|
this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT);
|
||||||
this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME);
|
this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME);
|
||||||
this.password = settings.getProperty(DatabaseSettings.MYSQL_PASSWORD);
|
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.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE);
|
||||||
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
|
||||||
this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS);
|
this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS);
|
||||||
@ -134,14 +134,14 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
ds.setMaxLifetime(maxLifetime * 1000L);
|
ds.setMaxLifetime(maxLifetime * 1000L);
|
||||||
|
|
||||||
// Database URL
|
// Database URL
|
||||||
ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
ds.setJdbcUrl(this.getJdbcUrl(this.host, this.port, this.database));
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
ds.setUsername(this.username);
|
ds.setUsername(this.username);
|
||||||
ds.setPassword(this.password);
|
ds.setPassword(this.password);
|
||||||
|
|
||||||
// Driver
|
// Driver
|
||||||
ds.setDriverClassName(this.className);
|
ds.setDriverClassName(this.getDriverClassName());
|
||||||
|
|
||||||
// Request mysql over SSL
|
// Request mysql over SSL
|
||||||
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
|
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
|
||||||
@ -299,7 +299,7 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException {
|
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();
|
return !rs.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,6 +348,11 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getJdbcUrl(String host, String port, String database) {
|
||||||
|
return "jdbc:mysql://" + host + ":" + port + "/" + database;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getRecordsToPurge(long until) {
|
public Set<String> getRecordsToPurge(long until) {
|
||||||
Set<String> list = new HashSet<>();
|
Set<String> list = new HashSet<>();
|
||||||
|
@ -119,7 +119,7 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource {
|
|||||||
|
|
||||||
// Database URL
|
// Database URL
|
||||||
ds.setDriverClassName("org.postgresql.Driver");
|
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
|
// Auth
|
||||||
ds.setUsername(this.username);
|
ds.setUsername(this.username);
|
||||||
@ -306,6 +306,11 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getJdbcUrl(String host, String port, String database) {
|
||||||
|
return "jdbc:postgresql://" + host + ":" + port + "/" + database;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getRecordsToPurge(long until) {
|
public Set<String> getRecordsToPurge(long until) {
|
||||||
Set<String> list = new HashSet<>();
|
Set<String> list = new HashSet<>();
|
||||||
|
@ -88,7 +88,7 @@ public class SQLite extends AbstractSqlDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("SQLite driver loaded");
|
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);
|
this.columnsHandler = AuthMeColumnsHandler.createForSqlite(con, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,6 +405,11 @@ public class SQLite extends AbstractSqlDataSource {
|
|||||||
+ currentTimestamp + ", to all " + updatedRows + " rows");
|
+ 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) {
|
private static void close(Connection con) {
|
||||||
if (con != null) {
|
if (con != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.datasource.CacheDataSource;
|
import fr.xephi.authme.datasource.CacheDataSource;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.datasource.DataSourceType;
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
|
import fr.xephi.authme.datasource.MariaDB;
|
||||||
import fr.xephi.authme.datasource.MySQL;
|
import fr.xephi.authme.datasource.MySQL;
|
||||||
import fr.xephi.authme.datasource.PostgreSqlDataSource;
|
import fr.xephi.authme.datasource.PostgreSqlDataSource;
|
||||||
import fr.xephi.authme.datasource.SQLite;
|
import fr.xephi.authme.datasource.SQLite;
|
||||||
@ -66,6 +67,9 @@ public class DataSourceProvider implements Provider<DataSource> {
|
|||||||
case MYSQL:
|
case MYSQL:
|
||||||
dataSource = new MySQL(settings, mySqlExtensionsFactory);
|
dataSource = new MySQL(settings, mySqlExtensionsFactory);
|
||||||
break;
|
break;
|
||||||
|
case MARIADB:
|
||||||
|
dataSource = new MariaDB(settings, mySqlExtensionsFactory);
|
||||||
|
break;
|
||||||
case POSTGRESQL:
|
case POSTGRESQL:
|
||||||
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
|
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
|
||||||
break;
|
break;
|
||||||
|
@ -6,6 +6,7 @@ import ch.jalu.configme.properties.Property;
|
|||||||
import ch.jalu.configme.properties.convertresult.PropertyValue;
|
import ch.jalu.configme.properties.convertresult.PropertyValue;
|
||||||
import ch.jalu.configme.resource.PropertyReader;
|
import ch.jalu.configme.resource.PropertyReader;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.datasource.DataSourceType;
|
||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||||
import fr.xephi.authme.output.LogLevel;
|
import fr.xephi.authme.output.LogLevel;
|
||||||
@ -65,10 +66,10 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
configurationData.setValue(ALLOWED_NICKNAME_CHARACTERS, "[a-zA-Z0-9_]*");
|
configurationData.setValue(ALLOWED_NICKNAME_CHARACTERS, "[a-zA-Z0-9_]*");
|
||||||
changes = true;
|
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)) {
|
String driverClass = reader.getString("DataSource.mySQLDriverClassName");
|
||||||
configurationData.setValue(DatabaseSettings.MYSQL_DRIVER_CLASS_NAME,
|
if ("fr.xephi.authme.libs.org.mariadb.jdbc.Driver".equals(driverClass)) {
|
||||||
DatabaseSettings.MYSQL_DRIVER_CLASS_NAME.getDefaultValue());
|
configurationData.setValue(DatabaseSettings.BACKEND, DataSourceType.MARIADB);
|
||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
"settings.restrictions.keepCollisionsDisabled", "settings.forceCommands", "settings.forceCommandsAsConsole",
|
"settings.restrictions.keepCollisionsDisabled", "settings.forceCommands", "settings.forceCommandsAsConsole",
|
||||||
"settings.forceRegisterCommands", "settings.forceRegisterCommandsAsConsole",
|
"settings.forceRegisterCommands", "settings.forceRegisterCommandsAsConsole",
|
||||||
"settings.sessions.sessionExpireOnIpChange", "settings.restrictions.otherAccountsCmd",
|
"settings.sessions.sessionExpireOnIpChange", "settings.restrictions.otherAccountsCmd",
|
||||||
"settings.restrictions.otherAccountsCmdThreshold"};
|
"settings.restrictions.otherAccountsCmdThreshold, DataSource.mySQLDriverClassName"};
|
||||||
for (String deprecatedPath : deprecatedProperties) {
|
for (String deprecatedPath : deprecatedProperties) {
|
||||||
if (reader.contains(deprecatedPath)) {
|
if (reader.contains(deprecatedPath)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,7 +10,7 @@ import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
|||||||
public final class DatabaseSettings implements SettingsHolder {
|
public final class DatabaseSettings implements SettingsHolder {
|
||||||
|
|
||||||
@Comment({"What type of database do you want to use?",
|
@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 =
|
public static final Property<DataSourceType> BACKEND =
|
||||||
newProperty(DataSourceType.class, "DataSource.backend", DataSourceType.SQLITE);
|
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")
|
@Comment("Password to connect to the MySQL database")
|
||||||
public static final Property<String> MYSQL_PASSWORD =
|
public static final Property<String> MYSQL_PASSWORD =
|
||||||
newProperty("DataSource.mySQLPassword", "12345");
|
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")
|
@Comment("Database Name, use with converters or as SQLITE database name")
|
||||||
public static final Property<String> MYSQL_DATABASE =
|
public static final Property<String> MYSQL_DATABASE =
|
||||||
|
Loading…
Reference in New Issue
Block a user