@@ -32,9 +32,8 @@ Enterprise Edition:
32
32
- :ref:`LDAP (PLAIN) <plain-auth-mechanism>`
33
33
- :ref:`MONGODB-OIDC <kotlin-oidc>`
34
34
35
- For more
36
- information on establishing a connection to your MongoDB cluster, read our
37
- :doc:`Connection Guide </fundamentals/connection>`.
35
+ For more information on establishing a connection to your MongoDB cluster, read our
36
+ :ref:`Connection Guide <kotlin-sync-connect>`.
38
37
39
38
40
39
Specify an Authentication Mechanism
@@ -67,10 +66,10 @@ authenticating using a ``MongoCredential``.
67
66
For more information on these classes and methods, refer to the following API
68
67
documentation:
69
68
70
- - `MongoClient.create() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/ com.mongodb.kotlin.client.coroutine /-mongo-client/-factory/create .html>`__
71
- - `MongoClient <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/ com.mongodb.kotlin.client.coroutine /-mongo-client/index.html>`__
72
- - `MongoClientSettings.Builder <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__
73
- - `MongoCredential <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html>`__
69
+ - `MongoClient.create() <{+api+}/com.mongodb.kotlin.client/-mongo-client/-factory/index .html>`__
70
+ - `MongoClient <{+api+}/com.mongodb.kotlin.client/-mongo-client/index.html>`__
71
+ - `MongoClientSettings.Builder <{+java- api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__
72
+ - `MongoCredential <{+java- api+}/apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html>`__
74
73
75
74
Mechanisms
76
75
----------
@@ -120,8 +119,11 @@ mechanism:
120
119
121
120
Your code to instantiate a ``MongoClient`` should resemble the following:
122
121
123
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.gssapi-connection-string .kt
122
+ .. literalinclude:: /includes/security/enterprise-auth .kt
124
123
:language: kotlin
124
+ :dedent:
125
+ :start-after: start-gssapi-connect-string
126
+ :end-before: end-gssapi-connect-string
125
127
126
128
.. tab::
127
129
:tabid: MongoCredential
@@ -130,8 +132,11 @@ mechanism:
130
132
``MongoCredential`` class, use the ``createGSSAPICredential()``
131
133
method. Your code to instantiate a ``MongoClient`` should resemble the following:
132
134
133
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.auth-creds-gssapi .kt
135
+ .. literalinclude:: /includes/security/enterprise-auth .kt
134
136
:language: kotlin
137
+ :dedent:
138
+ :start-after: start-gssapi-mongo-cred
139
+ :end-before: end-gssapi-mongo-cred
135
140
136
141
In order to acquire a
137
142
`Kerberos ticket <https://docs.oracle.com/en/java/javase/11/docs/api/java.security.jgss/javax/security/auth/kerberos/KerberosTicket.html>`__,
@@ -177,8 +182,11 @@ You may need to specify one or more of the following additional
177
182
Your code to instantiate a ``MongoClient`` using GSSAPI and additional
178
183
properties might resemble the following:
179
184
180
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.gssapi-properties-connection-string.kt
181
- :language: kotlin
185
+ .. literalinclude:: /includes/security/enterprise-auth.kt
186
+ :language: kotlin
187
+ :dedent:
188
+ :start-after: start-gssapi-properties-connect-string
189
+ :end-before: end-gssapi-properties-connect-string
182
190
183
191
.. tab::
184
192
:tabid: MongoCredential
@@ -203,14 +211,20 @@ You may need to specify one or more of the following additional
203
211
.. tab::
204
212
:tabid: SERVICE_NAME_KEY
205
213
206
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.service-name-key.kt
207
- :language: kotlin
214
+ .. literalinclude:: /includes/security/enterprise-auth.kt
215
+ :language: kotlin
216
+ :dedent:
217
+ :start-after: start-gssapi-service-name-key
218
+ :end-before: end-gssapi-service-name-key
208
219
209
220
.. tab::
210
221
:tabid: JAVA_SUBJECT_KEY
211
222
212
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.java-subject-key.kt
213
- :language: kotlin
223
+ .. literalinclude:: /includes/security/enterprise-auth.kt
224
+ :language: kotlin
225
+ :dedent:
226
+ :start-after: start-gssapi-java-subject-key
227
+ :end-before: end-gssapi-java-subject-key
214
228
215
229
By default, the Kotlin driver caches Kerberos tickets by ``MongoClient`` instance.
216
230
If your deployment needs to frequently create and destroy ``MongoClient`` instances,
@@ -237,8 +251,11 @@ to improve performance.
237
251
in your ``MongoCredential`` instance. The code to configure the Kotlin driver to cache Kerberos tickets
238
252
by process should resemble the following:
239
253
240
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.kerberos-subject-provider.kt
241
- :language: kotlin
254
+ .. literalinclude:: /includes/security/enterprise-auth.kt
255
+ :language: kotlin
256
+ :dedent:
257
+ :start-after: start-gssapi-java-subject-provider
258
+ :end-before: end-gssapi-java-subject-provider
242
259
243
260
.. note::
244
261
@@ -252,7 +269,6 @@ to improve performance.
252
269
- `JDK-6722928 <https://bugs.openjdk.java.net/browse/JDK-6722928>`__
253
270
- `SO 23427343 <https://stackoverflow.com/questions/23427343/cannot-retrieve-tgt-despite-allowtgtsessionkey-registry-entry>`__
254
271
255
-
256
272
.. _plain-auth-mechanism:
257
273
258
274
LDAP (PLAIN)
@@ -303,8 +319,11 @@ mechanism:
303
319
304
320
Your code to instantiate a ``MongoClient`` should resemble the following:
305
321
306
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.ldap-connection-string .kt
322
+ .. literalinclude:: /includes/security/enterprise-auth .kt
307
323
:language: kotlin
324
+ :dedent:
325
+ :start-after: start-ldap-connect-string
326
+ :end-before: end-ldap-connect-string
308
327
309
328
.. tab::
310
329
:tabid: MongoCredential
@@ -313,8 +332,11 @@ mechanism:
313
332
``MongoCredential`` class, use the ``createPlainCredential()``
314
333
method. Your code to instantiate a ``MongoClient`` should resemble the following:
315
334
316
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.ldap-mongo-credential .kt
335
+ .. literalinclude:: /includes/security/enterprise-auth .kt
317
336
:language: kotlin
337
+ :dedent:
338
+ :start-after: start-ldap-mongo-cred
339
+ :end-before: end-ldap-mongo-cred
318
340
319
341
.. _kotlin-oidc:
320
342
@@ -366,8 +388,11 @@ see the corresponding syntax.
366
388
You must specify values that contain commas in a ``MongoCredential`` instance, as
367
389
demonstrated in the :guilabel:`MongoCredential` tab.
368
390
369
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.oidc-azure-connection-string .kt
391
+ .. literalinclude:: /includes/security/enterprise-auth .kt
370
392
:language: kotlin
393
+ :dedent:
394
+ :start-after: start-oidc-azure-connect-str
395
+ :end-before: end-oidc-azure-connect-str
371
396
372
397
.. tab:: MongoCredential
373
398
:tabid: mongodb-azure-mongo-credential
@@ -377,8 +402,11 @@ see the corresponding syntax.
377
402
placeholder with the value of the
378
403
``audience`` server parameter configured on your MongoDB deployment.
379
404
380
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.oidc-azure-credential .kt
405
+ .. literalinclude:: /includes/security/enterprise-auth .kt
381
406
:language: kotlin
407
+ :dedent:
408
+ :start-after: start-oidc-azure-mongo-cred
409
+ :end-before: end-oidc-azure-mongo-cred
382
410
383
411
.. _kotlin-mongodb-oidc-gcp-imds:
384
412
@@ -412,17 +440,23 @@ see the corresponding syntax.
412
440
You must specify values that contain commas in a ``MongoCredential`` instance, as
413
441
demonstrated in the :guilabel:`MongoCredential` tab.
414
442
415
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-connection-string .kt
443
+ .. literalinclude:: /includes/security/enterprise-auth .kt
416
444
:language: kotlin
445
+ :dedent:
446
+ :start-after: start-oidc-gcp-connect-str
447
+ :end-before: end-oidc-gcp-connect-str
417
448
418
449
.. tab:: MongoCredential
419
450
:tabid: mongodb-gcp-mongo-credential
420
451
421
452
Replace the ``<audience>`` placeholder with the value of the
422
453
``audience`` server parameter configured on your MongoDB deployment.
423
454
424
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-credential .kt
455
+ .. literalinclude:: /includes/security/enterprise-auth .kt
425
456
:language: kotlin
457
+ :dedent:
458
+ :start-after: start-oidc-gcp-mongo-cred
459
+ :end-before: end-oidc-gcp-mongo-cred
426
460
427
461
Custom Callback
428
462
+++++++++++++++
@@ -433,8 +467,11 @@ must define a custom callback to use OIDC to authenticate from these platforms.
433
467
To do so, use the ``"OIDC_CALLBACK"`` authentication property, as shown in the following
434
468
code example:
435
469
436
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.oidc-callback .kt
470
+ .. literalinclude:: /includes/security/enterprise-auth .kt
437
471
:language: kotlin
472
+ :dedent:
473
+ :start-after: start-oidc-custom-callback
474
+ :end-before: end-oidc-custom-callback
438
475
439
476
The value of the ``"OIDC_CALLBACK"`` property must be a lambda or other implementation
440
477
of the ``OidcCallback`` functional interface that accepts an ``OidcCallbackContext``
@@ -443,5 +480,8 @@ as a parameter and returns an ``OidcCallbackResult``.
443
480
The following example uses an example callback to retrieve an OIDC token from a file
444
481
named ``"access-token.dat"`` in the local file system:
445
482
446
- .. literalinclude:: /examples/generated/EnterpriseAuthTest.snippet.oidc-callback-file .kt
483
+ .. literalinclude:: /includes/security/enterprise-auth .kt
447
484
:language: kotlin
485
+ :dedent:
486
+ :start-after: start-oidc-custom-callback-ex
487
+ :end-before: end-oidc-custom-callback-ex
0 commit comments