无法从ReactiveMongo Play应用访问经过身份验证的MongoDB集合 [英] Cannot access authenticated MongoDB collection from ReactiveMongo Play app

查看:84
本文介绍了无法从ReactiveMongo Play应用访问经过身份验证的MongoDB集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台MongoDB服务器,在其中启用了身份验证并创建了具有DB特定权限的用户.此应用程序的用户定义如下所示,即geoAdmin拥有相关数据库的read,readWrite和dbOwner权限:

I have a MongoDB server where I have enabled authentication and created users with DB-specific permissions. The user for this app is defined as shown below i.e. geoAdmin has read, readWrite and dbOwner permissions for the relevant database:

MongoDB shell version: 3.0.0
connecting to: 192.168.2.89/test
> use geo_db
switched to db geo_db
> db.getUser("geoAdmin")
{
    "_id" : "geo_db.geoAdmin",
    "user" : "geoAdmin",
    "db" : "geo_db",
    "roles" : [
        {
            "role" : "read",
            "db" : "geo_db"
        },
        {
            "role" : "dbOwner",
            "db" : "geo_db"
        },
        {
            "role" : "readWrite",
            "db" : "geo_db"
        }
    ]
}

以下查询正常运行,即从我的本地mongo客户端连接到远程服务器:

The following query works OK i.e. connecting to the remote server from my local mongo client:

mint:~ $ mongo 192.168.2.89:27017 -u geoAdmin -p secret --authenticationDatabase geo_db
MongoDB shell version: 3.0.0
connecting to: 192.168.2.89/test
> use geo_db
switched to db geo_db
>  db.LAD_DEC_2013_GB_BFE.findOne({},{'properties.LAD13NM':1})
{
    "_id" : ObjectId("54ffe2824f0787ec1293017f"),
    "properties" : {
        "LAD13NM" : "Hartlepool"
    }
}

然后,我从同一本地客户端上的ReactiveMongo Play应用程序连接到同一远程主机,并在应用程序配置文件中使用以下URL:

I then connect to the same remote host from a ReactiveMongo Play app on the same local client, with this URL in the app config file:

# ReactiveMongo
mongodb.uri = "mongodb://geoAdmin:secret@192.168.2.89:27017/geo_db"

但是当我的应用尝试从同一集合中读取数据时,我收到MongoDB"code = 13"错误:

But when my app tries to read from the same collection, I get a MongoDB "code = 13" error:

[DetailedDatabaseException: DatabaseException['not authorized for query on geo_db.LAD_DEC_2013_GB_BFE' (code = 13)]]

如果我连接到未启用身份验证的本地MongoDB,则该应用程序可以正常运行.

The app works fine if I connect to a local MongoDB which does not have authentication enabled.

任何想法在这里可能出什么问题吗?

Any ideas what might be going wrong here?

推荐答案

ReactiveMongo 0.11.7.play23 支持 mongo 3.0身份验证协议,但仍使用旧的作为默认值.

ReactiveMongo 0.11.7.play23 is supporting mongo 3.0 auth-protocols, but is still using the old as default.

使用ReactiveMongo 0.11.7.play23 -plugin,您可以通过在mongodb.uri的末尾添加?authMode = scram-sha1"来使其通过mongo 3.0进行身份验证. 例如:

With ReactiveMongo 0.11.7.play23 -plugin, you can make it authenticate with mongo 3.0, by adding "?authMode=scram-sha1" to the end of your mongodb.uri. E.g.:

mongodb.uri = "mongodb://geoAdmin:secret@192.168.2.89:27017/geo_db?authMode=scram-sha1"

这篇关于无法从ReactiveMongo Play应用访问经过身份验证的MongoDB集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆