Module: WEBrick::HTTPAuth::Authenticator
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/webrick/httpauth/authenticator.rb |
Overview
Module providing generic support for both Digest and Basic authentication schemes.
Constant Summary
-
AuthException =
Internal use only
# File 'lib/webrick/httpauth/authenticator.rb', line 23HTTPStatus::Unauthorized
-
AuthScheme =
Method of authentication, must be overridden by the including class
nil
-
RequestField =
Internal use only
# File 'lib/webrick/httpauth/authenticator.rb', line 20"Authorization"
-
ResponseField =
Internal use only
# File 'lib/webrick/httpauth/authenticator.rb', line 21"WWW-Authenticate"
-
ResponseInfoField =
Internal use only
# File 'lib/webrick/httpauth/authenticator.rb', line 22"Authentication-Info"
Instance Attribute Summary
Instance Method Summary
-
#check_init(config)
private
Internal use only
Initializes the authenticator from
config
-
#check_scheme(req)
private
Internal use only
Ensures
req
has credentials that can be authenticated. - #error(fmt, *args) private Internal use only
- #info(fmt, *args) private Internal use only
- #log(meth, fmt, *args) private Internal use only
Instance Attribute Details
#logger (readonly)
The logger for this authenticator
# File 'lib/webrick/httpauth/authenticator.rb', line 43
attr_reader :logger
#realm (readonly)
The realm this authenticator covers
# File 'lib/webrick/httpauth/authenticator.rb', line 33
attr_reader :realm
#userdb (readonly)
The user database for this authenticator
# File 'lib/webrick/httpauth/authenticator.rb', line 38
attr_reader :userdb
Instance Method Details
#check_init(config) (private)
This method is for internal use only.
Initializes the authenticator from config
# File 'lib/webrick/httpauth/authenticator.rb', line 52
def check_init(config) [:UserDB, :Realm].each{|sym| unless config[sym] raise ArgumentError, "Argument #{sym.inspect} missing." end } @realm = config[:Realm] @userdb = config[:UserDB] @logger = config[:Logger] || Log::new($stderr) @reload_db = config[:AutoReloadUserDB] @request_field = self::class::RequestField @response_field = self::class::ResponseField @resp_info_field = self::class::ResponseInfoField @auth_exception = self::class::AuthException @auth_scheme = self::class::AuthScheme end
#check_scheme(req) (private)
This method is for internal use only.
Ensures req
has credentials that can be authenticated.
# File 'lib/webrick/httpauth/authenticator.rb', line 72
def check_scheme(req) unless credentials = req[@request_field] error("no credentials in the request.") return nil end unless match = /^#{@auth_scheme}\s+/i.match(credentials) error("invalid scheme in %s.", credentials) info("%s: %s", @request_field, credentials) if $DEBUG return nil end return match.post_match end
#error(fmt, *args) (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/webrick/httpauth/authenticator.rb', line 91
def error(fmt, *args) if @logger.error? log(:error, fmt, *args) end end
#info(fmt, *args) (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/webrick/httpauth/authenticator.rb', line 97
def info(fmt, *args) if @logger.info? log(:info, fmt, *args) end end
#log(meth, fmt, *args) (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/webrick/httpauth/authenticator.rb', line 85
def log(meth, fmt, *args) msg = format("%s %s: ", @auth_scheme, @realm) msg << fmt % args @logger.send(meth, msg) end