class Origen::Users::LDAP

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)

Constants

BASE_DN
HOST
LDAP_ENCRYPTION
PORT
SERVICE_ACCOUNT
SERVICE_PASS

Public Instance Methods

available?() click to toggle source
# File lib/origen/users/ldap.rb, line 24
def available?
  !!(SERVICE_ACCOUNT && SERVICE_PASS && HOST && PORT && BASE_DN && LDAP_ENCRYPTION)
end
display(user_or_id = Origen.current_user) click to toggle source

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

# File lib/origen/users/ldap.rb, line 47
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) click to toggle source

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   # => stephen.mcginty@freescale.com
# File lib/origen/users/ldap.rb, line 36
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

Private Instance Methods

id(user_or_id) click to toggle source
# File lib/origen/users/ldap.rb, line 58
def id(user_or_id)
  user_or_id.respond_to?(:id) ? user_or_id.id : user_or_id
end
service() click to toggle source
# File lib/origen/users/ldap.rb, line 62
def service
  @service ||= Net::LDAP.new host:       HOST,
                             port:       PORT,
                             base:       BASE_DN,
                             encryption: LDAP_ENCRYPTION,
                             auth:       { method: :simple, username: SERVICE_ACCOUNT, password: SERVICE_PASS }
end