Class: Cul::LDAP
- Inherits:
-
Net::LDAP
- Object
- Net::LDAP
- Cul::LDAP
- Defined in:
- lib/cul/ldap.rb,
lib/cul/ldap/version.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- CONFIG_FILENAME =
'cul_ldap.yml'
- CONFIG_DEFAULTS =
{ host: 'ldap.columbia.edu', port: '636', encryption: { method: :simple_tls, tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS } }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#find_by_name(name) ⇒ Cul::LDAP::Entry?
LDAP lookup based on name.
-
#find_by_uni(uni) ⇒ Cul::LDAP::Entry?
LDAP lookup based on UNI.
-
#initialize(options = {}) ⇒ LDAP
constructor
A new instance of LDAP.
-
#search(args = {}) ⇒ Object
Wrapper around Net::LDAP#search, converts Net::LDAP::Entry objects to Cul::LDAP::Entry objects.
Constructor Details
#initialize(options = {}) ⇒ LDAP
Returns a new instance of LDAP.
19 20 21 |
# File 'lib/cul/ldap.rb', line 19 def initialize( = {}) super(build_config()) # All keys have to be symbols. end |
Class Method Details
.version ⇒ Object
5 6 7 |
# File 'lib/cul/ldap/version.rb', line 5 def self.version IO.read("VERSION").strip end |
Instance Method Details
#find_by_name(name) ⇒ Cul::LDAP::Entry?
LDAP lookup based on name.
38 39 40 41 42 43 44 |
# File 'lib/cul/ldap.rb', line 38 def find_by_name(name) if name.include?(',') name = name.split(',').map(&:strip).reverse.join(" ") end entries = search(base: "ou=People,o=Columbia University, c=US", filter: Net::LDAP::Filter.eq("cn", name)) (entries.count == 1) ? entries.first : nil end |
#find_by_uni(uni) ⇒ Cul::LDAP::Entry?
LDAP lookup based on UNI. If record could not be found returns nil.
28 29 30 31 |
# File 'lib/cul/ldap.rb', line 28 def find_by_uni(uni) entries = search(base: "ou=People,o=Columbia University, c=US", filter: Net::LDAP::Filter.eq("uid", uni)) (entries.count == 1) ? entries.first : nil end |
#search(args = {}) ⇒ Object
Wrapper around Net::LDAP#search, converts Net::LDAP::Entry objects to Cul::LDAP::Entry objects.
48 49 50 51 52 53 54 |
# File 'lib/cul/ldap.rb', line 48 def search(args = {}) super(args).tap do |result| if result.is_a?(Array) result.map!{ |e| Cul::LDAP::Entry.new(e) } end end end |