# File lib/opennebula/ldap_auth.rb, line 23 def initialize(options) @options={ :host => 'localhost', :port => 389, :user => nil, :password => nil, :base => nil, :auth_method => :simple, :user_field => 'cn', :user_group_field => 'dn', :group_field => 'member' }.merge(options) ops={} if @options[:user] ops[:auth] = { :method => @options[:auth_method], :username => @options[:user], :password => @options[:password] } end ops[:host]=@options[:host] if @options[:host] ops[:port]=@options[:port].to_i if @options[:port] ops[:encryption]=@options[:encryption] if @options[:encryption] @ldap=Net::LDAP.new(ops) end
# File lib/opennebula/ldap_auth.rb, line 87 def authenticate(user, password) ldap=@ldap.clone auth={ :method => @options[:auth_method], :username => user, :password => password } if ldap.bind(auth) true else false end end
# File lib/opennebula/ldap_auth.rb, line 53 def find_user(name) begin result=@ldap.search( :base => @options[:base], :filter => "#{@options[:user_field]}=#{name}") if result && result.first [result.first.dn, result.first[@options[:user_group_field]]] else result=@ldap.search(:base => name) if result && result.first [name, result.first[@options[:user_group_field]]] else [nil, nil] end end rescue [nil, nil] end end
Generated with the Darkfish Rdoc Generator 2.