Skip to content

Instantly share code, notes, and snippets.

@gscheibel
Created July 25, 2012 11:45
Show Gist options
  • Save gscheibel/3175704 to your computer and use it in GitHub Desktop.
Save gscheibel/3175704 to your computer and use it in GitHub Desktop.
private DB extractDatabase() {
Object dbNameObject = this.cfg.get( Environment.MONGODB_DATABASE );
if ( dbNameObject == null ) {
throw log.mongoDbNameMissing();
}
String dbName = (String) dbNameObject;
log.connectingToMongoDatabase( dbName );
if ( !this.mongo.getDatabaseNames().contains( dbName ) ) {
log.creatingDatabase( dbName );
}
Object usernameObject = this.cfg.get( Environment.MONGODB_USERNAME );
Object passwordObject = this.cfg.get( Environment.MONGODB_PASSWORD );
DB db = this.mongo.getDB( dbName );
if ( usernameObject != null && passwordObject != null ) {
String username = usernameObject.toString();
String password = passwordObject.toString();
boolean isAuth = db.authenticate( username, password.toCharArray() );
if(!isAuth){
log.authenticationfail(username, password);
}
}
return db;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment