Skip to content

Commit 8956505

Browse files
committed
back to standard form
1 parent ecd78d8 commit 8956505

File tree

2 files changed

+36
-50
lines changed

2 files changed

+36
-50
lines changed

source/includes/security/authentication.kt

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,69 @@ import org.bson.Document
66
// SCRAM Authentication
77
// start-default-cred-string
88
val mongoClient =
9-
MongoClient.create("mongodb+srv://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>")
9+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>")
1010
// end-default-cred-string
1111

1212
// start-default-mongo-cred
1313
val credential = MongoCredential.createCredential(
1414
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
1515
)
1616

17+
val credential = MongoCredential.createCredential(
18+
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
19+
)
1720
val settings = MongoClientSettings.builder()
18-
.applyToClusterSettings { builder: ClusterSettings.Builder ->
19-
builder.srvHost("<hostname>")
20-
}
21-
.credential(credential)
22-
.applyToSslSettings { builder ->
23-
builder.enabled(true)
24-
}
25-
.build()
21+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
22+
builder.hosts(
23+
listOf(ServerAddress("<hostname>", "<port>"))
24+
)
25+
}
26+
.credential(credential)
27+
.build()
2628

2729
val mongoClient = MongoClient.create(settings)
2830
// end-default-mongo-cred
2931

3032
// start-scramsha256-cred-string
3133
val mongoClient =
32-
MongoClient.create("mongodb+srv://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-256")
34+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-256")
3335
// end-scramsha256-cred-string
3436

3537
// start-scramsha256-mongo-cred
3638
val credential = MongoCredential.createScramSha256Credential(
37-
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
38-
)
39-
39+
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
40+
)
4041
val settings = MongoClientSettings.builder()
41-
.applyToClusterSettings { builder: ClusterSettings.Builder ->
42-
builder.srvHost("<hostname>")
43-
}
44-
.applyToSslSettings { builder ->
45-
builder.enabled(true)
46-
}
47-
.credential(credential)
48-
.build()
42+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
43+
builder.hosts(
44+
listOf(ServerAddress("<hostname>", "<port>"))
45+
)
46+
}
47+
.credential(credential)
48+
.build()
4949

5050
val mongoClient = MongoClient.create(settings)
5151
// end-scramsha256-mongo-cred
5252

5353
// start-scramsha1-cred-string
5454
val mongoClient =
55-
MongoClient.create("mongodb+srv://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-1")
55+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-1")
5656
// end-scramsha1-cred-string
5757

5858
// start-scramsha1-mongo-cred
5959
val credential = MongoCredential.createScramSha1Credential(
60-
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
61-
)
62-
60+
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
61+
)
6362
val settings = MongoClientSettings.builder()
64-
.applyToClusterSettings { builder: ClusterSettings.Builder ->
65-
builder.srvHost("<hostname>")
66-
}
67-
.applyToSslSettings { builder ->
68-
builder.enabled(true)
69-
}
70-
.credential(credential)
71-
.build()
72-
73-
val mongoClient = MongoClient.create(settings)
63+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
64+
builder.hosts(
65+
listOf(ServerAddress("<hostname>", "<port>"))
66+
)
67+
}
68+
.credential(credential)
69+
.build()
70+
71+
val mongoClient = MongoClient.create(settings)
7472
// end-scramsha1-mongo-cred
7573

7674
// AWS Authentication

source/security/authentication.txt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ mechanism:
8585

8686
To specify the default authentication mechanism by using the
8787
``MongoCredential`` class, use the ``createCredential()`` method.
88-
Also, enable TLS by calling the
89-
`applyToSslSettings() <{+core-api+}/com/mongodb/MongoClientSettings.Builder.html#applyToSslSettings(com.mongodb.Block)>`__
90-
method and setting the ``enabled`` property to ``true`` in the
91-
`SslSettings.Builder <{+core-api+}/com/mongodb/connection/SslSettings.Builder.html>`__
92-
block. Your code to instantiate a ``MongoClient`` should resemble the following:
88+
Your code to instantiate a ``MongoClient`` should resemble the following:
9389

9490
.. literalinclude:: /includes/security/authentication.kt
9591
:language: kotlin
@@ -152,11 +148,7 @@ mechanism:
152148
To specify the default authentication mechanism by using the
153149
``MongoCredential`` class, use the
154150
`createScramSha256Credential() <{+core-api+}/com/mongodb/MongoCredential.html#createScramSha256Credential(java.lang.String,java.lang.String,char[])>`__
155-
method. Also, enable TLS by calling the
156-
`applyToSslSettings() <{+core-api+}/com/mongodb/MongoClientSettings.Builder.html#applyToSslSettings(com.mongodb.Block)>`__
157-
method and setting the ``enabled`` property to ``true`` in the
158-
`SslSettings.Builder <{+core-api+}/com/mongodb/connection/SslSettings.Builder.html>`__
159-
block. Your code to instantiate a ``MongoClient`` should resemble the following:
151+
method. Your code to instantiate a ``MongoClient`` should resemble the following:
160152

161153
.. literalinclude:: /includes/security/authentication.kt
162154
:language: kotlin
@@ -215,11 +207,7 @@ mechanism:
215207
To specify the default authentication mechanism by using the
216208
``MongoCredential`` class, use the
217209
`createScramSha1Credential() <{+core-api+}/com/mongodb/MongoCredential.html#createScramSha1Credential(java.lang.String,java.lang.String,char[])>`__
218-
method. Also, enable TLS by calling the
219-
`applyToSslSettings() <{+core-api+}/com/mongodb/MongoClientSettings.Builder.html#applyToSslSettings(com.mongodb.Block)>`__
220-
method and setting the ``enabled`` property to ``true`` in the
221-
`SslSettings.Builder <{+core-api+}/com/mongodb/connection/SslSettings.Builder.html>`__
222-
block. Your code to instantiate a ``MongoClient`` should resemble the following:
210+
method. Your code to instantiate a ``MongoClient`` should resemble the following:
223211

224212
.. literalinclude:: /includes/security/authentication.kt
225213
:language: kotlin

0 commit comments

Comments
 (0)