123456789_123456789_123456789_123456789_123456789_

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

Instance Attribute Summary

  • #logger readonly

    The logger for this authenticator.

  • #realm readonly

    The realm this authenticator covers.

  • #userdb readonly

    The user database for this authenticator.

Instance Method Summary

Instance Attribute Details

#logger (readonly)

The logger for this authenticator

[ GitHub ]

  
# File 'lib/webrick/httpauth/authenticator.rb', line 43

attr_reader :logger

#realm (readonly)

The realm this authenticator covers

[ GitHub ]

  
# File 'lib/webrick/httpauth/authenticator.rb', line 33

attr_reader :realm

#userdb (readonly)

The user database for this authenticator

[ GitHub ]

  
# 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

[ GitHub ]

  
# 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.

[ GitHub ]

  
# 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