Class: Origen::Users::LDAP

Inherits:
Object show all
Defined in:
lib/origen/users/ldap.rb

Overview

Interface to talk to a company’s LDAP-based employee directory, an instance of this class is available at Origen.ldap

This provides APIs to lookup public information about any user (email, phone number, etc)

Constant Summary collapse

SERVICE_ACCOUNT =
Origen.site_config.ldap_username
SERVICE_PASS =
Origen.site_config.ldap_password
HOST =
Origen.site_config.ldap_host
PORT =
Origen.site_config.ldap_port
BASE_DN =
Origen.site_config.ldap_base_dn

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/origen/users/ldap.rb', line 19

def available?
  !!(SERVICE_ACCOUNT && SERVICE_PASS && HOST && PORT && BASE_DN)
end

#display(user_or_id = Origen.current_user) ⇒ Object

Prints out the information available for the given core, this is useful to work out the name of the information that you want to pull from the object returned from lookup



42
43
44
45
46
47
48
49
# File 'lib/origen/users/ldap.rb', line 42

def display(user_or_id = Origen.current_user)
  lookup(user_or_id).each do |attribute, values|
    puts "   #{attribute}:"
    values.each do |value|
      puts "      --->#{value}"
    end
  end
end

#lookup(user_or_id = Origen.current_user) ⇒ Object

Lookup the given user in the core directory and return an object representing the user’s entry in the FSL application directory, run the display method from the console to see the field names and what information is available. The record for the given user will be cached the first time it is generated, so this method can be repeatedly called from the same thread without incurring a remote fetch each time.

entry = Origen.fsl.lookup("r49409")
entry.mail   # => [email protected]


31
32
33
34
35
36
37
38
# File 'lib/origen/users/ldap.rb', line 31

def lookup(user_or_id = Origen.current_user)
  id = id(user_or_id)
  unless instance_variable_defined?("@#{id.downcase}")
    record = service.search(base: BASE_DN, filter: "#{Origen.site_config.ldap_user_id_attribute || 'id'}=#{id}").first
    instance_variable_set("@#{id.downcase}", record)
  end
  instance_variable_get("@#{id.downcase}")
end