Class: Warden::Ldap::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/warden/ldap/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/warden/ldap/connection.rb', line 11

def initialize(options= {})
  @login = options.delete(:username)
  @password = options.delete(:password)

  options[:encryption] = config["ssl"].to_sym if config["ssl"]

  @ldap = Net::LDAP.new(options)
  @ldap.host = config["host"]
  @ldap.port = config["port"]
  @ldap.base = config["base"]

  @generic_credentials = config["generic_credentials"]
  @attribute = [config["attributes"]].flatten
end

Instance Attribute Details

#ldapObject (readonly)

Returns the value of attribute ldap.



6
7
8
# File 'lib/warden/ldap/connection.rb', line 6

def ldap
  @ldap
end

#loginObject (readonly)

Returns the value of attribute login.



6
7
8
# File 'lib/warden/ldap/connection.rb', line 6

def 
  @login
end

Instance Method Details

#authenticate!Object



45
46
47
48
49
50
# File 'lib/warden/ldap/connection.rb', line 45

def authenticate!
  if @password
    @ldap.auth(dn, @password)
    @ldap.bind
  end
end

#authenticated?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/warden/ldap/connection.rb', line 52

def authenticated?
  authenticate!
end

#authorized?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/warden/ldap/connection.rb', line 56

def authorized?
  logger.info("Authorizing user #{dn}")
  authenticated?
end

#ldap_param_value(param) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/warden/ldap/connection.rb', line 26

def ldap_param_value(param)
  ldap_entry = nil
  @ldap.search(:filter => ldap_username_filter) {|entry| ldap_entry = entry}

  if ldap_entry
    if ldap_entry[param]
      logger.info("Requested param #{param} has value #{ldap_entry.send(param)}")
      value = ldap_entry.send(param)
      value = value.first if value.is_a?(Array) and value.count == 1
    else
      logger.error("Requested param #{param} does not exist")
      value = nil
    end
  else
    logger.error("Requested ldap entry does not exist")
    value = nil
  end
end

#loggerObject



7
8
9
# File 'lib/warden/ldap/connection.rb', line 7

def logger
  Warden::Ldap.logger
end

#valid_login?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/warden/ldap/connection.rb', line 61

def valid_login?
  !.nil?
end