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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ceefour committed May 10, 2013
1 parent 26132f7 commit c426f5e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/com/jaspersoft/mongodb/connection/MongoDbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -62,8 +64,14 @@ public class MongoDbConnection implements Connection {

private DB mongoDatabase;

private final Logger logger = LoggerFactory.getLogger(MongoDbConnection.class);
private static final Logger logger = LoggerFactory.getLogger(MongoDbConnection.class);

protected static final List<Integer> AUTH_ERROR_CODES = Arrays.asList(new Integer[] {
16550, // not authorized for query on foo.system.namespaces
10057, // unauthorized db:admin ns:admin.system.users lock type:1 client:127.0.0.1
15845 // unauthorized
});

public MongoDbConnection(String mongoURI, String username, String password)
throws JRException {
create(this.mongoURI = mongoURI);
Expand Down Expand Up @@ -97,7 +105,7 @@ private void setDatabase() throws JRException {
} catch (Exception e) {
String message = e.getMessage();
if (e instanceof MongoException) {
if (message != null && message.startsWith("unauthorized db")) {
if (AUTH_ERROR_CODES.contains(((MongoException) e).getCode())) {
performaAuthentication = true;
} else {
logger.error("Cannot set database", e);
Expand Down

0 comments on commit c426f5e

Please sign in to comment.