Ruby with LDAP or AD [closed]

2019-05-14 04:47发布

Is there a way of deciding and confirming with facts regarding, which is better and easier to integrate with Ruby. LDAP or ActiveDirectory?

标签: ruby ldap
3条回答
Melony?
2楼-- · 2019-05-14 05:18

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
查看更多
三岁会撩人
3楼-- · 2019-05-14 05:27

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.

查看更多
放荡不羁爱自由
4楼-- · 2019-05-14 05:30

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
查看更多
登录 后发表回答