Class: Mongo::Auth::User
- Inherits:
-
Object
- Object
- Mongo::Auth::User
- Defined in:
- lib/mongo/auth/user.rb,
lib/mongo/auth/user/view.rb
Overview
Represents a user in MongoDB.
Defined Under Namespace
Classes: View
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<String>
readonly
Roles The user roles.
Instance Method Summary collapse
-
#==(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.
-
#initialize(options) ⇒ User
constructor
Create the new user.
- #sasl_prepped_hashed_password ⇒ Object
-
#spec ⇒ Hash
Get the specification for the user, used in creation.
Constructor Details
#initialize(options) ⇒ User
Create the new user.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mongo/auth/user.rb', line 137 def initialize() @database = [:database] || Database::ADMIN @auth_source = [:auth_source] || @database @name = [:user] @password = [:password] || [:pwd] @mechanism = [:auth_mech] @auth_mech_properties = [:auth_mech_properties] || {} @roles = [:roles] || [] @client_key = [:client_key] end |
Instance Attribute Details
#auth_mech_properties ⇒ Hash (readonly)
Returns The authentication mechanism properties.
33 34 35 |
# File 'lib/mongo/auth/user.rb', line 33 def auth_mech_properties @auth_mech_properties end |
#auth_source ⇒ String (readonly)
Returns The authorization source, either a database or external name.
27 28 29 |
# File 'lib/mongo/auth/user.rb', line 27 def auth_source @auth_source end |
#database ⇒ String (readonly)
Returns The database the user is created in.
30 31 32 |
# File 'lib/mongo/auth/user.rb', line 30 def database @database end |
#mechanism ⇒ Symbol (readonly)
Returns The authorization mechanism.
36 37 38 |
# File 'lib/mongo/auth/user.rb', line 36 def mechanism @mechanism end |
#name ⇒ String (readonly)
Returns The username.
39 40 41 |
# File 'lib/mongo/auth/user.rb', line 39 def name @name end |
#password ⇒ String (readonly)
Returns The cleartext password.
42 43 44 |
# File 'lib/mongo/auth/user.rb', line 42 def password @password end |
#roles ⇒ Array<String> (readonly)
Returns roles The user roles.
45 46 47 |
# File 'lib/mongo/auth/user.rb', line 45 def roles @roles end |
Instance Method Details
#==(other) ⇒ true, false
Determine if this user is equal to another.
57 58 59 60 |
# File 'lib/mongo/auth/user.rb', line 57 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.
73 74 75 |
# File 'lib/mongo/auth/user.rb', line 73 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.
86 87 88 |
# File 'lib/mongo/auth/user.rb', line 86 def encoded_name name.encode(BSON::UTF8).gsub('=','=3D').gsub(',','=2C') end |
#hash ⇒ String
Get the hash key for the user.
98 99 100 |
# File 'lib/mongo/auth/user.rb', line 98 def hash [ name, database, password ].hash end |
#hashed_password ⇒ String
Get the user’s hashed password.
110 111 112 |
# File 'lib/mongo/auth/user.rb', line 110 def hashed_password @hashed_password ||= Digest::MD5.hexdigest("#{name}:mongo:#{password}").encode(BSON::UTF8) end |
#sasl_prepped_hashed_password ⇒ Object
114 115 116 |
# File 'lib/mongo/auth/user.rb', line 114 def sasl_prepped_hashed_password @sasl_prepped_hashed_password ||= sasl_prepped_password.encode(BSON::UTF8) end |
#spec ⇒ Hash
Get the specification for the user, used in creation.
156 157 158 |
# File 'lib/mongo/auth/user.rb', line 156 def spec { pwd: password, roles: roles } end |