Object
# File lib/omniauth-ldap/adaptor.rb, line 36 def initialize(configuration={}) Adaptor.validate(configuration) @configuration = configuration.dup @configuration[:allow_anonymous] ||= false @logger = @configuration.delete(:logger) VALID_ADAPTER_CONFIGURATION_KEYS.each do |name| instance_variable_set("@#{name}", @configuration[name]) end method = ensure_method(@method) config = { :host => @host, :port => @port, :encryption => method, :base => @base } @uri = construct_uri(@host, @port, @method != :plain) @bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple) @auth = sasl_auths({:username => @bind_dn, :password => @password}).first if @bind_method == :sasl @auth ||= { :method => @bind_method, :username => @bind_dn, :password => @password } config[:auth] = @auth @connection = Net::LDAP.new(config) end
# File lib/omniauth-ldap/adaptor.rb, line 29 def self.validate(configuration={}) message = [] MUST_HAVE_KEYS.each do |name| message << name if configuration[name].nil? end raise ArgumentError.new(message.join(",") +" MUST be provided") unless message.empty? end
:base => “dc=yourcompany, dc=com”,
:filter => "(mail=#{user})", :password => psw
# File lib/omniauth-ldap/adaptor.rb, line 68 def bind_as(args = {}) result = false @connection.open do |me| rs = me.search args if rs and rs.first and dn = rs.first.dn password = args[:password] method = args[:method] || @method password = password.call if password.respond_to?(:call) if method == 'sasl' result = rs.first if me.bind(sasl_auths({:username => dn, :password => password}).first) else result = rs.first if me.bind(:method => :simple, :username => dn, :password => password) end end end result end
Generated with the Darkfish Rdoc Generator 2.