Java 3.0 Driver and Authentication

590 views
Skip to first unread message

John Rinehart

unread,
Mar 12, 2015, 1:21:27 PM3/12/15
to mongod...@googlegroups.com
I would like to check if a user has provided proper credentials as soon as they create a MongoClient or database instance. Is there a way to do this with the Java 3.0 driver? The Java 2.13 driver had an authenticate() method in the DB class that I could use to perform such a function. Can I obtain similar functionality with the latest driver? If not, the user must attempt to perform an operation and, if the credentials are wrong, the operation times out after 30 seconds. This is unacceptable. I want to know immediately after connecting to mongod if the user is properly authenticated or not.

Thank you very much.

Jeff Yemin

unread,
Mar 12, 2015, 3:12:33 PM3/12/15
to mongod...@googlegroups.com
Hi John,

First of all, thank you for trying out the 3.0 Java driver and for reporting this issue.  

Currently, the closest you can get to your desired behavior is to lower the MongoClientOptions.serverSelectionTimeout property to an acceptable value and execute some arbitrary command to force a failure.   I created an example in this gist.  If lowering the serverSelectionTimeout for all operations is not acceptable, you can create a separate MongoClient with this lower value just for the purpose of checking connectivity.

Let us know if that works for you, and if not we'll open a Jira to see what changes we could make to the driver that will more completely address your concerns.

Regards,
Jeff


On Thu, Mar 12, 2015 at 12:21 PM, John Rinehart <johnricha...@gmail.com> wrote:
I would like to check if a user has provided proper credentials as soon as they create a MongoClient or database instance. Is there a way to do this with the Java 3.0 driver? The Java 2.13 driver had an authenticate() method in the DB class that I could use to perform such a function. Can I obtain similar functionality with the latest driver? If not, the user must attempt to perform an operation and, if the credentials are wrong, the operation times out after 30 seconds. This is unacceptable. I want to know immediately after connecting to mongod if the user is properly authenticated or not.

Thank you very much.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/3e051a69-c754-4f46-b1e1-0873d81e4df4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jérémy Béjanin

unread,
Mar 26, 2015, 4:43:48 PM3/26/15
to mongod...@googlegroups.com
Hi Jeff,

I am in John's group and replying for him. Sorry, we had not seen your message.

Changing the serverSelectionTimeout seems like a poor workaround... Is there a rationale for not having a function that returns the validity of the credentials entered?

If not, I believe that such a function should be added to the driver.

Thanks,
Jeremy

Jeff Yemin

unread,
Mar 27, 2015, 4:28:56 PM3/27/15
to mongod...@googlegroups.com
The rationale is that in the vast majority of use cases an incorrect authentication credential is a severe configuration error that requires human intervention to rectify, and not something that should be explicitly coded for.

That said, if you present a case for it in a Jira issue, we can take it under consideration.

Regards,
Jeff
Reply all
Reply to author
Forward
0 new messages