0

I am using hibernate OGM to interact with mongoDB. As part of business requirement, I need to enable ssl for the communication between mongodb and my java application.

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. 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. I can not upgrade hibernateOGM version because its still either beta or 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

======== Update 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). 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

Obaid Maroof
  • 1,523
  • 2
  • 19
  • 40

1 Answers1

1

You can enable SSL using the following property:

hibernate.ogm.mongodb.driver.sslEnabled = true

you can also set:

hibernate.ogm.mongodb.driver.sslInvalidHostNameAllowed = true

HIbernate OGM uses the com.mongodb.MongoClientand you can set all the properties in com.mongod.MongoClientOptions using the prefix hibernate.ogm.mongodb.driver.

Check the documentation and MongoClient.Builder for more details.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
  • I have updated the question in light of your suggestion but now trapped in another problem. Do you have any other option to point at? – Obaid Maroof May 03 '16 at 15:43
  • Currently, there is an open issue for this: https://hibernate.atlassian.net/browse/OGM-975 – Davide D'Alto May 25 '16 at 10:17
  • One workaround might be to extend the MongoDBDatastoreProvider method: protected MongoClient createMongoClient(MongoDBConfiguration config) and use the parameter `hibernate.ogm.datastore.provider`. – Davide D'Alto May 25 '16 at 10:56