Skip to content

Commit 04f4ae0

Browse files
committed
DOCSP-48679: strongly recommend Netty (#124)
(cherry picked from commit 2f0b2ea)
1 parent d3f7200 commit 04f4ae0

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

snooty.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ mdb-server = "MongoDB Server"
3636
snappyVersion = "org.xerial.snappy:snappy-java:1.1.10.3"
3737
zstdVersion = "com.github.luben:zstd-jni:1.5.5-3"
3838
stable-api = "Stable API"
39+
netty-version = "io.netty:netty-all:4.1.87.Final"

source/connect-to-mongo/tls.txt

+49-28
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,27 @@ TLS/SSL
1717
:depth: 2
1818
:class: singlecol
1919

20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to use the **TLS protocol** to secure your
24+
connection to a MongoDB deployment. TLS is a cryptographic protocol that
25+
secures communication between your application and MongoDB. To configure
26+
your connection to use TLS, enable the TLS option and provide your
27+
certificates for validation when creating a client.
28+
2029
By default, the driver supports TLS/SSL connections to MongoDB
2130
servers using the underlying support for TLS/SSL provided by the JDK.
22-
This can be changed either by utilizing the extensibility of the `Java SE
23-
API <https://docs.oracle.com/javase/8/docs/api/>`__, or by using the
24-
`Netty API <https://netty.io/4.1/api/>`__.
31+
This can be changed either by using the `Netty API
32+
<https://netty.io/4.1/api/>`__ or the extensibility of the `Java SE
33+
API <https://docs.oracle.com/javase/8/docs/api/>`__.
34+
35+
.. tip:: Prefer Netty for Asynchronous Apps
36+
37+
We recommend using Netty for asychronous applications because it supports
38+
asynchronous I/O and handles high connection volumes effectively. To
39+
learn about using Netty to configure your TLS settings, see the
40+
:ref:`java-rs-tls-netty-config` section of this guide.
2541

2642
MongoClient API
2743
---------------
@@ -68,30 +84,10 @@ To specify TLS/SSL in a ``MongoClientSettings`` instance, set the
6884
.build();
6985
MongoClient client = MongoClients.create(settings);
7086

71-
Specify Java SE SSLContext in MongoClientSettings
72-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73-
74-
Include the following import statements:
75-
76-
.. code-block:: java
77-
78-
import javax.net.ssl.SSLContext;
79-
import com.mongodb.MongoClientSettings;
80-
import com.mongodb.MongoClient;
81-
82-
To specify the ``javax.net.ssl.SSLContext`` with
83-
``MongoClientSettings``, set the ``sslContext`` property:
84-
85-
.. code-block:: java
86-
87-
SSLContext sslContext = ...
88-
MongoClientSettings settings = MongoClientSettings.builder()
89-
.applyToSslSettings(builder -> builder.enabled(true).context(sslContext))
90-
.build();
91-
MongoClient client = new MongoClient(settings);
87+
.. _java-rs-tls-netty-config:
9288

93-
Customize TLS/SSL Configuration through the Netty SslContext
94-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89+
Configure TLS/SSL by Using Netty SslContext
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9591

9692
Include the following import statements:
9793

@@ -105,9 +101,9 @@ Include the following import statements:
105101
import io.netty.handler.ssl.SslContextBuilder;
106102
import io.netty.handler.ssl.SslProvider;
107103

108-
.. note::
104+
.. note:: Netty Package Version
109105

110-
The driver tests with Netty version ``io.netty:netty-all:4.1.87.Final``
106+
The driver tests with Netty package version ``{+netty-version+}``
111107

112108
To instruct the driver to use
113109
`io.netty.handler.ssl.SslContext <https://netty.io/4.1/api/io/netty/handler/ssl/SslContext.html>`__,
@@ -118,21 +114,46 @@ Use ``MongoClientSettings.Builder.transportSettings()``
118114
and ``NettyTransportSettings.Builder.sslContext()`` to build your settings:
119115

120116
.. code-block:: java
117+
:emphasize-lines: 7-9
121118

122119
SslContext sslContext = SslContextBuilder.forClient()
123120
.sslProvider(SslProvider.OPENSSL)
124121
.build();
122+
125123
MongoClientSettings settings = MongoClientSettings.builder()
126124
.applyToSslSettings(builder -> builder.enabled(true))
127125
.transportSettings(TransportSettings.nettyBuilder()
128126
.sslContext(sslContext)
129127
.build())
130128
.build();
129+
131130
MongoClient client = MongoClients.create(settings);
132131

133132
For more details about the ``io.netty.handler.ssl.SslProvider``, see the `Netty
134133
documentation <https://netty.io/4.1/api/io/netty/handler/ssl/SslProvider.html>`__.
135134

135+
Specify Java SE SSLContext in MongoClientSettings
136+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137+
138+
Include the following import statements:
139+
140+
.. code-block:: java
141+
142+
import javax.net.ssl.SSLContext;
143+
import com.mongodb.MongoClientSettings;
144+
import com.mongodb.MongoClient;
145+
146+
To specify the ``javax.net.ssl.SSLContext`` with
147+
``MongoClientSettings``, set the ``sslContext`` property:
148+
149+
.. code-block:: java
150+
151+
SSLContext sslContext = ...
152+
MongoClientSettings settings = MongoClientSettings.builder()
153+
.applyToSslSettings(builder -> builder.enabled(true).context(sslContext))
154+
.build();
155+
MongoClient client = new MongoClient(settings);
156+
136157
Disable Hostname Verification
137158
-----------------------------
138159

0 commit comments

Comments
 (0)