Rails で LDAP 認証
やっとできたので備忘録
class HogeController < ApplicationController
before_filter :authenticate
...
def authenticate
authenticate_or_request_with_http_basic do |name, password|
ldap = Net::LDAP.new(:host=>‘hoge.fuga’, :port => 389, :base => ‘dc=hoge,dc=fuga)
username = name
filter = Net::LDAP::Filter.eq(’uid’, username)
ldap.search(:filter => filter) {|entry| username = entry.dn}
ldap.auth(username, password)
if ldap.bind
return
end
end
Add comment June 27th, 2009