diff options
Diffstat (limited to 'lib/webrick/httpauth/htgroup.rb')
-rw-r--r-- | lib/webrick/httpauth/htgroup.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/webrick/httpauth/htgroup.rb b/lib/webrick/httpauth/htgroup.rb index c9270c61cc..0ecabef820 100644 --- a/lib/webrick/httpauth/htgroup.rb +++ b/lib/webrick/httpauth/htgroup.rb @@ -11,7 +11,26 @@ require 'tempfile' module WEBrick module HTTPAuth + + ## + # Htgroup accesses apache-compatible group files. Htgroup can be used to + # provide group-based authentication for users. Currently Htgroup is not + # directly integrated with any authenticators in WEBrick. For security, + # the path for a digest password database should be stored outside of the + # paths available to the HTTP server. + # + # Example: + # + # htgroup = WEBrick::HTTPAuth::Htgroup.new 'my_group_file' + # htgroup.add 'superheroes', %w[spiderman batman] + # + # htgroup.members('superheroes').include? 'magneto' # => false + class Htgroup + + ## + # Open a group database at +path+ + def initialize(path) @path = path @mtime = Time.at(0) @@ -20,6 +39,9 @@ module WEBrick reload end + ## + # Reload groups from the database + def reload if (mtime = File::mtime(@path)) > @mtime @group.clear @@ -34,6 +56,10 @@ module WEBrick end end + ## + # Flush the group database. If +output+ is given the database will be + # written there instead of to the original path. + def flush(output=nil) output ||= @path tmp = Tempfile.new("htgroup", File::dirname(output)) @@ -48,11 +74,17 @@ module WEBrick end end + ## + # Retrieve the list of members from +group+ + def members(group) reload @group[group] || [] end + ## + # Add an Array of +members+ to +group+ + def add(group, members) @group[group] = members(group) | members end |