User — Documentation by YARD 0.9.37 (original) (raw)
Class: Mongo::Auth::User
Inherits:
Object
- Object
- Mongo::Auth::User show all
Includes:
Defined in:
lib/mongo/auth/user.rb,
lib/mongo/auth/user/view.rb
Overview
Represents a user in MongoDB.
Defined Under Namespace
Classes: View
Constant Summary
Constants included from Loggable
Instance Attribute Summary collapse
- #auth_mech_properties ⇒ Hash readonly
The authentication mechanism properties. - #auth_source ⇒ String readonly
The authorization source, either a database or external name. - #database ⇒ String readonly
The database the user is created in. - #mechanism ⇒ Symbol readonly
The authorization mechanism. - #name ⇒ String readonly
The username. - #password ⇒ String readonly
The cleartext password. - #roles ⇒ Array readonly
Roles The user roles.
Instance Method Summarycollapse
- #==(other) ⇒ true, false
Determine if this user is equal to another. - #auth_key(nonce) ⇒ String
Get an authentication key for the user based on a nonce from the server. - #encoded_name ⇒ String
Get the UTF-8 encoded name with escaped special characters for use with SCRAM authorization. - #hash ⇒ String
Get the hash key for the user. - #hashed_password ⇒ String
Get the user’s hashed password for SCRAM-SHA-1. - #initialize(options) ⇒ User constructor
Create the new user. - #options ⇒ Object private
Loggable requires an options attribute. - #sasl_prepped_password ⇒ Object private
Get the user’s stringprepped password for SCRAM-SHA-256. - #spec ⇒ Hash
Get the specification for the user, used in creation.
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Constructor Details
#initialize(options) ⇒ User
| 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | # File 'lib/mongo/auth/user.rb', line 163 def initialize(options) @database = options[:database] || Database::ADMIN @auth_source = options[:auth_source] | | self.class.default_auth_source(options) @name = options[:user] @password = options[:password] | | options[:pwd] @mechanism = options[:auth_mech] if @mechanism unless @mechanism.is_a?(Symbol) if Lint.enabled? raise Error::LintError, "Auth mechanism #{@mechanism.inspect} must be specified as a symbol" else log_warn("Auth mechanism #{@mechanism.inspect} should be specified as a symbol") @mechanism = @mechanism.to_sym end end unless Auth::SOURCES.key?(@mechanism) raise InvalidMechanism.new(options[:auth_mech]) end end @auth_mech_properties = options[:auth_mech_properties] | | {} @roles = options[:roles] | | [] end | | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ---------- |
Instance Attribute Details
#auth_mech_properties ⇒ Hash
Returns The authentication mechanism properties.
37 38 39 | # File 'lib/mongo/auth/user.rb', line 37 def auth_mech_properties @auth_mech_properties end |
---|
#auth_source ⇒ String
Returns The authorization source, either a database or external name.
31 32 33 | # File 'lib/mongo/auth/user.rb', line 31 def auth_source @auth_source end |
---|
#database ⇒ String
Returns The database the user is created in.
34 35 36 | # File 'lib/mongo/auth/user.rb', line 34 def database @database end |
---|
#mechanism ⇒ Symbol
Returns The authorization mechanism.
40 41 42 | # File 'lib/mongo/auth/user.rb', line 40 def mechanism @mechanism end |
---|
#name ⇒ String
43 44 45 | # File 'lib/mongo/auth/user.rb', line 43 def name @name end |
---|
#password ⇒ String
Returns The cleartext password.
46 47 48 | # File 'lib/mongo/auth/user.rb', line 46 def password @password end |
---|
#roles ⇒ Array
Returns roles The user roles.
49 50 51 | # File 'lib/mongo/auth/user.rb', line 49 def roles @roles end |
---|
Instance Method Details
#==(other) ⇒ true, false
Determine if this user is equal to another.
69 70 71 72 | # File 'lib/mongo/auth/user.rb', line 69 def ==(other) return false unless other.is_a?(User) name == other.name && database == other.database && password == other.password end |
---|
#auth_key(nonce) ⇒ String
Get an authentication key for the user based on a nonce from the server.
85 86 87 | # File 'lib/mongo/auth/user.rb', line 85 def auth_key(nonce) Digest::MD5.hexdigest("#{nonce}#{name}#{hashed_password}") end |
---|
#encoded_name ⇒ String
Get the UTF-8 encoded name with escaped special characters for use with SCRAM authorization.
98 99 100 | # File 'lib/mongo/auth/user.rb', line 98 def encoded_name name.encode(BSON::UTF8).gsub('=','=3D').gsub(',','=2C') end |
---|
#hash ⇒ String
Get the hash key for the user.
110 111 112 | # File 'lib/mongo/auth/user.rb', line 110 def hash [ name, database, password ].hash end |
---|
#hashed_password ⇒ String
Get the user’s hashed password for SCRAM-SHA-1.
| 122 123 124 125 126 127 128 | # File 'lib/mongo/auth/user.rb', line 122 def hashed_password unless password raise Error::MissingPassword end @hashed_password ||= Digest::MD5.hexdigest("#{name}:mongo:#{password}").encode(BSON::UTF8) end | | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
#options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Loggable requires an options attribute. We don’t have any options hence provide this as a stub.
55 56 57 | # File 'lib/mongo/auth/user.rb', line 55 def options {} end |
---|
#sasl_prepped_password ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the user’s stringprepped password for SCRAM-SHA-256.
| 133 134 135 136 137 138 139 140 141 142 | # File 'lib/mongo/auth/user.rb', line 133 def sasl_prepped_password unless password raise Error::MissingPassword end @sasl_prepped_password ||= StringPrep.prepare(password, StringPrep::Profiles::SASL::MAPPINGS, StringPrep::Profiles::SASL::PROHIBITED, normalize: true, bidi: true).encode(BSON::UTF8) end | | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
#spec ⇒ Hash
Get the specification for the user, used in creation.
| 200 201 202 203 204 205 206 | # File 'lib/mongo/auth/user.rb', line 200 def spec {roles: roles}.tap do |spec| if password spec[:pwd] = password end end end | | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |