Skip to content

Commit 7421685

Browse files
authored
Docsp 17234 (#177)
* document Netty config * fix api link * nits * nits * fix typo
1 parent 356e221 commit 7421685

File tree

1 file changed

+41
-3
lines changed
  • source/fundamentals/connection

1 file changed

+41
-3
lines changed

source/fundamentals/connection/tls.txt

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ To restrict your application to use only the TLS 1.2 protocol, set the
217217

218218
.. _tls-custom-sslContext:
219219

220-
Customize TLS/SSL Configuration with an SSLContext
221-
--------------------------------------------------
220+
Customize TLS/SSL Configuration through the Java SE SSLContext
221+
--------------------------------------------------------------
222222

223223
If your TLS/SSL configuration requires additional customization, you can
224224
set the ``sslContext`` property of your ``MongoClient`` by
225225
passing an `SSLContext
226-
<https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/class-use/SSLContext.html>`__
226+
<https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html>`__
227227
object to the builder in the ``applyToSslSettings()`` lambda:
228228

229229
.. code-block:: java
@@ -237,6 +237,44 @@ object to the builder in the ``applyToSslSettings()`` lambda:
237237
.build();
238238
MongoClient client = MongoClients.create(settings);
239239

240+
Customize TLS/SSL Configuration through the Netty SslContext
241+
------------------------------------------------------------
242+
243+
If you use the driver with `Netty <https://netty.io/>`__ for network IO,
244+
you have an option to plug an alternative TLS/SSL protocol implementation
245+
provided by Netty.
246+
247+
.. code-block:: java
248+
:copyable: true
249+
250+
import com.mongodb.MongoClientSettings;
251+
import com.mongodb.client.MongoClients;
252+
import com.mongodb.client.MongoClient;
253+
import com.mongodb.connection.netty.NettyStreamFactoryFactory;
254+
import io.netty.handler.ssl.SslContext;
255+
import io.netty.handler.ssl.SslContextBuilder;
256+
import io.netty.handler.ssl.SslProvider;
257+
258+
To instruct the driver to use `io.netty.handler.ssl.SslContext <https://netty.io/4.1/api/io/netty/handler/ssl/SslContext.html>`__,
259+
use the `NettyStreamFactoryFactory.Builder.sslContext <{+api+}/apidocs/mongodb-driver-core/com/mongodb/connection/netty/NettyStreamFactoryFactory.Builder.html#sslContext(io.netty.handler.ssl.SslContext)>`__
260+
method. See the method documentation for details about the different `io.netty.handler.ssl.SslProvider <https://netty.io/4.1/api/io/netty/handler/ssl/SslProvider.html>`__
261+
variants the driver supports and the implications of using them.
262+
263+
.. code-block:: java
264+
:copyable: true
265+
266+
SslContext sslContext = SslContextBuilder.forClient()
267+
.sslProvider(SslProvider.OPENSSL)
268+
.build();
269+
MongoClientSettings settings = MongoClientSettings.builder()
270+
.applyToSslSettings(builder -> builder.enabled(true))
271+
.streamFactoryFactory(NettyStreamFactoryFactory.builder()
272+
.sslContext(sslContext)
273+
.build())
274+
.build();
275+
MongoClient client = MongoClients.create(settings);
276+
277+
240278
Online Certificate Status Protocol (OCSP)
241279
-----------------------------------------
242280

0 commit comments

Comments
 (0)