Add an option to disable MySQL server certificate check - Fix #1735
This commit is contained in:
parent
08c1bb33c7
commit
44cb787577
@ -34,6 +34,7 @@ import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException;
|
|||||||
public class MySQL extends AbstractSqlDataSource {
|
public class MySQL extends AbstractSqlDataSource {
|
||||||
|
|
||||||
private boolean useSsl;
|
private boolean useSsl;
|
||||||
|
private boolean serverCertificateVerification;
|
||||||
private String host;
|
private String host;
|
||||||
private String port;
|
private String port;
|
||||||
private String username;
|
private String username;
|
||||||
@ -103,6 +104,7 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
|
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
|
||||||
this.maxLifetime = settings.getProperty(DatabaseSettings.MYSQL_CONNECTION_MAX_LIFETIME);
|
this.maxLifetime = settings.getProperty(DatabaseSettings.MYSQL_CONNECTION_MAX_LIFETIME);
|
||||||
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
||||||
|
this.serverCertificateVerification = settings.getProperty(DatabaseSettings.MYSQL_CHECK_SERVER_CERTIFICATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,6 +128,11 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
// Request mysql over SSL
|
// Request mysql over SSL
|
||||||
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
|
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
|
||||||
|
|
||||||
|
// Disabling server certificate verification on need
|
||||||
|
if (!serverCertificateVerification) {
|
||||||
|
ds.addDataSourceProperty("verifyServerCertificate", String.valueOf(false));
|
||||||
|
}
|
||||||
|
|
||||||
// Encoding
|
// Encoding
|
||||||
ds.addDataSourceProperty("characterEncoding", "utf8");
|
ds.addDataSourceProperty("characterEncoding", "utf8");
|
||||||
ds.addDataSourceProperty("encoding", "UTF-8");
|
ds.addDataSourceProperty("encoding", "UTF-8");
|
||||||
|
|||||||
@ -31,6 +31,12 @@ public final class DatabaseSettings implements SettingsHolder {
|
|||||||
public static final Property<Boolean> MYSQL_USE_SSL =
|
public static final Property<Boolean> MYSQL_USE_SSL =
|
||||||
newProperty("DataSource.mySQLUseSSL", true);
|
newProperty("DataSource.mySQLUseSSL", true);
|
||||||
|
|
||||||
|
@Comment({"Verification of server's certificate.",
|
||||||
|
"We would not recommend to set this option to false.",
|
||||||
|
"Set this option to false at your own risk if and only if you know what you're doing"})
|
||||||
|
public static final Property<Boolean> MYSQL_CHECK_SERVER_CERTIFICATE =
|
||||||
|
newProperty( "DataSource.mySQLCheckServerCertificate", true );
|
||||||
|
|
||||||
@Comment("Username to connect to the MySQL database")
|
@Comment("Username to connect to the MySQL database")
|
||||||
public static final Property<String> MYSQL_USERNAME =
|
public static final Property<String> MYSQL_USERNAME =
|
||||||
newProperty("DataSource.mySQLUsername", "authme");
|
newProperty("DataSource.mySQLUsername", "authme");
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class AuthMeSettingsRetrieverTest {
|
|||||||
// an error margin of 10: this prevents us from having to adjust the test every time the config is changed.
|
// an error margin of 10: this prevents us from having to adjust the test every time the config is changed.
|
||||||
// If this test fails, replace the first argument in closeTo() with the new number of properties
|
// If this test fails, replace the first argument in closeTo() with the new number of properties
|
||||||
assertThat((double) configurationData.getProperties().size(),
|
assertThat((double) configurationData.getProperties().size(),
|
||||||
closeTo(171, 10));
|
closeTo(182, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user