Skip to content

Commit aba39d6

Browse files
committed
Merge pull request #11 from davejsmith/master
Mongo authentication
2 parents b58709d + a7eeeb0 commit aba39d6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: src/java/grails/plugins/mongodb/MongoHolderBean.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ public MongoHolderBean(GrailsApplication application) throws UnknownHostExceptio
6565
}
6666

6767
morphia = new Morphia();
68-
datastore = (DatastoreImpl)morphia.createDatastore(mongo, database);
68+
String username = getConfigVar(flatConfig,"mongodb.username",null);
69+
char[] password = getCharArray(getConfigVar(flatConfig, "mongodb.password", null));
70+
datastore = (DatastoreImpl)morphia.createDatastore(mongo, database,username,password);
6971

7072
// init ObjectFactory
7173
morphia.getMapper().getOptions().objectFactory = new MongoDomainObjectFactory(application);
7274
}
7375

76+
private char[] getCharArray(String configVar) {
77+
return configVar == null ? null : configVar.toCharArray();
78+
}
79+
7480
private String getConfigVar(Map config, String key, String defaultValue) {
7581
if (!config.containsKey(key)) {
7682
log.info("MongoDB configuration option missing: '" + key + "'. Using default value '" + defaultValue + "'.");

0 commit comments

Comments
 (0)