Description
This module is to be used for anonymous lookup of user attributes in the MCommunity service provide at the University of Michigan. It can be easily modifed to use other LDAP server configurations.
Try it out
Requirements:
- Ruby at least 2.0.0
- Gem 'net-ldap' ~> '0.17.0'
The Net::LDAP (aka net-ldap) gem before 0.16.0 for Ruby has a Missing SSL Certificate Validation.
To try the module out:
- Clone the repo
- Edit the configurations by opening ldaptest.rb and set the CONFIGURATION BLOCK to your environment.
LdapLookup.configuration do |config| config.host = < your host > # "ldap.umich.edu" config.port = < your port > # "986" the default is set to "389" so this optional config.base = < your LDAP base > # "dc=umich,dc=edu" config.dept_attribute = < your dept attribute > # "umichPostalAddressData" config.group_attribute = < your group email attribute > # "umichGroupEmail" end
- run the ldaptest.rb script
ruby ./ldaptest.rb
Installation
Add this line to your application's Gemfile:
gem 'ldap_lookup'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ldap_lookup
In your application create a file config/initializers/ldap_lookup.rb
LdapLookup.configuration do |config| config.host = < your host > # "ldap.umich.edu" config.port = < your port > # "954" port 389 is set by default config.base = < your LDAP base > # "dc=umich,dc=edu" config.dept_attribute = < your dept attribute > # "umichPostalAddressData" config.group_attribute = < your group email attribute > # "umichGroupEmail" end
Methods available
uid_exist?: returns true if uid is in LDAP
LdapLookup.uid_exist?(uniqname)
response: true or false (boolean)
get_simple_name: returns the Display Name
LdapLookup.get_simple_name(uniqname = nil)
response: name or "No #{attribute} found for #{uniqname}"
get_dept: returns the users Department_name
LdapLookup.get_dept(uniqname = nil)
response: dept name or "No #{nested_attribute} found for #{uniqname}"
get_email: returns the users email address
LdapLookup.get_email(uniqname = nil)
response: email or "No #{attribute} found for #{uniqname}"
is_member_of_group?: returns true/false if uniqname is a member of the specified group
LdapLookup.is_member_of_group?(uid = nil, group_name = nil)
response: true or false (boolean)
get_email_distribution_list: Returns the list of emails that are associated to a group.
LdapLookup.get_email_distribution_list(group_name = nil)
response: result_hash
all_groups_for_user: Returns the list of groups that a user is a member of.
LdapLookup.all_groups_for_user(uniqname = nil)
response: result_array
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/rsmoke/ldap_lookup. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the LdapLookup project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.