Exception: Mongo::Auth::Unauthorized

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/mongo/auth.rb

Overview

Raised when a user is not authorized on a database.

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(user, used_mechanism = nil) ⇒ Unauthorized

Instantiate the new error.

Examples:

Instantiate the error.

Mongo::Auth::Unauthorized.new(user)

Parameters:

  • user (Mongo::Auth::User)

    The unauthorized user.

  • used_mechanism (String) (defaults to: nil)

    Auth mechanism actually used for authentication. This is a full string like SCRAM-SHA-256.

Since:

  • 2.0.0



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/mongo/auth.rb', line 109

def initialize(user, used_mechanism = nil)
  specified_mechanism = if user.mechanism
    " (mechanism: #{user.mechanism})"
  else
    ''
  end
  used_mechanism = if used_mechanism
    " (used mechanism: #{used_mechanism})"
  else
    ''
  end
  msg = "User #{user.name}#{specified_mechanism} is not authorized to access #{user.database}#{used_mechanism}"
  super(msg)
end