Ruby with LDAP or AD [closed]
Want to improve th开发者_如何学编程is question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this questionIs there a way of deciding and confirming with facts regarding, which is better and easier to integrate with Ruby. LDAP or ActiveDirectory?
I use the net-ldap gem to authenticate and query the ActiveDirectory server at work. It works well. Here's some sample code for verifying a user's login credentials and getting their full name.
def name_for_login( email, password )
email = email[/\A\w+/].downcase # Throw out the domain, if it was there
email << "@mycompany.com" # I only check people in my company
ldap = Net::LDAP.new(
host: 'ldap.mycompany.com', # Thankfully this is a standard name
auth: { method: :simple, email: email, password:password }
)
if ldap.bind
# Yay, the login credentials were valid!
# Get the user's full name and return it
ldap.search(
base: "OU=Users,OU=Accounts,DC=mycompany,DC=com",
filter: Net::LDAP::Filter.eq( "mail", email ),
attributes: %w[ displayName ],
return_result:true
).first.displayName.first
end
end
ActiveDirectory is an implementation of the LDAP. You can use the RubyLDAP gem to integrate with AD. I am currently using this gem to connect from a RHEL server to a Windows Domain Controller.
gem install ruby-ldap
The LDAP bindings for Ruby are pretty decent -- not exactly beautiful, but they work well. And, of course, you can access ActiveDirectory as an LDAP server. I have never tried any ActiveDirectory bindings for Ruby.
精彩评论