Skip to content

Commit 91798da

Browse files
committed
JAVA-2656: In the reference documentation, remove examples of constructors or factory methods that take multiple credentials
1 parent e0368f1 commit 91798da

File tree

2 files changed

+17
-38
lines changed

2 files changed

+17
-38
lines changed

docs/reference/content/driver-async/tutorials/authentication.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,9 @@ An authentication credential is represented as an instance of the
2323
[`MongoCredential`]({{< apiref "com/mongodb/MongoCredential" >}}) class. The [`MongoCredential`]({{<apiref "com/mongodb/MongoCredential.html">}}) class includes static
2424
factory methods for each of the supported authentication mechanisms.
2525

26-
To specify a list of these instances, use the [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings" >}}) and pass as a parameter to the
27-
[`MongoClients.create()`]({{<apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.async.client.MongoClientSettings-">}}) method.
28-
29-
To specify a single `MongoCredential` instance, you can also use the [`ConnectionString`]({{< apiref "com/mongodb/ConnectionString" >}}) and pass to a
26+
You can also use the [`ConnectionString`]({{< apiref "com/mongodb/ConnectionString" >}}) and pass it to a
3027
[`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.ConnectionString-" >}}) method.
3128

32-
{{% note %}}
33-
34-
- You can also specify the credential with a string that specifies the connection URI and pass the string to the [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-java.lang.String-" >}}) method that takes the connection string as a parameter. For brevity, the tutorial omits the examples using the string.
35-
36-
- Given the flexibility of role-based access control in MongoDB, it is usually sufficient to authenticate with a single user, but, for completeness, the driver accepts a list of credentials.
37-
{{% /note %}}
38-
3929
## Default Authentication Mechanism
4030

4131
Starting in MongoDB 3.0, MongoDB changed the default authentication
@@ -60,7 +50,7 @@ ClusterSettings clusterSettings = ClusterSettings.builder()
6050
.hosts(asList(new ServerAddress("localhost"))).build();
6151
MongoClientSettings settings = MongoClientSettings.builder()
6252
.clusterSettings(clusterSettings)
63-
.credentialList(Arrays.asList(credential))
53+
.credential(credential)
6454
.build();
6555
MongoClient mongoClient = MongoClients.create(settings);
6656
```
@@ -74,7 +64,7 @@ MongoClient mongoClient = MongoClients.create(
7464
```
7565

7666
For challenge and response mechanisms, using the default authentication
77-
mechanism is the recommended approach as the approach will make
67+
mechanism is the recommended approach as it will make
7868
upgrading from MongoDB 2.6 to MongoDB 3.0 seamless, even after
7969
[upgrading the authentication schema]({{<docsref "release-notes/3.0-scram/">}}).
8070

@@ -92,7 +82,7 @@ ClusterSettings clusterSettings = ClusterSettings.builder()
9282
.hosts(asList(new ServerAddress("localhost"))).build();
9383
MongoClientSettings settings = MongoClientSettings.builder()
9484
.clusterSettings(clusterSettings)
95-
.credentialList(Arrays.asList(credential))
85+
.credential(credential)
9686
.build();
9787
MongoClient mongoClient = MongoClients.create(settings);
9888

@@ -121,7 +111,7 @@ ClusterSettings clusterSettings = ClusterSettings.builder()
121111
.hosts(asList(new ServerAddress("localhost"))).build();
122112
MongoClientSettings settings = MongoClientSettings.builder()
123113
.clusterSettings(clusterSettings)
124-
.credentialList(Arrays.asList(credential))
114+
.credential(credential)
125115
.build();
126116
MongoClient mongoClient = MongoClients.create(settings);
127117
```
@@ -161,7 +151,7 @@ EventLoopGroup eventLoopGroup = new NioEventLoopGroup(); // make sure applicati
161151

162152
MongoClientSettings settings = MongoClientSettings.builder()
163153
.clusterSettings(clusterSettings)
164-
.credentialList(Arrays.asList(credential))
154+
.credential(credential)
165155
.streamFactoryFactory(NettyStreamFactoryFactory.builder().eventLoopGroup(eventLoopGroup).build())
166156
.sslSettings(SslSettings.builder().enabled(true).build())
167157
.build();
@@ -196,7 +186,7 @@ ClusterSettings clusterSettings = ClusterSettings.builder()
196186
.hosts(asList(new ServerAddress("localhost"))).build();
197187
MongoClientSettings settings = MongoClientSettings.builder()
198188
.clusterSettings(clusterSettings)
199-
.credentialList(Arrays.asList(credential))
189+
.credential(credential)
200190
.build();
201191
MongoClient mongoClient = MongoClients.create(settings);
202192

@@ -270,7 +260,7 @@ ClusterSettings clusterSettings = ClusterSettings.builder()
270260
.hosts(asList(new ServerAddress("localhost"))).build();
271261
MongoClientSettings settings = MongoClientSettings.builder()
272262
.clusterSettings(clusterSettings)
273-
.credentialList(Arrays.asList(credential))
263+
.credential(credential)
274264
.build();
275265
MongoClient mongoClient = MongoClients.create(settings);
276266
```

docs/reference/content/driver/tutorials/authentication.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,8 @@ An authentication credential is represented as an instance of the
2323
[`MongoCredential`]({{<apiref "com/mongodb/MongoCredential.html">}}) class. The [`MongoCredential`]({{<apiref "com/mongodb/MongoCredential.html">}}) class includes static
2424
factory methods for each of the supported authentication mechanisms.
2525

26-
To specify a list of these instances, use one of
27-
several [`MongoClient()`]({{< apiref "com/mongodb/MongoClient.html">}}) constructors that take a parameter of type
28-
`List <MongoCredential>`.
29-
30-
To specify a single `MongoCredential`, you can also use a [`MongoClientURI`]({{< apiref "/com/mongodb/MongoClientURI.html">}}) and pass it to a [`MongoClient()`]({{< apiref "com/mongodb/MongoClient.html">}}) constructor that takes a `MongoClientURI` parameter.
31-
32-
{{% note %}}
33-
Given the flexibility of role-based access control in MongoDB, it is
34-
usually sufficient to authenticate with a single user, but, for
35-
completeness, the driver accepts a list of credentials.
36-
{{% /note %}}
26+
You can also use a [`MongoClientURI`]({{< apiref "/com/mongodb/MongoClientURI.html">}}) and pass it to a
27+
[`MongoClient()`]({{< apiref "com/mongodb/MongoClient.html">}}) constructor that takes a `MongoClientURI` parameter.
3728

3829
## Default Authentication Mechanism
3930

@@ -52,8 +43,7 @@ String database; // the name of the database in which the user is defined
5243
char[] password; // the password as a character array
5344
// ...
5445
MongoCredential credential = MongoCredential.createCredential(user, database, password);
55-
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017),
56-
Arrays.asList(credential));
46+
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017), credential);
5747
```
5848
Or use a connection string without explicitly specifying the
5949
authentication mechanism:
@@ -64,7 +54,7 @@ MongoClient mongoClient = new MongoClient(uri);
6454
```
6555

6656
For challenge and response mechanisms, using the default authentication
67-
mechanism is the recommended approach as the approach will make
57+
mechanism is the recommended approach as it will make
6858
upgrading from MongoDB 2.6 to MongoDB 3.0 seamless, even after
6959
[upgrading the authentication schema]({{<docsref "release-notes/3.0-scram/">}}).
7060

@@ -81,8 +71,7 @@ char[] password; // the password as a character array
8171
MongoCredential credential = MongoCredential.createScramSha1Credential(user,
8272
database,
8373
password);
84-
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017),
85-
Arrays.asList(credential));
74+
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017), credential);
8675
```
8776

8877
Or use a connection string that explicitly specifies the
@@ -105,8 +94,7 @@ char[] password; // the password as a character array
10594
MongoCredential credential = MongoCredential.createMongoCRCredential(user,
10695
database,
10796
password);
108-
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017),
109-
Arrays.asList(credential));
97+
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017), credential);
11098
```
11199
Or use a connection string that explicitly specifies the
112100
`authMechanism=MONGODB-CR`:
@@ -140,8 +128,7 @@ MongoCredential credential = MongoCredential.createMongoX509Credential(user);
140128
MongoClientOptions options = MongoClientOptions.builder().sslEnabled(true).build();
141129

142130

143-
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017),
144-
Arrays.asList(credential), options);
131+
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017), credential, options);
145132
```
146133

147134
Or use a connection string that explicitly specifies the
@@ -168,6 +155,7 @@ static factory method:
168155
String user; // The Kerberos user name, including the realm, e.g. "[email protected]"
169156
// ...
170157
MongoCredential credential = MongoCredential.createGSSAPICredential(user);
158+
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017), credential);
171159
```
172160
Or use a connection string that explicitly specifies the
173161
`authMechanism=GSSAPI`:
@@ -202,6 +190,7 @@ String user; // The LDAP user name
202190
char[] password; // The LDAP password
203191
// ...
204192
MongoCredential credential = MongoCredential.createPlainCredential(user, "$external", password);
193+
MongoClient mongoClient = new MongoClient(new ServerAddress("host1", 27017), credential);
205194
```
206195
Or use a connection string that explicitly specifies the
207196
`authMechanism=PLAIN`:

0 commit comments

Comments
 (0)