~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/webrick/httpauth/htgroup.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
module WEBrick
13
13
  module HTTPAuth
 
14
 
 
15
    ##
 
16
    # Htgroup accesses apache-compatible group files.  Htgroup can be used to
 
17
    # provide group-based authentication for users.  Currently Htgroup is not
 
18
    # directly integrated with any authenticators in WEBrick.  For security,
 
19
    # the path for a digest password database should be stored outside of the
 
20
    # paths available to the HTTP server.
 
21
    #
 
22
    # Example:
 
23
    #
 
24
    #   htgroup = WEBrick::HTTPAuth::Htgroup.new 'my_group_file'
 
25
    #   htgroup.add 'superheroes', %w[spiderman batman]
 
26
    #
 
27
    #   htgroup.members('superheroes').include? 'magneto' # => false
 
28
 
14
29
    class Htgroup
 
30
 
 
31
      ##
 
32
      # Open a group database at +path+
 
33
 
15
34
      def initialize(path)
16
35
        @path = path
17
36
        @mtime = Time.at(0)
20
39
        reload
21
40
      end
22
41
 
 
42
      ##
 
43
      # Reload groups from the database
 
44
 
23
45
      def reload
24
46
        if (mtime = File::mtime(@path)) > @mtime
25
47
          @group.clear
34
56
        end
35
57
      end
36
58
 
 
59
      ##
 
60
      # Flush the group database.  If +output+ is given the database will be
 
61
      # written there instead of to the original path.
 
62
 
37
63
      def flush(output=nil)
38
64
        output ||= @path
39
65
        tmp = Tempfile.new("htgroup", File::dirname(output))
48
74
        end
49
75
      end
50
76
 
 
77
      ##
 
78
      # Retrieve the list of members from +group+
 
79
 
51
80
      def members(group)
52
81
        reload
53
82
        @group[group] || []
54
83
      end
55
84
 
 
85
      ##
 
86
      # Add an Array of +members+ to +group+
 
87
 
56
88
      def add(group, members)
57
89
        @group[group] = members(group) | members
58
90
      end