@@ -24,25 +24,33 @@ public class MongoConfig {
2424 @ Value ("${truststore.pwd}" )
2525 private String trustStorePwd ;
2626
27+ @ Value ("${mongodb.atlas}" )
28+ private boolean atlas ;
29+
2730 @ Bean
2831 public MongoClient mongo () {
2932
3033 ConnectionString connectionString = new ConnectionString (uri );
3134
32- SSLFactory sslFactory = SSLFactory .builder ()
33- .withTrustMaterial (Paths .get (trustStorePath ), trustStorePwd .toCharArray ())
34- .build ();
35-
36- SSLContext sslContext = sslFactory .getSslContext ();
37- MongoClientSettings mongoClientSettings = MongoClientSettings .builder ()
38- .applyConnectionString (connectionString )
39- .applyToSslSettings (builder -> {
40- builder .context (sslContext );
41- builder .invalidHostNameAllowed (true );
42- builder .enabled (true );
35+ MongoClientSettings mongoClientSettings = MongoClientSettings .builder ()
36+ .applyConnectionString (connectionString )
37+ .applyToSslSettings (builder -> {
38+
39+ if (!atlas ) {
40+ // Use SSLContext if a trustStore has been provided
41+ if (!trustStorePath .isEmpty ()) {
42+ SSLFactory sslFactory = SSLFactory .builder ()
43+ .withTrustMaterial (Paths .get (trustStorePath ), trustStorePwd .toCharArray ())
44+ .build ();
45+ SSLContext sslContext = sslFactory .getSslContext ();
46+ builder .context (sslContext );
47+ builder .invalidHostNameAllowed (true );
48+ }
49+ }
50+ builder .enabled (true );
51+ })
52+ .build ();
4353
44- })
45- .build ();
4654
4755 return MongoClients .create (mongoClientSettings );
4856 }
0 commit comments