Skip to content

Commit fd30f52

Browse files
committed
DOCSP-42514: kotlin user/pass placeholders (#169)
(cherry picked from commit 27a5c2a)
1 parent 6b4c10b commit fd30f52

27 files changed

+51
-50
lines changed

examples/src/test/kotlin/AuthTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal class AuthTest {
4747
fun defaultConnectionStringTest() = runBlocking {
4848
// :replace-start: {
4949
// "terms": {
50-
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>\""
50+
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>\""
5151
// }
5252
// }
5353
// :snippet-start: default-cred-string
@@ -70,7 +70,7 @@ internal class AuthTest {
7070
fun scramSha256ConnectionStringTest() = runBlocking {
7171
// :replace-start: {
7272
// "terms": {
73-
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-256\""
73+
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-256\""
7474
// }
7575
// }
7676
// :snippet-start: scram-sha-256-string
@@ -93,7 +93,7 @@ internal class AuthTest {
9393
fun scramSha1ConnectionStringTest() = runBlocking {
9494
// :replace-start: {
9595
// "terms": {
96-
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-1\""
96+
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-1\""
9797
// }
9898
// }
9999
// :snippet-start: scram-sha-1-string
@@ -116,7 +116,7 @@ internal class AuthTest {
116116
fun x509ConnectionStringTest() = runBlocking {
117117
// :replace-start: {
118118
// "terms": {
119-
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=MONGODB-X509&tls=true\""
119+
// "CONNECTION_URI_PLACEHOLDER": "\"mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=MONGODB-X509&tls=true\""
120120
// }
121121
// }
122122
// :snippet-start: x-509-string
@@ -137,8 +137,8 @@ internal class AuthTest {
137137

138138
// :replace-start: {
139139
// "terms": {
140-
// "USERNAME": "\"<username>\"",
141-
// "PASSWORD": "\"<password>\"",
140+
// "USERNAME": "\"<db_username>\"",
141+
// "PASSWORD": "\"<db_password>\"",
142142
// "AUTH_DB": "\"<authenticationDb>\"",
143143
// "HOSTNAME": "\"<hostname>\"",
144144
// "PORT": "\"<port>\""

examples/src/test/kotlin/EnterpriseAuthTest.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import javax.naming.Context
1313
import javax.security.auth.Subject
1414
import javax.security.auth.login.LoginContext
1515
import kotlin.test.Ignore
16+
1617
// :replace-start: {
1718
// "terms": {
1819
// "PORT": "<port>",
@@ -36,7 +37,7 @@ internal class EnterpriseAuthTest {
3637

3738
fun createGSSAPICred() = runBlocking {
3839
// :snippet-start: auth-creds-gssapi
39-
val credential = MongoCredential.createGSSAPICredential("<username>")
40+
val credential = MongoCredential.createGSSAPICredential("<Kerberos principal>")
4041

4142
val settings = MongoClientSettings.builder()
4243
.applyToClusterSettings { builder ->
@@ -51,7 +52,7 @@ internal class EnterpriseAuthTest {
5152

5253
fun serviceNameKey() = runBlocking {
5354
// :snippet-start: service-name-key
54-
val credential = MongoCredential.createGSSAPICredential("<username>")
55+
val credential = MongoCredential.createGSSAPICredential("<Kerberos principal>")
5556
.withMechanismProperty(MongoCredential.SERVICE_NAME_KEY, "myService")
5657
// :snippet-end:
5758
}
@@ -62,7 +63,7 @@ internal class EnterpriseAuthTest {
6263
loginContext.login()
6364
val subject: Subject = loginContext.subject
6465

65-
val credential = MongoCredential.createGSSAPICredential("<username>")
66+
val credential = MongoCredential.createGSSAPICredential("<Kerberos principal>")
6667
.withMechanismProperty(MongoCredential.JAVA_SUBJECT_KEY, subject)
6768
// :snippet-end:
6869
}
@@ -74,7 +75,7 @@ internal class EnterpriseAuthTest {
7475
val myLoginContext = "myContext"
7576
/* Login context defaults to "com.sun.security.jgss.krb5.initiate"
7677
if unspecified in KerberosSubjectProvider */
77-
val credential = MongoCredential.createGSSAPICredential("<username>")
78+
val credential = MongoCredential.createGSSAPICredential("<Kerberos principal>")
7879
.withMechanismProperty(
7980
MongoCredential.JAVA_SUBJECT_PROVIDER_KEY,
8081
KerberosSubjectProvider(myLoginContext)
@@ -84,7 +85,7 @@ internal class EnterpriseAuthTest {
8485

8586
fun ldapCredential() = runBlocking {
8687
// :snippet-start: ldap-mongo-credential
87-
val credential = MongoCredential.createPlainCredential("<username>", "$external", "<password>".toCharArray())
88+
val credential = MongoCredential.createPlainCredential("<LDAP username>", "$external", "<password>".toCharArray())
8889

8990
val settings = MongoClientSettings.builder()
9091
.applyToClusterSettings { builder ->
@@ -99,29 +100,29 @@ internal class EnterpriseAuthTest {
99100

100101
fun gssapiConnectionString() = runBlocking {
101102
// :snippet-start: gssapi-connection-string
102-
val connectionString = ConnectionString("<username>@<hostname>:<port>/?authSource=$external&authMechanism=GSSAPI")
103+
val connectionString = ConnectionString("<Kerberos principal>@<hostname>:<port>/?authSource=$external&authMechanism=GSSAPI")
103104
val mongoClient = MongoClient.create(connectionString)
104105
// :snippet-end:
105106
}
106107

107108
fun gssapiPropertiesConnectionString() = runBlocking {
108109
// :snippet-start: gssapi-properties-connection-string
109-
val connectionString = ConnectionString("<username>@<hostname>:<port>/?authSource=$external&authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:myService")
110+
val connectionString = ConnectionString("<Kerberos principal>@<hostname>:<port>/?authSource=$external&authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:myService")
110111
val mongoClient = MongoClient.create(connectionString)
111112
// :snippet-end:
112113
}
113114

114115
fun ldapConnectionString() = runBlocking {
115116
// :snippet-start: ldap-connection-string
116-
val connectionString = ConnectionString("<username>:<password>@<hostname>:<port>/?authSource=$external&authMechanism=PLAIN")
117+
val connectionString = ConnectionString("<LDAP username>:<password>@<hostname>:<port>/?authSource=$external&authMechanism=PLAIN")
117118
val mongoClient = MongoClient.create(connectionString)
118119
// :snippet-end:
119120
}
120121

121122
fun oidcAzureConnectionString() = runBlocking {
122123
// :snippet-start: oidc-azure-connection-string
123124
val connectionString = ConnectionString(
124-
"mongodb://<username>@<hostname>:<port>/?" +
125+
"mongodb://<OIDC principal>@<hostname>:<port>/?" +
125126
"?authMechanism=MONGODB-OIDC" +
126127
"&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:<percent-encoded audience>")
127128
val mongoClient = MongoClient.create(connectionString)
@@ -130,7 +131,7 @@ internal class EnterpriseAuthTest {
130131

131132
fun oidcAzureCredential() = runBlocking {
132133
// :snippet-start: oidc-azure-credential
133-
val credential = MongoCredential.createOidcCredential("<username>")
134+
val credential = MongoCredential.createOidcCredential("<OIDC principal>")
134135
.withMechanismProperty("ENVIRONMENT", "azure")
135136
.withMechanismProperty("TOKEN_RESOURCE", "<audience>")
136137

@@ -147,7 +148,7 @@ internal class EnterpriseAuthTest {
147148
fun oidcGCPConnectionString() = runBlocking {
148149
// :snippet-start: oidc-gcp-connection-string
149150
val connectionString = ConnectionString(
150-
"mongodb://<hostname>:<port>/?" +
151+
"mongodb://<OIDC principal>@<hostname>:<port>/?" +
151152
"authMechanism=MONGODB-OIDC" +
152153
"&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:<percent-encoded audience>")
153154
val mongoClient = MongoClient.create(connectionString)
@@ -156,7 +157,7 @@ internal class EnterpriseAuthTest {
156157

157158
fun oidcGCPCredential() = runBlocking {
158159
// :snippet-start: oidc-gcp-credential
159-
val credential = MongoCredential.createOidcCredential("<username>")
160+
val credential = MongoCredential.createOidcCredential("<OIDC principal>")
160161
.withMechanismProperty("ENVIRONMENT", "gcp")
161162
.withMechanismProperty("TOKEN_RESOURCE", "<audience>")
162163

examples/src/test/kotlin/MongoClientSettingsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import kotlin.test.Ignore
1616
// :replace-start: {
1717
// "terms": {
1818
// "uri": "\"<your connection string>\"",
19-
// "uriString": "\"mongodb+srv:/<username>:<password>@<hostname>:<port>?connectTimeoutMS(2000)\"",
19+
// "uriString": "\"mongodb+srv:/<db_username>:<db_password>@<hostname>:<port>?connectTimeoutMS(2000)\"",
2020
// "uriAcmeString": "\"mongodb+srv://host1.acme.com\""
2121
// }
2222
// }

source/connection-troubleshooting.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ database:
127127
:copyable: false
128128

129129
val mongoClient =
130-
MongoClient.create("mongodb://<username>:<password>@<hostname>:<port>/?authSource=users")
130+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=users")
131131

132132
.. _kotlin-error-sending-message:
133133

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
val mongoClient =
2-
MongoClient.create("mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>")
2+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>")

source/examples/generated/AuthTest.snippet.default-mongo-cred.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
val credential = MongoCredential.createCredential(
2-
"<username>", "<authenticationDb>", "<password>".toCharArray()
2+
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
33
)
44
val settings = MongoClientSettings.builder()
55
.applyToClusterSettings { builder: ClusterSettings.Builder ->

source/examples/generated/AuthTest.snippet.scram-sha-1-cred.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
val credential = MongoCredential.createScramSha1Credential(
2-
"<username>", "<authenticationDb>", "<password>".toCharArray()
2+
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
33
)
44
val settings = MongoClientSettings.builder()
55
.applyToClusterSettings { builder: ClusterSettings.Builder ->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
val mongoClient =
2-
MongoClient.create("mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-1")
2+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-1")

source/examples/generated/AuthTest.snippet.scram-sha-256-cred.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
val credential = MongoCredential.createScramSha256Credential(
2-
"<username>", "<authenticationDb>", "<password>".toCharArray()
2+
"<db_username>", "<authenticationDb>", "<db_password>".toCharArray()
33
)
44
val settings = MongoClientSettings.builder()
55
.applyToClusterSettings { builder: ClusterSettings.Builder ->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
val mongoClient =
2-
MongoClient.create("mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-256")
2+
MongoClient.create("mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-256")

0 commit comments

Comments
 (0)