📅  最后修改于: 2023-12-03 14:47:08.592000             🧑  作者: Mango
Ruby LDAP is a Ruby programming language library that allows interaction with LDAP (Lightweight Directory Access Protocol) servers. It provides a convenient way to perform LDAP operations such as searching, adding, modifying, and deleting entries in LDAP directories.
To install Ruby LDAP, you can use the following command:
gem install ruby-ldap
Make sure you have Ruby and RubyGems installed before running the above command.
Here is a simple example demonstrating how to perform a basic LDAP search using Ruby LDAP:
require 'ldap'
ldap = LDAP::Conn.new('ldap.example.com', 389)
ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
ldap.set_option(LDAP::LDAP_OPT_TIMELIMIT, 10)
ldap.bind('cn=admin,dc=example,dc=com', 'password')
ldap.search('dc=example, dc=com', LDAP::LDAP_SCOPE_SUBTREE, '(&(objectClass=person)(sn=Smith))') do |entry|
puts "DN: #{entry.dn}"
entry.each_attribute do |attr, values|
puts "#{attr}: #{values.join(', ')}"
end
end
ldap.unbind
This example connects to an LDAP server, performs a search operation to find entries of people with the last name "Smith" within the "dc=example, dc=com" subtree, and prints the retrieved entries' Distinguished Names (DNs) along with their attributes.
For more details and advanced usage, refer to the Ruby LDAP documentation.
Ruby LDAP is a powerful library that allows you to interact with LDAP servers using the Ruby programming language. It simplifies LDAP operations and provides essential features for managing LDAP directories. Get started with Ruby LDAP today and leverage the power of LDAP in your Ruby applications!
Note: Ruby LDAP relies on native LDAP libraries to be installed on your system. Make sure to install the necessary LDAP client libraries before using Ruby LDAP.
Happy LDAP programming with Ruby!