Skip to content

Commit 99c3b2a

Browse files
authored
(DOCSP-29261): Authentication (#80)
# Pull Request Info [PR Reviewing Guidelines](https://github.com/mongodb/docs-java/blob/master/REVIEWING.md) JIRA - https://jira.mongodb.org/browse/DOCSP-29261 Staging - https://docs-mongodbcom-staging.corp.mongodb.com/kotlin/docsworker-xlarge/docsp-29261-auth/fundamentals/auth/ # Updated Page Fundamentals > [Authentication Mechanisms page](https://www.mongodb.com/docs/drivers/java/sync/v4.9/fundamentals/auth/#mongodb-aws) ## Self-Review Checklist - [ ] Is this free of any warnings or errors in the RST? - [ ] Did you run a spell-check? - [ ] Did you run a grammar-check? - [ ] Are all the links working?
1 parent a1fe183 commit 99c3b2a

19 files changed

+605
-95
lines changed

examples/src/test/kotlin/AuthTest.kt

Lines changed: 408 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
val credential = MongoCredential.createAwsCredential("<awsKeyId>", "<awsSecretKey>".toCharArray())
2+
val connectionString = ConnectionString("mongodb://<atlasUri>/?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:<awsSessionToken>")
3+
4+
val settings = MongoClientSettings.builder()
5+
.applyConnectionString(connectionString)
6+
.credential(credential)
7+
.build()
8+
9+
val mongoClient = MongoClient.create(settings)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
val mongoClient =
2+
MongoClient.create("mongodb://<atlasUri>?authMechanism=MONGODB-AWS")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
val credential = MongoCredential.createAwsCredential("<awsKeyId>", "<awsSecretKey>".toCharArray())
2+
3+
val settings = MongoClientSettings.builder()
4+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
5+
builder.hosts(
6+
listOf(ServerAddress("<atlasUri>"))
7+
)
8+
}
9+
.credential(credential)
10+
.build()
11+
12+
val mongoClient = MongoClient.create(settings)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
val credential = MongoCredential.createAwsCredential("<awsKeyId>", "<awsSecretKey>".toCharArray())
2+
.withMechanismProperty("AWS_SESSION_TOKEN", "<awsSessionToken>")
3+
4+
val settings = MongoClientSettings.builder()
5+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
6+
builder.hosts(
7+
listOf(ServerAddress("<atlasUri>"))
8+
)
9+
}
10+
.credential(credential)
11+
.build()
12+
13+
val mongoClient = MongoClient.create(settings)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
val credential = MongoCredential.createAwsCredential(null, null)
2+
3+
val settings = MongoClientSettings.builder()
4+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
5+
builder.hosts(
6+
listOf(ServerAddress("<atlasUri>"))
7+
)
8+
}
9+
.credential(credential)
10+
.build()
11+
12+
val mongoClient = MongoClient.create(settings)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
val awsFreshCredentialSupplier: Supplier<AwsCredential> = Supplier {
2+
// Add your code here to fetch new credentials
3+
4+
// Return the new credentials
5+
AwsCredential("<awsKeyId>", "<awsSecretKey>", "<awsSessionToken>")
6+
}
7+
8+
val credential = MongoCredential.createAwsCredential("<awsKeyId>", "<awsSecretKey>".toCharArray())
9+
.withMechanismProperty(MongoCredential.AWS_CREDENTIAL_PROVIDER_KEY, awsFreshCredentialSupplier)
10+
11+
val settings = MongoClientSettings.builder()
12+
.applyToClusterSettings { builder ->
13+
builder.hosts(listOf(ServerAddress("<hostname>", "<port>")))
14+
}
15+
.credential(credential)
16+
.build()
17+
18+
val mongoClient = MongoClient.create(settings)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
val mongoClient =
2+
MongoClient.create("mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
val credential = MongoCredential.createCredential(
2+
"<username>", "<authenticationDb>", "<password>".toCharArray()
3+
)
4+
val settings = MongoClientSettings.builder()
5+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
6+
builder.hosts(
7+
listOf(ServerAddress("<hostname>", "<port>"))
8+
)
9+
}
10+
.credential(credential)
11+
.build()
12+
13+
val mongoClient = MongoClient.create(settings)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
val credential = MongoCredential.createScramSha1Credential(
2+
"<username>", "<authenticationDb>", "<password>".toCharArray()
3+
)
4+
val settings = MongoClientSettings.builder()
5+
.applyToClusterSettings { builder: ClusterSettings.Builder ->
6+
builder.hosts(
7+
listOf(ServerAddress("<hostname>", "<port>"))
8+
)
9+
}
10+
.credential(credential)
11+
.build()
12+
13+
val mongoClient = MongoClient.create(settings)

0 commit comments

Comments
 (0)