Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16729

MongoDB Authentication failed when using hosts query parameter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Bug
    • None
    • None
    • camel-mongodb
    • None
    • Unknown

    Description

      I am using the mongodb url

      mongodb://?collection=sales&database=sales&hosts=172.17.0.7%3A27017&operation=findAll&password=xxxxxx&username=myuser
      

      When using the hosts parameter to authenticate to a mongodb server, it fails with

      Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server 172.17.0.7:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
      

      mongo server shows

      "Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"myuser","authenticationDatabase":"admin","remote":"172.17.0.6:60642","extraInfo":{},"error":"UserNotFound: Could not find user \"myuser\" for db \"admin\""
      

      MongoDB connection string uses admin database when no authentication database is specified
      https://github.com/mongodb/mongo-java-driver/blob/r4.1.0/driver-core/src/main/com/mongodb/ConnectionString.java#L63
      https://github.com/mongodb/mongo-java-driver/blob/r4.1.0/driver-core/src/main/com/mongodb/ConnectionString.java#L729

      I think the database should be used in camel-mongodb authentication mechanism, at least I changed the code and it worked.

      mongoClient = MongoClients.create(String.format("mongodb://%s%s", credentials, hosts));
      

      https://github.com/apache/camel/blob/main/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java#L344

      Attachments

        Activity

          People

            Unassigned Unassigned
            claudio4j Claudio Miranda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: