Set authSource in MongoDB Docker Compose connection details
When authentication credentials are provided in environment variables for the official MongoDB Docker image, the authentication source must also be set to the `admin` database. Fixes gh-35777
This commit is contained in:
@@ -30,6 +30,7 @@ import org.springframework.boot.docker.compose.service.connection.DockerComposeC
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class MongoDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<MongoConnectionDetails> {
|
||||
|
||||
@@ -73,6 +74,9 @@ class MongoDockerComposeConnectionDetailsFactory extends DockerComposeConnection
|
||||
builder.append(service.ports().get(MONGODB_PORT));
|
||||
builder.append("/");
|
||||
builder.append((environment.getDatabase() != null) ? environment.getDatabase() : "test");
|
||||
if (environment.getUsername() != null) {
|
||||
builder.append("?authSource=admin");
|
||||
}
|
||||
return new ConnectionString(builder.toString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user