File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
includes/fundamentals/code-snippets Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -158,11 +158,21 @@ You may need to specify one or more of the following additional
158
158
- :java-docs:`JAVA_SASL_CLIENT_PROPERTIES_KEY <apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html#JAVA_SASL_CLIENT_PROPERTIES_KEY>`
159
159
- :java-docs:`JAVA_SUBJECT_PROVIDER_KEY <apidocs/mongodb-driver-core/com/mongodb/MongoCredential.html#JAVA_SUBJECT_PROVIDER_KEY>`
160
160
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
163
169
164
- .. include:: /includes/fundamentals/code-snippets/auth-credentials-gssapi-properties.rst
170
+ .. include:: /includes/fundamentals/code-snippets/auth-credentials-gssapi-properties.rst
165
171
172
+ .. tab::
173
+ :tabid: JAVA_SUBJECT_KEY
174
+
175
+ .. include:: /includes/fundamentals/code-snippets/auth-credentials-gssapi-subject-key.rst
166
176
167
177
By default, the Java driver caches Kerberos tickets by ``MongoClient`` instance.
168
178
If your deployment needs to frequently create and destroy ``MongoClient`` instances,
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments