Module providing generic support for both Digest and Basic authentication schemes.

Methods
C
E
I
L
Constants
RequestField = "Authorization"
 
ResponseField = "WWW-Authenticate"
 
ResponseInfoField = "Authentication-Info"
 
AuthException = HTTPStatus::Unauthorized
 
AuthScheme = nil
 

Method of authentication, must be overridden by the including class

Attributes
[R] logger

The logger for this authenticator

[R] realm

The realm this authenticator covers

[R] userdb

The user database for this authenticator

Instance Private methods
check_init(config)

Initializes the authenticator from config

# File ../ruby/lib/webrick/httpauth/authenticator.rb, line 49
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)

Ensures req has credentials that can be authenticated.

# File ../ruby/lib/webrick/httpauth/authenticator.rb, line 69
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)
# File ../ruby/lib/webrick/httpauth/authenticator.rb, line 88
def error(fmt, *args)
  if @logger.error?
    log(:error, fmt, *args)
  end
end
info(fmt, *args)
# File ../ruby/lib/webrick/httpauth/authenticator.rb, line 94
def info(fmt, *args)
  if @logger.info?
    log(:info, fmt, *args)
  end
end
log(meth, fmt, *args)
# File ../ruby/lib/webrick/httpauth/authenticator.rb, line 82
def log(meth, fmt, *args)
  msg = format("%s %s: ", @auth_scheme, @realm)
  msg << fmt % args
  @logger.send(meth, msg)
end