Commit bdea46e38c0c8943313cde461bd3867a16b8d825:
rough in HTTP authorization support
Branch: refs/heads/master
Author: Sam Ruby <[email protected]>
Committer: Sam Ruby <[email protected]>
Pusher: rubys <[email protected]>
------------------------------------------------------------
lib/whimsy/asf/ldap.rb | ++++++++++++ -
------------------------------------------------------------
25 changes: 24 additions, 1 deletions.
------------------------------------------------------------
diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index bd24245..7a270dc 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -2,6 +2,7 @@
require 'ldap'
require 'weakref'
require 'net/http'
+require 'base64'
module ASF
module LDAP
@@ -54,7 +55,6 @@ def self.connect
# test the connection
ldap.bind
- ldap.unbind rescue nil
# save the host
@host = host
@@ -256,6 +256,10 @@ def asf_member?
ASF::Member.status[name] or ASF.members.include? self
end
+ def asf_officer_or_member?
+ asf_member? or ASF.pmc_chairs.include? self
+ end
+
def asf_committer?
ASF::Group.new('committers').include? self
end
@@ -406,6 +410,25 @@ def self.bind(user, password, &block)
end
end
+ # validate HTTP authorization, and optionally invoke a block bound to
+ # that user.
+ def self.http_auth(string, &block)
+ auth = Base64.decode64(string[/Basic (.*)/, 1] || '')
+ user, password = auth.split(':', 2)
+ return unless password
+
+ if block
+ self.bind(user, password, &block)
+ else
+ begin
+ ASF::LDAP.bind(user, password) {}
+ return ASF::Person.new(user)
+ rescue ::LDAP::ResultError
+ return nil
+ end
+ end
+ end
+
# determine what LDAP hosts are available
def self.hosts
# try whimsy config