Class: Kennedy::Backends::LDAP

Inherits:
Object
  • Object
show all
Defined in:
lib/kennedy/backends/ldap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ LDAP

Creates a new LDAP auth backend with the given arguments

Parameters:

  • args (Hash) (defaults to: {})

    The arguments to construct the backend with

Options Hash (args):

  • :host (String)

    The LDAP server host to connect to

  • :auth (Hash)

    The auth method ruby-net-ldap should use

  • :base (String)

    The treebase to check against



11
12
13
14
15
16
# File 'lib/kennedy/backends/ldap.rb', line 11

def initialize(args = {})
  @host = args[:host] || raise(ArgumentError, "Host must be given as :host")
  @auth = args[:auth] || raise(ArgumentError, "Auth must be given as :auth")
  @base = args[:base] || raise(ArgumentError, "Base must be given as :base")
  @filter = lambda { raise(ArgumentError, "Set a filter block on this object using the 'filter' writer") }
end

Instance Attribute Details

#filter=(value) ⇒ Object (writeonly)

Sets the attribute filter

Parameters:

  • value

    the value to set the attribute filter to.



4
5
6
# File 'lib/kennedy/backends/ldap.rb', line 4

def filter=(value)
  @filter = value
end

Instance Method Details

#authenticate(identifier, password) ⇒ true, false

Authenticates the given credentials against LDAP

Parameters:

  • identifier (String)

    The identifier to filter on

  • password (String)

    The password to use

Returns:

  • (true, false)

    A boolean indicating authentication success



22
23
24
25
# File 'lib/kennedy/backends/ldap.rb', line 22

def authenticate(identifier, password)
  filter_string = @filter.call(identifier)
  !!ldap_conn.bind_as(:filter => filter_string, :password => password)
end