Configuration option to require SSL on the database connection

This commit is contained in:
Brokkonaut
2019-05-14 17:54:33 +02:00
parent bd23c93071
commit 1602fdb03a
3 changed files with 9 additions and 2 deletions

View File

@@ -72,7 +72,7 @@ public class LogBlock extends JavaPlugin {
}
try {
getLogger().info("Connecting to " + user + "@" + url + "...");
pool = new MySQLConnectionPool(url, user, password);
pool = new MySQLConnectionPool(url, user, password, mysqlRequireSSL);
final Connection conn = getConnection(true);
if (conn == null) {
noDb = true;

View File

@@ -25,6 +25,7 @@ public class Config {
private static LoggingEnabledMapping superWorldConfig;
private static Map<String, WorldConfig> worldConfigs;
public static String url, user, password;
public static boolean mysqlRequireSSL;
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
public static boolean fireCustomEvents;
public static boolean useBukkitScheduler;
@@ -79,6 +80,7 @@ public class Config {
def.put("mysql.database", "minecraft");
def.put("mysql.user", "username");
def.put("mysql.password", "pass");
def.put("mysql.requireSSL", false);
def.put("consumer.delayBetweenRuns", 2);
def.put("consumer.forceToProcessAtLeast", 200);
def.put("consumer.timePerRun", 1000);
@@ -163,6 +165,7 @@ public class Config {
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
user = getStringIncludingInts(config, "mysql.user");
password = getStringIncludingInts(config, "mysql.password");
mysqlRequireSSL = config.getBoolean("mysql.requireSSL", false);
delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2);
forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0);
timePerRun = config.getInt("consumer.timePerRun", 1000);

View File

@@ -11,7 +11,7 @@ public class MySQLConnectionPool implements Closeable {
private final HikariDataSource ds;
public MySQLConnectionPool(String url, String user, String password) {
public MySQLConnectionPool(String url, String user, String password, boolean requireSSL) {
this.ds = new HikariDataSource();
ds.setJdbcUrl(url);
ds.setUsername(user);
@@ -29,6 +29,10 @@ public class MySQLConnectionPool implements Closeable {
ds.addDataSourceProperty("prepStmtCacheSize", "250");
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
ds.addDataSourceProperty("useServerPrepStmts", "true");
ds.addDataSourceProperty("useSSL", "true");
ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL));
ds.addDataSourceProperty("verifyServerCertificate", "false");
}
@Override