grails - Issue with mongodb user authentication -
i trying connect server-1 mongo server running in other sever server-2 grails app running in server-1. have given external configuration this.
grails { mongo { host = "<server-2>-host" port = 27017 username = "myapp" password = "myapp" databasename = "myapp" options { autoconnectretry = true connecttimeout = 3000 } } }
and in server-2 i've created myapp db , same user , credentials
use myapp db.createuser( { "user" : "myapp", "pwd": "myapp", "roles" : [] }, { w: "majority" , wtimeout: 5000 } )
and able see users list below
> db.getusers() [ { "_id" : "myapp.myapp", "user" : "myapp", "db" : "myapp", "roles" : [ ] } ]
mongo configuration contains "noauth=true", , server-1, i'm able connect server-2 mongo using below command
mongo server-2-host:27017/myapp -u myapp -p myapp
but when try connect server-1 grails application, giving below error
| error error executing script loadvars: org.springframework.beans.factory.beancreationexception: error creating bean name 'transactionmanagerpostprocessor': initialization of bean failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'transactionmanager': cannot resolve reference bean 'mongotransactionmanager' while setting constructor argument key [1]; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'mongotransactionmanager': cannot resolve reference bean 'mongodatastore' while setting bean property 'datastore'; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'mongodatastore': factorybean threw exception on object creation; nested exception org.springframework.data.mongodb.cannotgetmongodbconnectionexception: failed authenticate database [myapp], username = [myapp], password = [m***p]
my mongod.conf file
# mongod.conf logpath=/var/log/mongodb/mongod.log logappend=true fork=true #port=27017 dbpath=/var/lib/mongo pidfilepath=/var/run/mongodb/mongod.pid # listen local interface only. comment out listen on interfaces. #bind_ip=127.0.0.1 # nojournal=true #cpu=true #noauth=false auth=true
am missing here?
looks mongodb server running , listening not able authenticate.
the first problem i'm seeing that, mentioned grails application running on 1st server while mongodb server on 2nd, host
in datasource.groovy
configuration configured connect 1st host, not 2nd. in example or code connecting 1st server (which wrong)? please verify it.
the second problem might way adding user database name myapp
. please follow these steps , try again after connecting:
1) login mongodb instance on 2nd host: mongo
2) use database use myapp
3) verify don not have user named myapp
running db.dropuser("myapp")
4) add user:
db.createuser({ user: "myapp", pwd: "myapp", roles: [ "readwrite", "dbadmin" ] });
now connect grails application.
update
if using mongodb 3.x , grails 2.5.x or 2.4.x should problem of authentication failure. forgot tell problem.
grails somehow shipping older version of java driver i.e. 2.12.3
, support mongodb 3, require minimum 2.13.x
of java driver. also, 3.0 java driver not required upgrade mongodb 3.0. 2.13.0 release minimum required full compatibility mongodb 3.0.
https://github.com/mongodb/mongo-java-driver/releases/tag/r3.0.0
so, in buildconfig.groovy
add dependency
:
dependencies { compile "org.mongodb:mongo-java-driver:2.13.1" }
also, if using grails mongeez plugin, exclude java driver there:
compile (":mongeez:0.2.3") { excludes("mongo-java-driver") }
i'll create ticket in grails. hope helps!
Comments
Post a Comment