Skip to content

Instantly share code, notes, and snippets.

@fnichol
Created June 19, 2010 02:04
Show Gist options
  • Save fnichol/444486 to your computer and use it in GitHub Desktop.
Save fnichol/444486 to your computer and use it in GitHub Desktop.
Quick-and-dirty LDAP/local fallback auth for hudson
#!/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
@patrick1292
Copy link

This sounds interesting. But could you please elaborate on how to install this script in Hudson? I have no clue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment