I am connecting to MySQL over SSL from my Java application. I have configured MYSQL to support SSL and generated client certificates. I have imported server CA certificate a
You can configure the useSSl, requireSSL, and verifyServerCertificate properties of a DataSource by using Java based configuration. The addDataSourceProperty method of the DataSource class gives you the ability, as shown in the below code snippet (you can replace HikariDataSource with a C3p0 instance)
MySQL Connector/J exposes configuration properties for key stores (e.g. trustCertificateKeyStoreUrl), so I assume that addDataSourceProperty can be used for these properties too.
I do not know if the XML configuration schema provides a tag that corresponds to addDataSourceProperty.
public DataSource createPslDataSource(final MyDataSourceProperties myDataSourceProperties) {
HikariDataSource dataSource = new HikariDataSource();
dataSource.addDataSourceProperty("useSSL", true);
dataSource.addDataSourceProperty("requireSSL", true);
dataSource.addDataSourceProperty("verifyServerCertificate", true);
dataSource.setJdbcUrl(myDataSourceProperties.getJdbcUrl());
dataSource.setUsername(myDataSourceProperties.getUsername());
dataSource.setPassword(myDataSourceProperties.getPassword());
return dataSource;
}