Skip to content

Commit 112b707

Browse files
committed
Ensure that MongoClient is not created with a null credentials list
Mongo’s 2.x driver allowed the credentials list to be null, however the 3.x driver requires an empty list instead. The behaviour of the 2.x driver is the same whether the client is created with a null credential list or an empty credential list. This commit aligns with the requirements of the 3.x driver by ensuring that we never pass in a null credential list when creating the client. Closes gh-4076
1 parent 6dadac1 commit 112b707

File tree

1 file changed

+5
-4
lines changed
  • spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo

1 file changed

+5
-4
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.autoconfigure.mongo;
1818

1919
import java.net.UnknownHostException;
20+
import java.util.ArrayList;
2021
import java.util.Arrays;
2122
import java.util.List;
2223

@@ -213,12 +214,12 @@ public MongoClient createMongoClient(MongoClientOptions options,
213214
if (options == null) {
214215
options = MongoClientOptions.builder().build();
215216
}
216-
List<MongoCredential> credentials = null;
217+
List<MongoCredential> credentials = new ArrayList<MongoCredential>();
217218
if (hasCustomCredentials()) {
218219
String database = this.authenticationDatabase == null
219220
? getMongoClientDatabase() : this.authenticationDatabase;
220-
credentials = Arrays.asList(MongoCredential
221-
.createCredential(this.username, database, this.password));
221+
credentials.add(MongoCredential.createCredential(this.username,
222+
database, this.password));
222223
}
223224
String host = this.host == null ? "localhost" : this.host;
224225
int port = determinePort(environment);

0 commit comments

Comments
 (0)