原文出自:http://www.mkyong.com/mongodb/mongodb-authentication-example/
返回目录:http://ysj5125094.iteye.com/blog/2192754
MongoDB Authentication Example
This guide shows you how to enable authentication in MongoDB. The authentication is disabled by default. To configure it, you must first add a user to the “admin” database.
译:本指南将告诉你,如果在MongoDB中启用身份认证。 默认情况下身份认证是禁用的。如果想要配置他,首先必须把该用户添加到 "admin" 数据库。
> show dbs admin #add single user to this database testdb
Note
Users with normal access in “admin” database, HAVE read and write access to all the other databases. Users with read only access to the “admin” database HAVE only read to all databases.
译:注,用户如果有一般管理员数据库权限,那就有读写访问所有其他的数据库的权利。如果用户只能访问管理员数据库,那他对其他数据库只有读权限。
P.S This example is using MongoDB version 2.2.3
译:这个例子使用的是MongoDB 2.2.3版本。
Authentication example
See a full example to add a “admin” user to the admin database, and a normal user to the “testdb” database, and how to perform the authentication.
译:看下面一个完整的实例,添加一个"admin"用户到 admin 数据库,普通用户操作"testdb"数据库,以及如何进行身份认证。
Terminal 1 – Start MongoDB in secure mode, authentication is required.
译:终端1 - 在安全模式下启动MongoDB,需要认证。
$mongod --auth
Terminal 2 – MongoDB client, see comment “#” for self-explanatory.
译:终端2 - MongoDB客户端,以#开头的是注释部分。
$ mongo MongoDB shell version: 2.2.3 connecting to: test > use admin #1. connect to the "admin" database. switched to db admin > db.addUser("admin","password") #2. add a user "admin" to the admin database. { "user" : "admin", "readOnly" : false, "pwd" : "90f500568434c37b61c8c1ce05fdf3ae", "_id" : ObjectId("513af8cac115e7a6b4bcceb9") } addUser succeeded, but cannot wait for replication since we no longer have auth > use testdb #3. connect to the "testdb" database. switched to db testdb > show collections #4. now, read and write need authentication Sat Mar 9 16:54:57 uncaught exception: error: { "$err" : "unauthorized db:testdb ns:testdb.system.namespaces lock type:0 client:127.0.0.1", "code" : 10057 } > use admin #5. connect back to the "admin" database. switched to db admin > db.auth("admin","password") #6. performs authentication, 1 means succeed, 0 means failed 1 > use testdb #7. connect to the "testdb" database. switched to db testdb > show collections #8. no problem, it shows all collections system.indexes user > db.addUser("testdb","password") #9. add another user "testdb" to the "testdb" database. { "user" : "testdb", "readOnly" : false, "pwd" : "b9ff75cbf18bd98d8554efec12c72090", "_id" : ObjectId("513af934c115e7a6b4bcceba") } > show collections system.indexes system.users #10. All users' data are stored in this system.users collection. user > db.system.users.find() { "_id" : ObjectId("513af934c115e7a6b4bcceba"), "user" : "testdb", "readOnly" : false, "pwd" : "b9ff75cbf18bd98d8554efec12c72090" } >
Done.
References
相关推荐
本项目创建的购物车提供了所需的大部分功能,但是省略了诸如身份验证和错误处理等细节,只是单纯地设计到与购物车有关的东西,其余一概省略。 例如本例子采用一个userid(用户ID)被硬编码为customerA的用户...
这是一个演示示例,它使用 Morphia API 演示了针对 mongoDB 的 Spring 身份验证 此示例使用带有 Gradle 插件的 STS IDE 开发。 要运行该应用程序,请按照下列步骤操作: 1-创建名为“authDB”的 MongodDB 数据库2-...
关于认证 用 Go 编写的身份验证、授权和用户管理服务该项目为您提供了两种使用方式: 用于身份验证、授权和用户管理的 ,带有一些客户端库,以便与 REST 服务器进行轻松通信。 AngualrJS 客户端。 一个抽象接口...
它使用Flask-Login进行身份验证,使用Flask-Pymongo进行数据库连接,使用Flask-Bcrypt进行密码哈希处理,并使用Flask-Talisman进行安全保护。 前端使用Bootstrap进行样式设置。 该应用程序具有通过电子邮件进行用户...
使用MongoDB表达Boillerplate RestfullApi 核心堆栈 Node.js - Express - Mongo数据库-https : 猫鼬-https : nodemon - //www.npmjs.com/package/nodemon pm2 - //www.npmjs.com/package/pm2 特征 使用jwt进行...
这是一个基于node实现的一个简单登入例子,对于刚上手node想进一步了解,前端页面请求到服务层,路由处理,数据库操作,返回结果到页面这整个过程的同学比较有用。这个例子基于github上两个项目
授权商店 cloudpipe 的本地管理帐户管理 这是将帐户数据存储在 MongoDB 中的的默认... 一旦它启动并运行,您就可以使用curl与身份验证 API 进行交互。 这里有一些例子: # If you're on a Mac and using boot2dock
Nestjs-BFF概述 状态该库当前处于“冰冻状态”,目前不再处于主动维护状态。 但是,它仍然可以作为有用的参考,以供他人参考如何围绕NestJS平台构建可用于生产环境的应用程序。 另外,在将来某个不确定的时间点,库...
这个怎么做的:使用的技术: -HTML,CSS,JavaScript,Express,Node.js,MongoDB经验教训: -我学习了如何使用Express和Node.js使我的应用在服务器端运行并创建使用身份验证。 我还学习了如何使用MondoDB创建数据库...
Spring 5 Webflux模板 此代码可用于使用微服务,React式编程,Web套接字,Rest,mongoDB,JWT(JSON Web令牌)和Netty构建下一代应用程序... 关于如何在Webflux堆栈中使用Spring Security的例子很少。 React性Oauth2支
使用Passport进行身份验证 使用Mongoose创建帐户和验证服务器。 CRUD界面,用于使用MongoDB创建帖子 用于帐户创建的客户验证,包括用于验证用户名是否可用的指令。 授权中间件,用于检查是否允许您编辑帖子。 ...
用户身份验证(JWT) 计划和食谱选择 当前交货信息 菜单浏览器 个别食谱页面/模式 用户个人资料 例子: 用户可以按照注册步骤选择订阅DailyRecipe。 这包括选择计划并提供帐单信息。 订阅的用户可以选择他们希望...
高级Dontpad-在线编辑,无需身份验证 在Heroku App上部署: : 例子: 特征 不登录,仅使用URL 不保存,任何更改都将自动保存 设置字体样式,字体系列,字体大小,颜色 格式化段落,标题,代码,对齐方式,列表...
打字稿演示版描述 Prisma客户端在脚本中的简单用法 简单的GraphQL服务器 具有电子邮件密码身份验证和权限的GraphQL服务器 带有实时订阅的GraphQL服务器 带有Express.JS的简单REST API 简单的gRPC API 使用MongoDB在...
:sparkles: :sparkles: Flask-GraphQL-Large-应用示例 :sparkles: :sparkles: 概要 这就是我用Flask + ... 基本身份验证示例 MongoDB示例 MySQL(SQLAlchemy,PeeWee)示例 项目依赖 GraphQL框架石墨烯 HTTP服务
它支持基本身份验证和cookie。 它是一个使用React,React-Bootstrap,Node.js,Express和MongoDB构建的同构应用程序。 演示版 入门 安装 注意:确保mongoDB已安装并正在运行。 第一的 $ git clone ...
验证用户身份并授予授权(权限)的服务。 资源服务 托管受保护资源并在资源访问期间验证访问令牌的服务。 1.2。 推荐服务认证流程 1.3。 用户管理服务的类图 2.电影服务的构建和运行 2.1。 设置开发环境 安装Golang...
身份验证和授权:JsonWebToken 短信系统:Twilio 开始使用 :warning: 这是一个个人项目,可以做出贡献,可以随时与作者联系,并要求在作者的授权下做出贡献,这个项目可以被分叉。 先决条件 在声明为该项目做贡献...
-我学习了如何使用Express和Node.js使我的应用在服务器端运行并创建使用身份验证。 我还学习了如何使用MondoDB创建数据库,并由此能够练习使用CRUD和rest api。 ##例子: -看一下我自己的投资组合中的以下几个...
OAuth 2用于社交身份验证。 我们使用JWT和HTML5本地存储来代替auth cookie。 艰巨的任务用于促进开发和测试。 MongoDB的持久性。 现场例子 以下是捆绑的演示应用程序(类似于Facebook的实时共享应用程序)的屏幕...