Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

authDbName param #59

Merged
merged 7 commits into from Jan 13, 2014
20 changes: 18 additions & 2 deletions src/main/java/com/novemberain/quartz/mongodb/MongoDBJobStore.java
Expand Up @@ -45,6 +45,7 @@ public class MongoDBJobStore implements JobStore, Constants {
private Mongo mongo;
private String collectionPrefix = "quartz_";
private String dbName;
private String authDbName;
private DBCollection jobCollection;
private DBCollection triggerCollection;
private DBCollection calendarCollection;
Expand Down Expand Up @@ -852,7 +853,15 @@ private DB selectDatabase(Mongo mongo) {
// But we would be insane not to override this when writing lock records. LB.
db.setWriteConcern(WriteConcern.JOURNALED);
if (username != null) {
db.authenticate(username, password.toCharArray());
if(authDbName != null) {
// authentificating to db which gives access to all other dbs (role - readWriteAnyDatabase)
// by default in mongo it should be "admin"
DB authDb = mongo.getDB(authDbName);
authDb.authenticate(username, password.toCharArray());
} else {
db.authenticate(username, password.toCharArray());
}

}
return db;
}
Expand Down Expand Up @@ -1405,5 +1414,12 @@ public void setMongoOptionThreadsAllowedToBlockForConnectionMultiplier(int threa
public void setMongoOptionSocketKeepAlive(boolean mongoOptionSocketKeepAlive) {
this.mongoOptionSocketKeepAlive = mongoOptionSocketKeepAlive;
}


public String getAuthDbName() {
return authDbName;
}

public void setAuthDbName(String authDbName) {
this.authDbName = authDbName;
}
}