Skip to content

Commit abef198

Browse files
Docsp 17095 java subject (#147)
1 parent 68a285f commit abef198

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

source/fundamentals/enterprise-auth.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,21 @@ You may need to specify one or more of the following additional
158158
- :java-docs:`JAVA_SASL_CLIENT_PROPERTIES_KEY <apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html#JAVA_SASL_CLIENT_PROPERTIES_KEY>`
159159
- :java-docs:`JAVA_SUBJECT_PROVIDER_KEY <apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html#JAVA_SUBJECT_PROVIDER_KEY>`
160160

161-
Your code to instantiate a ``MongoClient`` using GSSAPI and additional
162-
properties might look something like this:
161+
Select the **SERVICE_NAME_KEY** or **JAVA_SUBJECT_KEY** tab to
162+
see sample code to instantiate a ``MongoCredential`` that uses GSSAPI and
163+
the selected property:
164+
165+
.. tabs::
166+
167+
.. tab::
168+
:tabid: SERVICE_NAME_KEY
163169

164-
.. include:: /includes/fundamentals/code-snippets/auth-credentials-gssapi-properties.rst
170+
.. include:: /includes/fundamentals/code-snippets/auth-credentials-gssapi-properties.rst
165171

172+
.. tab::
173+
:tabid: JAVA_SUBJECT_KEY
174+
175+
.. include:: /includes/fundamentals/code-snippets/auth-credentials-gssapi-subject-key.rst
166176

167177
By default, the Java driver caches Kerberos tickets by ``MongoClient`` instance.
168178
If your deployment needs to frequently create and destroy ``MongoClient`` instances,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. code-block:: java
2+
3+
LoginContext loginContext = new LoginContext(<LoginModule implementation from JAAS config>);
4+
loginContext.login();
5+
Subject subject = loginContext.getSubject();
6+
7+
MongoCredential credential = MongoCredential.createGSSAPICredential(<username>);
8+
credential = credential.withMechanismProperty(MongoCredential.JAVA_SUBJECT_KEY, subject);
9+

0 commit comments

Comments
 (0)