使用Hibernate指定证书

时间:2013-06-17 04:39:52

标签: hibernate

我正在寻找有关使用Hibernate启用SSL的信息,我遇到了这个问题(How can I configure Hibernate to use SSL to talk to the DB server?)。我在这里复制粘贴答案中提到的配置。

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://blablaba:8443/dbname?useSSL=true</property>
<property name="hibernate.connection.verifyServerCertificate">false</property>
<property name="hibernate.connection.requireSSL">true</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.connection.username">bablablab</property>
<property name="hibernate.connection.password">clclclclc</property>

我将使用哪些属性设置证书文件的路径,假设我要将verifyServerCertificate设置为True

1 个答案:

答案 0 :(得分:2)

假设您已经拥有证书,则需要

在命令行中添加路径信息:

-Djavax.net.ssl.keyStore=path_to_keystore_file
-Djavax.net.ssl.keyStorePassword=password
-Djavax.net.ssl.trustStore=path_to_truststore_file
-Djavax.net.ssl.trustStorePassword=password

或者您可以直接在应用程序中设置值:

System.setProperty("javax.net.ssl.keyStore","path_to_keystore_file");
System.setProperty("javax.net.ssl.keyStorePassword","password");
System.setProperty("javax.net.ssl.trustStore","path_to_truststore_file");
System.setProperty("javax.net.ssl.trustStorePassword","password");

阅读more from MySQL 5.1 documentation