简体   繁体   中英

SSL connection using slick and hikariCP

I am trying to set up SSL encryption with Slick and HikariCP. here is conf:

mysqldb = {
  dataSourceClass = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
  initializationFailFast = false
  properties {
    user = "ssl_user"
    password = "root"
    databaseName = "ssl_db"
    serverName = "localhost"
    useUnicode = true
    characterEncoding = UTF-8
    useSSL="true"
    javax.net.ssl.trustStore="/home/ec2-user/rds-combined-ca-bundle.pem"
    javax.net.ssl.trustStorePassword=""

  }
  connectionTimeout = 10000
  numThreads = 10
  maxConnections = 10
  minConnections = 4
  queueSize =10000
}

Code to create connection:

  import slick.jdbc.MySQLProfile.api._

  val connectionPool = Database.forConfig(s"mysqldb")
  val session = connectionPool.createSession()

But, It is throwing error:

Exception in thread "main" java.lang.RuntimeException: Property javax does not exist on target class com.mysql.jdbc.jdbc2.optional.MysqlDataSource
    at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:131)
    at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties$0(PropertyElf.java:57)
    at java.util.Hashtable.forEach(Hashtable.java:879)
    at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:52)
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:333)
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:109)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
    at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
    at slick.jdbc.hikaricp.HikariCPJdbcDataSource$.forConfig(HikariCPJdbcDataSource.scala:92)
    at slick.jdbc.hikaricp.HikariCPJdbcDataSource$.forConfig(HikariCPJdbcDataSource.scala:21)
    at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:47)
    at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig(JdbcBackend.scala:341)
    at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig$(JdbcBackend.scala:337)
    at slick.jdbc.JdbcBackend$$anon$1.forConfig(JdbcBackend.scala:32)
    at com.techmonad.SSLConnection$.delayedEndpoint$com$techmonad$SSLConnection$1(SSLConnection.scala:7)
    at com.techmonad.SSLConnection$delayedInit$body.apply(SSLConnection.scala:3)
    at scala.Function0.apply$mcV$sp(Function0.scala:39)
    at scala.Function0.apply$mcV$sp$(Function0.scala:39)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
    at scala.App.$anonfun$main$1(App.scala:73)
    at scala.App.$anonfun$main$1$adapted(App.scala:73)
    at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
    at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
    at scala.App.main(App.scala:73)
    at scala.App.main$(App.scala:71)

Any help would be appreciated.

sslMode is an unsupported configuration property for com.mysql.jdbc.jdbc2.optional.MysqlDataSource . According to the documentation, it does support useSSL=true/false . By default, this is set to true for MySQL 5.6.26+ or 5.7.6+, otherwise fales.

You can find all the security related configuration parameters here: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html .

If you're interested in verifying the certificate of the MySQL server, take a look at the verifyServerCertificate property's explanation.

There's also a page detailing how to setup a secure connection to MySQL using the jdbc2 driver: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-using-ssl.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM