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

Commit

Permalink
Fix username & password logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudi Wijaya committed May 20, 2014
1 parent 71aacfc commit f9d5d5b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/com/jaspersoft/mongodb/connection/MongoDbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
public class MongoDbConnection implements Connection {
private MongoClient client;

private String mongoURI;
private final String mongoURI;
private final String username;
private final String password;
private String mongoDatabaseName;
Expand All @@ -81,9 +81,10 @@ public class MongoDbConnection implements Connection {
*/
public MongoDbConnection(String mongoURI, String username, String password)
throws JRException {
create(this.mongoURI = mongoURI);
this.mongoURI = mongoURI;
this.username = username;
this.password = password;
create(mongoURI);
setDatabase();
}

Expand All @@ -93,7 +94,7 @@ private void create(String mongoURI) throws JRException {
final MongoClientURI origMongoUri = new MongoClientURI(mongoURI);
String uriWithoutDbStr = "mongodb://";
final String theUsername = this.username != null ? this.username : origMongoUri.getUsername();
if (username != null || origMongoUri.getUsername() != null) {
if (theUsername != null) {
// MongoDB passwords are never empty
final String thePassword = this.password != null ? this.password : String.valueOf(origMongoUri.getPassword());
try {
Expand All @@ -108,7 +109,7 @@ private void create(String mongoURI) throws JRException {
if (i > 0) {
uriWithoutDbStr += ",";
}
uriWithoutDbStr += origMongoUri.getHosts();
uriWithoutDbStr += origMongoUri.getHosts().get(i);
}
uriWithoutDbStr += "/";

Expand Down

0 comments on commit f9d5d5b

Please sign in to comment.