Jaspersoft Studio MongoDB 连接验证失败

Jaspersoft Studio MongoDB connection authentication failure

我正在尝试将 Jaspersoft Studio 6.2.0 连接到托管在 MongoLab 上的 MongoDB 数据库(mongod 版本:3.0.7)。

使用连接 URI:

 mongodb://ds012345-a0.mongolab.com:12345,ds012345-a1.mongolab.com:12345/mydb?replicaSet=rs-ds012345

我在测试适配器时遇到以下异常:

net.sf.jasperreports.engine.JRException: com.mongodb.CommandFailureException: { "serverUsed" : "ds012345-a0.mongolab.com:12345" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
    at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:162)
    at com.jaspersoft.mongodb.adapter.MongoDbDataAdapterService.test(MongoDbDataAdapterService.java:93)
    at com.jaspersoft.studio.data.wizard.AbstractDataAdapterWizard.runOperations(AbstractDataAdapterWizard.java:162)
    at com.jaspersoft.studio.utils.jobs.CheckedRunnableWithProgress.run(CheckedRunnableWithProgress.java:59)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "ds012345-a0.mongolab.com:12345" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
    at com.mongodb.CommandResult.getException(CommandResult.java:76)
    at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
    at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:652)
    at com.mongodb.DBPort.authenticate(DBPort.java:364)
    at com.mongodb.DBPort.checkAuth(DBPort.java:375)
    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:291)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:271)
    at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
    at com.mongodb.DB.command(DB.java:317)
    at com.mongodb.DB.command(DB.java:296)
    at com.mongodb.DB.command(DB.java:371)
    at com.mongodb.DB.command(DB.java:243)
    at com.mongodb.DB.command(DB.java:397)
    at com.jaspersoft.mongodb.connection.MongoDbConnection.test(MongoDbConnection.java:158)
    ... 4 more

问题出在 SCRAM-SHA-1 authentication mechanism added in MongoDB version 3.0

如本JasperReports Server issue所述,解决方案是通过替换文件来更新MongoDB Java驱动程序:

Jaspersoft Studio-6.2.0.final\configuration\org.eclipse.osgi[=10=]\.cp\lib\mongo-java-driver-2.12.3.jar

与此处找到的那个:https://github.com/mongodb/mongo-java-driver/releases/download/r2.13.2/mongo-java-driver-2.13.2.jar

使用 URI 中的凭据,连接成功。