类:Mongo::Auth::User
- 继承:
-
对象
- 对象
- Mongo::Auth::User
- 包括:
- Loggable
- 定义于:
- lib/ Mongo/auth/user.rb 、
lib/ Mongo/auth/user/view.rb
Overview
代表MongoDB中的用户。
在命名空间下定义
类: 查看
常量摘要
Loggable中包含的常量
实例属性摘要折叠
-
# auth_mech_properties ⇒ 哈希
只读
身份验证机制属性。
-
# auth_source ⇒ string
只读
授权源,可以是数据库或外部名称。
-
#database ⇒ String
只读
在其中创建用户的数据库。
-
#机制⇒ 符号
只读
授权机制。
-
#名称⇒ string
只读
用户名。
-
#密码⇒ string
只读
明文密码。
-
# roles ⇒ Array<String>
只读
角色 用户角色。
类方法摘要折叠
-
。default_auth_source (options) ⇒ 对象
private
根据 URI 和选项生成默认身份验证源。
实例方法摘要折叠
-
# == (other) ⇒ true, false
确定此用户是否与另一个用户相同。
-
# auth_key (nonce) ⇒ string
根据服务器的随机数获取用户的身份验证密钥。
-
# Encoded_name ⇒ string
获取带有转义特殊字符的 UTF- 8编码名称,以用于SCRAM授权。
-
#哈希⇒ string
获取用户的哈希键。
-
# hashed_password ⇒ string
获取用户的SCRAM -SHA-1哈希密码。
-
#initialize (options) ⇒ 用户
构造函数
创建新用户。
-
# options ⇒ 对象
private
Loggable 需要一个选项属性。
-
# sasl_prepped_password ⇒ 对象
private
获取适用于SCRAM-SHA-256 的用户字符串准备好的密码。
-
# spec ⇒ 哈希
获取创建时使用的用户规范。
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
构造函数详情
#initialize (options) ⇒用户
创建新用户。
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ Mongo/auth/user.rb', line 158 def 初始化() @database = [:database] || Database::ADMIN @auth_source = [:auth_source] || self.class.default_auth_source() @name = [: user] @password = [:password] || [:pwd] @chanism = [:auth_mech] if @chanism # 由于驱动程序必须选择身份验证类 # 指定的机制,驱动程序没有的机制 # 了解,但无法转换为身份验证类, # 需要被拒绝。 除非 @chanism.is_a?(符号) # 虽然我们将 auth_mech 选项记录为一个符号,但我们 # 尚未强制执行此操作;在 lint模式警告、拒绝 if Lint.已启用? 提高 错误::LintError, " Auth Mechanism #{ @ Mechanism . Inspect }必须指定为符号" end log_warn(" Auth Mechanism #{ @ Mechanism . Inspect }应指定为符号") @chanism = @chanism.to_sym end 提高 InvalidMechanism.new([:auth_mech]) 除非 auth::来源.键?(@chanism) end @auth_mech_properties = [:auth_mech_properties] || {} @roles = [:roles] || [] end |
实例属性详细信息
# auth_mech_properties ⇒哈希(只读)
返回身份验证机制属性。
35 36 37 |
# File 'lib/ Mongo/auth/user.rb', line 35 def auth_mech_properties @auth_mech_properties end |
# auth_source ⇒ string (只读)
返回 授权源,可以是数据库或外部名称。
29 30 31 |
# File 'lib/ Mongo/auth/user.rb', line 29 def auth_source @auth_source end |
#数据库⇒ string (只读)
返回创建用户的数据库。
32 33 34 |
# File 'lib/ Mongo/auth/user.rb', line 32 def database @database end |
# name ⇒ string (readonly)
返回 用户名。
41 42 43 |
# File 'lib/ Mongo/auth/user.rb', line 41 def 名称 @name end |
#密码⇒ string (只读)
返回 明文密码。
44 45 46 |
# File 'lib/ Mongo/auth/user.rb', line 44 def 密码 @password end |
# roles ⇒ Array<String> (只读)
返回角色 用户角色。
47 48 49 |
# File 'lib/ Mongo/auth/user.rb', line 47 def 角色 @roles end |
类方法详细信息
。default_auth_source (options) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
根据 URI 和选项生成默认身份验证源
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/ Mongo/auth/user.rb', line 203 def self.default_auth_source() 案例 [:auth_mech] when :aws, :gssapi, :mongodb_x 509 ' $external ' when :plain [:database] || ' $external ' else [:database] || Database::ADMIN end end |
实例方法详细信息
# == (other) ⇒ true , false
确定此用户是否与另一个用户相同。
67 68 69 70 71 |
# File 'lib/ Mongo/auth/user.rb', line 67 def ==(其他) return false 除非 其他.is_a?(user) 名称 == 其他.名称 && database == 其他.database && 密码 == 其他.密码 end |
# auth_key (nonce) ⇒ string
根据服务器的随机数获取用户的身份验证密钥。
84 85 86 |
# File 'lib/ Mongo/auth/user.rb', line 84 def auth_key(随机数) 摘要::MD5.hexdigest(" #{ nonce } #{ name } #{ hashed_password } ") end |
# Encoded_name ⇒ string
获取带有转义特殊字符的 UTF- 8编码名称,以用于SCRAM授权。
97 98 99 |
# File 'lib/ Mongo/auth/user.rb', line 97 def Encoded_name 名称.encode(BSON::UTF8).gsub(' = ', '=3D').gsub(' , ', ' = 2 C ') end |
#哈希⇒ string
获取用户的哈希键。
109 110 111 |
# File 'lib/ Mongo/auth/user.rb', line 109 def 哈希 [ 名称, database, 密码 ].哈希 end |
# hashed_password ⇒ string
获取用户的SCRAM -SHA-1哈希密码。
121 122 123 124 125 |
# File 'lib/ Mongo/auth/user.rb', line 121 def hashed_password 提高 错误::MissingPassword 除非 密码 @hashed_password ||= 摘要::MD5.hexdigest(" #{ name } : Mongo: #{ password } ").encode(BSON::UTF8) end |
# options ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
Loggable 需要一个选项属性。我们没有任何选项,因此将其作为存根提供。
53 54 55 |
# File 'lib/ Mongo/auth/user.rb', line 53 def {} end |
# sasl_prepped_password ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取适用于SCRAM-SHA-256 的用户字符串准备好的密码。
130 131 132 133 134 135 136 137 |
# File 'lib/ Mongo/auth/user.rb', line 130 def sasl_prepped_password 提高 错误::MissingPassword 除非 密码 @sasl_prepped_password ||= StringPrep.准备(密码, StringPrep::个人资料::sasl::mappings, StringPrep::个人资料::sasl::禁止, 规范化: true, bidi: true).encode(BSON::UTF8) end |
# spec ⇒哈希
获取创建时使用的用户规范。
194 195 196 197 198 |
# File 'lib/ Mongo/auth/user.rb', line 194 def spec { 角色: 角色 }.点击 do |spec| spec[:pwd] = 密码 if 密码 end end |