@@ -10,9 +10,11 @@ title = "SSL"
1010
1111## TLS/SSL
1212
13- The Java driver supports TLS/SSL connections to MongoDB servers using
14- the underlying support for TLS/SSL provided by the JDK.
15- To use TLS/SSL, you must configure the asynchronous driver to use [ Netty] ( http://netty.io/ ) .
13+ The asynchronous Java driver supports TLS/SSL connections to MongoDB servers using the underlying support
14+ for TLS/SSL provided by the JDK.
15+
16+ In its default configuration, the asynchronous driver is supported on Java 8+ when TLS/SSL is enabled.
17+ Otherwise, applications must configure the asynchronous driver to use [ Netty] ( http://netty.io/ ) .
1618
1719
1820## Specify TLS/SSL and Netty Configuration
@@ -24,7 +26,14 @@ Netty artifacts. The driver is currently tested against Netty 4.1.
2426
2527### Via Connection String
2628
27- To configure the driver to use Netty, include the ` ssl=true ` and ` streamType=netty ` options in the connection string, as in:
29+ To configure the driver to use TLS/SSL, include the ` ssl=true ` option in the connection string, as in:
30+
31+ ``` java
32+ MongoClient client = MongoClients . create(" mongodb://localhost/?ssl=true" );
33+ ```
34+
35+ To configure the driver to use use TLS/SSL with Netty, include the ` ssl=true ` and ` streamType=netty ` options in the connection string, as
36+ in:
2837
2938``` java
3039MongoClient client = MongoClients . create(" mongodb://localhost/?streamType=netty&ssl=true" );
@@ -36,12 +45,20 @@ The streamType connection string query parameter is deprecated as of the 3.10 re
3645
3746### Via ` MongoClientSettings `
3847
39- To specify TLS/SSL with [ ` MongoClientSettings ` ] ({{< apiref "com/mongodb/MongoClientSettings.Builder.html#streamFactoryFactory-com.mongodb.connection.StreamFactoryFactory-">}}) ,
40- set the `` sslEnabled `` property to `` true `` , and the stream factory to
41- [ ` NettyStreamFactoryFactory ` ] ({{< apiref "com/mongodb/connection/netty/NettyStreamFactoryFactory" >}}), as in
48+ To specify TLS/SSL with [ ` MongoClientSettings ` ] ({{< apiref "com/mongodb/MongoClientSettings.Builder.html#streamFactoryFactory-com.mongodb.connection.StreamFactoryFactory-">}}),
49+ set the `` sslEnabled `` property to ``true`, as in
4250
4351``` java
52+ MongoClient client = MongoClients . create(MongoClientSettings . builder()
53+ .applyToClusterSettings(builder - > builder. hosts(Arrays . asList(new ServerAddress ())))
54+ .applyToSslSettings(builder - > builder. enabled(true ))
55+ .build());
56+ ```
57+
58+ To specify TLS/SSL using Netty, set the `` sslEnabled `` property to `` true `` , and the stream factory to
59+ [ ` NettyStreamFactoryFactory ` ] ({{< apiref "com/mongodb/connection/netty/NettyStreamFactoryFactory" >}}), as in
4460
61+ ``` java
4562EventLoopGroup eventLoopGroup = new NioEventLoopGroup (); // make sure application shuts this down
4663
4764MongoClient client = MongoClients . create(MongoClientSettings . builder()
@@ -84,21 +101,18 @@ If your application must run on Java 6, or for some other reason you need
84101to disable host name verification, you must explicitly indicate this using the ` invalidHostNameAllowed ` property:
85102
86103``` java
87- EventLoopGroup eventLoopGroup = new NioEventLoopGroup (); // make sure application shuts this down
88-
89104MongoClient client = MongoClients . create(MongoClientSettings . builder()
105+ .applyToClusterSettings(builder - > builder. hosts(Arrays . asList(new ServerAddress ())))
90106 .applyToSslSettings(builder - >
91107 builder. enabled(true )
92108 .invalidHostNameAllowed(true ))
93- .streamFactoryFactory(NettyStreamFactoryFactory . builder()
94- .eventLoopGroup(eventLoopGroup). build())
95109 .build());
96110```
97111
98112Or via the connection string:
99113
100114``` java
101- MongoClient client = MongoClients . create(" mongodb://localhost/?ssl=true&sslInvalidHostNameAllowed=true&streamType=netty " );
115+ MongoClient client = MongoClients . create(" mongodb://localhost/?ssl=true&sslInvalidHostNameAllowed=true" );
102116```
103117
104118{{% note %}}
0 commit comments