Class: Mongo::Auth::User
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
::Mongo::Loggable
|
|
Inherits: | Object |
Defined in: | lib/mongo/auth/user.rb, lib/mongo/auth/user/view.rb |
Overview
Represents a user in MongoDB.
Constant Summary
::Mongo::Loggable
- Included
Class Method Summary
-
.new(options) ⇒ User
constructor
Create the new user.
-
.default_auth_source(options)
private
Internal use only
Internal use only
Generate default auth source based on the
::Mongo::URI
and options.
Instance Attribute Summary
- #auth_mech_properties ⇒ Hash readonly
- #auth_source ⇒ String readonly
- #database ⇒ String readonly
- #mechanism ⇒ Symbol readonly
- #name ⇒ String readonly
- #password ⇒ String readonly
- #roles ⇒ Array<String> readonly
Instance Method Summary
-
#==(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.
-
#options
Internal use only
Internal use only
::Mongo::Loggable
requires an options attribute. -
#sasl_prepped_password
Internal use only
Internal use only
Get the user’s stringprepped password for SCRAM-SHA-256.
-
#spec ⇒ Hash
Get the specification for the user, used in creation.
::Mongo::Loggable
- Included
#log_debug | Convenience method to log debug messages with the standard prefix. |
#log_error | Convenience method to log error messages with the standard prefix. |
#log_fatal | Convenience method to log fatal messages with the standard prefix. |
#log_info | Convenience method to log info messages with the standard prefix. |
#log_warn | Convenience method to log warn messages with the standard prefix. |
#logger | Get the logger instance. |
#_mongo_log_prefix, #format_message |
Constructor Details
.new(options) ⇒ User
Create the new user.
# File 'lib/mongo/auth/user.rb', line 163
def initialize( ) @database = [:database] || Database::ADMIN @auth_source = [:auth_source] || self.class.default_auth_source( ) @name = [:user] @password = [:password] || [:pwd] @mechanism = [:auth_mech] if @mechanism # Since the driver must select an authentication class for # the specified mechanism, mechanisms that the driver does not # know about, and cannot translate to an authentication class, # need to be rejected. unless @mechanism.is_a?(Symbol) # Although we documented auth_mech option as being a symbol, we # have not enforced this; warn, reject in lint mode 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( [:auth_mech]) end end @auth_mech_properties = [:auth_mech_properties] || {} @roles = [:roles] || [] end
Class Method Details
.default_auth_source(options) (private)
Generate default auth source based on the ::Mongo::URI
and options
Instance Attribute Details
#auth_mech_properties ⇒ Hash
(readonly)
# File 'lib/mongo/auth/user.rb', line 37
attr_reader :auth_mech_properties
#auth_source ⇒ String
(readonly)
# File 'lib/mongo/auth/user.rb', line 31
attr_reader :auth_source
#database ⇒ String
(readonly)
# File 'lib/mongo/auth/user.rb', line 34
attr_reader :database
#mechanism ⇒ Symbol (readonly)
# File 'lib/mongo/auth/user.rb', line 40
attr_reader :mechanism
#name ⇒ String
(readonly)
# File 'lib/mongo/auth/user.rb', line 43
attr_reader :name
#password ⇒ String
(readonly)
# File 'lib/mongo/auth/user.rb', line 46
attr_reader :password
#roles ⇒ Array
<String
> (readonly)
# File 'lib/mongo/auth/user.rb', line 49
attr_reader :roles
Instance Method Details
#==(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.
# 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.
# 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.
#hashed_password ⇒ String
Get the user’s hashed password for SCRAM-SHA-1.
# 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
::Mongo::Loggable
requires an options attribute. We don’t have any options hence provide this as a stub.
# File 'lib/mongo/auth/user.rb', line 55
def {} end
#sasl_prepped_password
Get the user’s stringprepped password for SCRAM-SHA-256.
# 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.