source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/webrick/httpauth.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 1.3 KB
Line 
1#
2# httpauth.rb -- HTTP access authentication
3#
4# Author: IPR -- Internet Programming with Ruby -- writers
5# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
6# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
7# reserved.
8#
9# $IPR: httpauth.rb,v 1.14 2003/07/22 19:20:42 gotoyuzo Exp $
10
11require 'webrick/httpauth/basicauth'
12require 'webrick/httpauth/digestauth'
13require 'webrick/httpauth/htpasswd'
14require 'webrick/httpauth/htdigest'
15require 'webrick/httpauth/htgroup'
16
17module WEBrick
18 module HTTPAuth
19 module_function
20
21 def _basic_auth(req, res, realm, req_field, res_field, err_type, block)
22 user = pass = nil
23 if /^Basic\s+(.*)/o =~ req[req_field]
24 userpass = $1
25 user, pass = userpass.unpack("m*")[0].split(":", 2)
26 end
27 if block.call(user, pass)
28 req.user = user
29 return
30 end
31 res[res_field] = "Basic realm=\"#{realm}\""
32 raise err_type
33 end
34
35 def basic_auth(req, res, realm, &block)
36 _basic_auth(req, res, realm, "Authorization", "WWW-Authenticate",
37 HTTPStatus::Unauthorized, block)
38 end
39
40 def proxy_basic_auth(req, res, realm, &block)
41 _basic_auth(req, res, realm, "Proxy-Authorization", "Proxy-Authenticate",
42 HTTPStatus::ProxyAuthenticationRequired, block)
43 end
44 end
45end
Note: See TracBrowser for help on using the repository browser.