-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Authentication
-
None
I was attempting to perform a db.auth() or authenticate command through the driver 3.6.1 and got the following error.
Error: com.mongodb.MongoCommandException: Command failed with error 2: 'Challenge-response authentication using getnonce and authenticate commands is disabled.' on server maas-gt-d4-u0038.nam.nsroot.net:37017. The full response is { "ok" : 0.0, "errmsg" : "Challenge-response authentication using getnonce and authenticate commands is disabled.", "code" : 2, "codeName" : "BadValue" }
My Code
mongodb://<user>:<pwd>@maas-gt-d4-u0038.nam.nsroot.net:37017/?ssl=true&authSource=admin&sslInvalidHostNameAllowed=true&authMechanism=SCRAM-SHA-1
MongoDatabase mongoDB = mongoClient.getDatabase(databaseName);
Document doc = mongoDB.runCommand(NativeAuthenticationHelper.getNonceCommand());
BsonDocument auth = NativeAuthenticationHelper.getAuthCommand(<my user>, <my password>.toCharArray(), doc.getString("nonce"));
Document res = mongoDB.runCommand(auth);
I am able to connect to the MongoDB instance with that string from my local Tomcat application. SCRAM-SHA-1 is being used.
Thanks & Regards,
Preeti Gupta