DATADOC-142 changed constructor taking Mongo and database name to accept user credentials
This commit is contained in:
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.data.authentication.UserCredentials;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.DB;
|
||||
@@ -52,6 +53,12 @@ public class MongoDbFactoryBean implements MongoDbFactory, FactoryBean<MongoDbFa
|
||||
public MongoDbFactoryBean() {
|
||||
}
|
||||
|
||||
public MongoDbFactoryBean(Mongo mongo, String databaseName, UserCredentials userCredentials) throws DataAccessException {
|
||||
this(mongo, databaseName);
|
||||
this.username = userCredentials.getUsername();
|
||||
this.password = userCredentials.getPassword();
|
||||
}
|
||||
|
||||
public MongoDbFactoryBean(Mongo mongo, String databaseName) throws DataAccessException {
|
||||
Assert.notNull(mongo, "Mongo must not be null");
|
||||
Assert.hasText(databaseName, "Database name must not be empty");
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.springframework.core.convert.ConversionFailedException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.authentication.UserCredentials;
|
||||
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
||||
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
||||
import org.springframework.data.document.mongodb.index.IndexDefinition;
|
||||
@@ -125,15 +126,15 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used for a template configuration with a custom
|
||||
* {@link org.springframework.data.document.mongodb.convert.MongoConverter}
|
||||
* Constructor used for a template configuration with user credentials in the form of
|
||||
* {@link org.springframework.data.authentication.UserCredentials}
|
||||
*
|
||||
* @param mongo
|
||||
* @param databaseName
|
||||
* @param mongoConverter
|
||||
* @param userCredentials
|
||||
*/
|
||||
public MongoTemplate(Mongo mongo, String databaseName, MongoConverter mongoConverter) {
|
||||
this(new MongoDbFactoryBean(mongo, databaseName), mongoConverter, null, null);
|
||||
public MongoTemplate(Mongo mongo, String databaseName, UserCredentials userCredentials) {
|
||||
this(new MongoDbFactoryBean(mongo, databaseName, userCredentials));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.springframework.data.document.mongodb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
|
||||
@@ -14,6 +14,7 @@ Import-Template:
|
||||
org.springframework.transaction.*;version="[3.0.0, 4.0.0)",
|
||||
org.springframework.data.core.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.data.annotation.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.data.authentication.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.data.mapping.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.data.mapping.model.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.data.domain.*;version="[1.0.0, 2.0.0)",
|
||||
|
||||
Reference in New Issue
Block a user