Created
June 19, 2010 02:04
-
-
Save fnichol/444486 to your computer and use it in GitHub Desktop.
Quick-and-dirty LDAP/local fallback auth for hudson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "net/ldap" | |
require "csv" | |
unless ARGV[0] && ARGV[1] | |
puts "Usage: #{__FILE__} <username> <password>" | |
abort | |
end | |
user = ARGV[0] | |
pass = ARGV[1] | |
# check local accounts setup in accounts.csv first | |
# useful for local or non-person accounts like git/hg in a post commit trigger | |
CSV.open(File.join(File.dirname(__FILE__), 'accounts.csv'), 'r') do |a| | |
if user == a[0] && pass == a[1] | |
puts "User #{user} authenticated successfully" | |
exit | |
end | |
end | |
# if no local accounts were successful, then fallback to ldap, sql, pam, etc. | |
# here's an ldap example | |
ldap = Net::LDAP.new :host => "ldap.example.com", :port => 389, | |
:auth => { | |
:method => :simple, | |
:username => "cn=#{user},ou=staff,o=example", | |
:password => pass | |
} | |
if ldap.bind | |
puts "User #{user} authenticated successfully" | |
exit | |
else | |
puts "User #{user} failed to authenticate" | |
abort | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sounds interesting. But could you please elaborate on how to install this script in Hudson? I have no clue.