Class: WEBrick::HTTPAuth::SiteWidePassword

Inherits:
Object
  • Object
show all
Includes:
Authenticator, SoksUserCookie
Defined in:
lib/authenticators.rb

Constant Summary collapse

AuthScheme =
"Basic"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SoksUserCookie

#add_cookie, #username_from_cookie

Constructor Details

#initialize(password = "", realm = "editing") ⇒ SiteWidePassword

Returns a new instance of SiteWidePassword.



86
87
88
89
90
91
# File 'lib/authenticators.rb', line 86

def initialize( password = "", realm = "editing" )
  			config = { :UserDB => "nodb" , :Realm => realm }
		   check_init(config)
			@config = Config::BasicAuth.dup.update(config)
			@password = password
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



84
85
86
# File 'lib/authenticators.rb', line 84

def logger
  @logger
end

#realmObject (readonly)

Returns the value of attribute realm.



84
85
86
# File 'lib/authenticators.rb', line 84

def realm
  @realm
end

#userdbObject (readonly)

Returns the value of attribute userdb.



84
85
86
# File 'lib/authenticators.rb', line 84

def userdb
  @userdb
end

Instance Method Details

#authenticate(req, res) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/authenticators.rb', line 93

def authenticate(req, res)
  unless basic_credentials = check_scheme(req)
    challenge(req, res)
  end
  userid, password = Base64.decode64(basic_credentials).split(":", 2) 
  password ||= ""
  if userid.empty?
    error("user id was not given.")
    challenge(req, res)
  end
 
  if password != @password
    error("%s: password unmatch.", userid)
    challenge(req, res)
  end
  info("%s: authentication succeeded.", userid)
  req.user = userid
 	add_cookie(req,res)
		userid
end

#challenge(req, res) ⇒ Object

Raises:

  • (@auth_exception)


114
115
116
117
# File 'lib/authenticators.rb', line 114

def challenge(req, res)
  res[@response_field] = "#{@auth_scheme} realm=\"#{@realm}\""
  raise @auth_exception
end