从Mule连接到Mongo Atlas时的身份验证错误

时间:2017-02-01 21:44:54

标签: mongodb mule anypoint-studio

我正在使用Anypoint Studio 6.1和Mule 3.8.1,我正在尝试配置Anypoint Mongo Connector v4.1以连接到Mongo Atlas(mongodb v3.4)。

我可以通过mongo shell连接但是当我向mongo连接器配置添加相同的细节时,我收到以下错误:

org.mule.api.ConnectionException: Authentication failed
org.mule.api.ConnectionException: Authentication failed
    at org.mule.modules.mongo.Config.testConnect(Config.java:190)
    at org.mule.modules.mongo.generated.connectivity.ConfigMongoCloudConnectorAdapter.test(ConfigMongoCloudConnectorAdapter.java:27)
    at org.mule.modules.mongo.generated.connectivity.MongoCloudConnectorConfigConnectionManagementConnectionManager.test(MongoCloudConnectorConfigConnectionManagementConnectionManager.java:442)
    at org.mule.tooling.metadata.api.utils.ConnectionTester.internalTestConnection(ConnectionTester.java:88)
    at org.mule.tooling.metadata.api.utils.ConnectionTester.testConnectionFor(ConnectionTester.java:113)
    at org.mule.tooling.messageflow.action.TestConnectorConnectionFromMuleConfigAction$1$1$1$1.call(TestConnectorConnectionFromMuleConfigAction.java:68)
    at org.mule.tooling.messageflow.action.TestConnectorConnectionFromMuleConfigAction$1$1$1$1.call(TestConnectorConnectionFromMuleConfigAction.java:1)
    at org.mule.tooling.utils.SilentRunner.run(SilentRunner.java:25)
    at org.mule.tooling.core.StudioDesignContextRunner.runSilentWithMuleProject(StudioDesignContextRunner.java:17)
    at org.mule.tooling.core.StudioDesignContextRunner.runSilentWithMuleProject(StudioDesignContextRunner.java:37)
    at org.mule.tooling.messageflow.action.TestConnectorConnectionFromMuleConfigAction$1$1$1.run(TestConnectorConnectionFromMuleConfigAction.java:65)
    at java.lang.Thread.run(Unknown Source)
Caused by: com.mongodb.MongoTimeoutException: Timed out after 5000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=shard0.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='admin-user', source='mydatabase', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server shard0.mongodb.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}, {address=shard1.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='admin-user', source='myDatabase', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server shard1.mongodb.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}, {address=shard2.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='admin-user', source='myDatabase', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server shard2.mongodb.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]
    at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)
    at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
    at com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:89)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:84)
    at com.mongodb.operation.CommandReadOperation.execute(CommandReadOperation.java:55)
    at com.mongodb.Mongo.execute(Mongo.java:773)
    at com.mongodb.Mongo$2.execute(Mongo.java:760)
    at com.mongodb.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:130)
    at com.mongodb.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:124)
    at com.mongodb.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:114)
    at org.mule.modules.mongo.api.MongoClientImpl.executeCommand(MongoClientImpl.java:321)
    at org.mule.modules.mongo.api.MongoClientImpl.isAlive(MongoClientImpl.java:335)
    at org.mule.modules.mongo.Config.testConnect(Config.java:183)
    ... 11 more

  java.lang.Throwable: org.mule.api.ConnectionException: Authentication failed
    at org.mule.modules.mongo.Config.testConnect(Config.java:190)
    at org.mule.modules.mongo.generated.connectivity.ConfigMongoCloudConnectorAdapter.test(ConfigMongoCloudConnectorAdapter.java:27)
    at org.mule.modules.mongo.generated.connectivity.MongoCloudConnectorConfigConnectionManagementConnectionManager.test(MongoCloudConnectorConfigConnectionManagementConnectionManager.java:442)
    at org.mule.tooling.metadata.api.utils.ConnectionTester.internalTestConnection(ConnectionTester.java:88)
    at org.mule.tooling.metadata.api.utils.ConnectionTester.testConnectionFor(ConnectionTester.java:113)
    at org.mule.tooling.messageflow.action.TestConnectorConnectionFromMuleConfigAction$1$1$1$1.call(TestConnectorConnectionFromMuleConfigAction.java:68)
    at org.mule.tooling.messageflow.action.TestConnectorConnectionFromMuleConfigAction$1$1$1$1.call(TestConnectorConnectionFromMuleConfigAction.java:1)
    at org.mule.tooling.utils.SilentRunner.run(SilentRunner.java:25)
    at org.mule.tooling.core.StudioDesignContextRunner.runSilentWithMuleProject(StudioDesignContextRunner.java:17)
    at org.mule.tooling.core.StudioDesignContextRunner.runSilentWithMuleProject(StudioDesignContextRunner.java:37)
    at org.mule.tooling.messageflow.action.TestConnectorConnectionFromMuleConfigAction$1$1$1.run(TestConnectorConnectionFromMuleConfigAction.java:65)
    at java.lang.Thread.run(Unknown Source)

Mongo Mule Connector配置(失败,错误如上)

<mongo:config name="Mongo_DB__Configuration" username="admin-user" password="pass1234" database="myDatabase" host="shard0.mongodb.net:27017, shard1.mongodb.net:27017, shard2.mongodb.net:27017" doc:name="Mongo DB: Configuration" ssl="true"/>

Mongo Shell连接字符串(有效)

mongo "mongodb://shard0.mongodb.net:27017,shard1.mongodb.net:27017,shard2.mongodb.net:27017/myDatabase?replicaSet=shard0" --ssl --username admin-user --password pass1234

谢谢

1 个答案:

答案 0 :(得分:0)

确保您在连接字符串中声明authenticationDBadmin。您的日志输出中似乎缺少这个。