[英]Enable SSL for mongoDB using hibernate OGM
I am using hibernate OGM to interact with mongoDB. 我正在使用休眠OGM与mongoDB进行交互。 As part of business requirement, I need to enable ssl
for the communication between mongodb and my java application. 作为业务需求的一部分,我需要启用ssl
,以实现mongodb与Java应用程序之间的通信。
I see in mongodb documentation that using the mongodb-java-driver, it is as simple as turing the ssl flag to true in the connection string. 我在mongodb文档中看到,使用mongodb-java-driver,就像将连接字符串中的ssl标志设置为true一样简单。 How can I do this in hibernate? 如何在休眠状态下执行此操作?
===== UPDATE based on the only given answer ====== =====根据唯一给出的答案进行更新======
Hibernate OGM version 4.2 uses mongodb Java driver version 2.13 which doesn't include the ssl property in MongoClientOptions.Builder class. Hibernate OGM版本4.2使用mongodb Java驱动程序版本2.13,该版本在MongoClientOptions.Builder类中不包含ssl属性。 I can not upgrade hibernateOGM version because its still either beta or alpha. 我不能升级hibernateOGM版本,因为它仍然是beta或alpha。 I tried explicitly upgrade the java driver version but then I started getting exception java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ogm.datastore.mongodb.options.impl.WriteConcernOption
我尝试显式升级Java驱动程序版本,但随后开始获取异常java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ogm.datastore.mongodb.options.impl.WriteConcernOption
======== Update 2 ============== ========更新2 ==============
I looked into the mongodb java driver documentation and found that setting socketFactory
option to SSLSocketFactory
might to the trick (see https://docs.mongodb.org/v2.6/tutorial/configure-ssl-clients/#java ). 我查看了mongodb java驱动程序文档,发现将socketFactory
选项设置为SSLSocketFactory
可能会达到目的(请参阅https://docs.mongodb.org/v2.6/tutorial/configure-ssl-clients/#java )。 But seems like hibernate OGM 4.2 is not picking up the following property to use the SSLSocketFactory for creating mongo client: hibernate.ogm.mongodb.driver.socketFactory=SSLSocketFactory
但是似乎休眠的OGM 4.2并未选择以下属性来使用SSLSocketFactory创建mongo客户端: hibernate.ogm.mongodb.driver.socketFactory=SSLSocketFactory
You can enable SSL using the following property: 您可以使用以下属性启用SSL:
hibernate.ogm.mongodb.driver.sslEnabled = true
you can also set: 您还可以设置:
hibernate.ogm.mongodb.driver.sslInvalidHostNameAllowed = true
HIbernate OGM uses the com.mongodb.MongoClient
and you can set all the properties in com.mongod.MongoClientOptions
using the prefix hibernate.ogm.mongodb.driver
. HIbernate OGM使用com.mongodb.MongoClient
,您可以使用前缀hibernate.ogm.mongodb.driver
设置com.mongod.MongoClientOptions
中的所有属性。
Check the documentation and MongoClient.Builder for more details. 查看文档和MongoClient.Builder以获取更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.