Class: WEBrick::HTTPAuth::SiteWidePassword
- Inherits:
-
Object
- Object
- WEBrick::HTTPAuth::SiteWidePassword
- Includes:
- Authenticator, SoksUserCookie
- Defined in:
- lib/authenticators.rb
Constant Summary collapse
- AuthScheme =
"Basic"
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.
Instance Method Summary collapse
- #authenticate(req, res) ⇒ Object
- #challenge(req, res) ⇒ Object
-
#initialize(password = "", realm = "editing") ⇒ SiteWidePassword
constructor
A new instance of SiteWidePassword.
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
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
84 85 86 |
# File 'lib/authenticators.rb', line 84 def logger @logger end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
84 85 86 |
# File 'lib/authenticators.rb', line 84 def realm @realm end |
#userdb ⇒ Object (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 (req,res) userid end |
#challenge(req, res) ⇒ Object
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 |