Class: WEBrick::HTTPAuth::BasicAuth
- Inherits:
-
Object
- Object
- WEBrick::HTTPAuth::BasicAuth
- Includes:
- Authenticator
- Defined in:
- lib/webrick/httpauth/basicauth.rb
Direct Known Subclasses
Constant Summary collapse
- AuthScheme =
"Basic"
Constants included from Authenticator
Authenticator::AuthException, Authenticator::RequestField, Authenticator::ResponseField, Authenticator::ResponseInfoField
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
-
#userdb ⇒ Object
readonly
Returns the value of attribute userdb.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate(req, res) ⇒ Object
- #challenge(req, res) ⇒ Object
-
#initialize(config, default = Config::BasicAuth) ⇒ BasicAuth
constructor
A new instance of BasicAuth.
Constructor Details
#initialize(config, default = Config::BasicAuth) ⇒ BasicAuth
28 29 30 31 |
# File 'lib/webrick/httpauth/basicauth.rb', line 28 def initialize(config, default=Config::BasicAuth) check_init(config) @config = default.dup.update(config) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
26 27 28 |
# File 'lib/webrick/httpauth/basicauth.rb', line 26 def logger @logger end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
26 27 28 |
# File 'lib/webrick/httpauth/basicauth.rb', line 26 def realm @realm end |
#userdb ⇒ Object (readonly)
Returns the value of attribute userdb.
26 27 28 |
# File 'lib/webrick/httpauth/basicauth.rb', line 26 def userdb @userdb end |
Class Method Details
.make_passwd(realm, user, pass) ⇒ Object
21 22 23 24 |
# File 'lib/webrick/httpauth/basicauth.rb', line 21 def self.make_passwd(realm, user, pass) pass ||= "" pass.crypt(Utils::random_string(2)) end |
Instance Method Details
#authenticate(req, res) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/webrick/httpauth/basicauth.rb', line 33 def authenticate(req, res) unless basic_credentials = check_scheme(req) challenge(req, res) end userid, password = basic_credentials.unpack("m*")[0].split(":", 2) password ||= "" if userid.empty? error("user id was not given.") challenge(req, res) end unless encpass = @userdb.get_passwd(@realm, userid, @reload_db) error("%s: the user is not allowed.", userid) challenge(req, res) end if password.crypt(encpass) != encpass error("%s: password unmatch.", userid) challenge(req, res) end info("%s: authentication succeeded.", userid) req.user = userid end |
#challenge(req, res) ⇒ Object
55 56 57 58 |
# File 'lib/webrick/httpauth/basicauth.rb', line 55 def challenge(req, res) res[@response_field] = "#{@auth_scheme} realm=\"#{@realm}\"" raise @auth_exception end |