Claudio Miranda created CAMEL-16729:
---------------------------------------
Summary: MongoDB Authentication failed when using hosts query
parameter
Key: CAMEL-16729
URL: https://issues.apache.org/jira/browse/CAMEL-16729
Project: Camel
Issue Type: Bug
Components: camel-mongodb
Reporter: Claudio Miranda
I am using the mongodb url
{code}
mongodb://?collection=sales&database=sales&hosts=172.17.0.7%3A27017&operation=findAll&password=xxxxxx&username=myuser
{code}
When using the hosts parameter to authenticate to a mongodb server, it fails
with
{code:java}
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"}
{code}
mongo server shows
{code:java}
"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\""
{code}
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.
{code:java}
mongoClient = MongoClients.create(String.format("mongodb://%s%s", credentials,
hosts));
{code}
[https://github.com/apache/camel/blob/main/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java#L344]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)