Mongodb authentication using MongoCredential -
i have grails application in im using db.authenticate login page understand method has been deprecated , therefore upgrade application using mongocredential object authentication. however, unlike db.authenticate nicely returns boolean authentication done, mongocredential doesn't return boolean how can go accomplishing code replacement minimal headache. ideally, i'd derive kind of boolean tell me if authentication achieved. patience. im newbie mongodb.
this part of code need replace makes use of deprecated method "authenticate":
mongoclient mongoclient = new mongoclient("localhost", 27017) db db = mongoclient.getdb("twcdb"); def username = params.username def password = params.password //deprecated method being used in line below. boolean auth = db.authenticate(username, password.tochararray()) if (auth) { userloggedin = params.username render(contenttype: 'text/json') { [success: true, url: createlink(controller: 'admin', action: 'loggedin')] } } else { render(contenttype: 'text/json') { ["success": false, "message": 'login or password incorrect.'] }
edit: know answer must lie in testing property of mongoclient object somehow see if contains valid authenticated connection still stuck on how this. given knowingly feed mongoclient constructor bogus mongocredential, still creates object isn't null. betting on null test no joy. so, how replace deprecated db.authenticate?
Comments
Post a Comment