Ruby与LDAP或AD

3
有没有一种方法可以通过事实来决定和确认,哪个更好并且更容易与Ruby集成。LDAP还是ActiveDirectory?
3个回答

4

我使用net-ldap宝石来验证和查询工作中的ActiveDirectory服务器。 它运行良好。下面是一些示例代码,用于验证用户的登录凭据并获取其全名。

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

3

ActiveDirectory是LDAP的一种实现。您可以使用RubyLDAP gem与AD集成。我目前正在使用这个gem从RHEL服务器连接到Windows域控制器。

gem install ruby-ldap

嗨jamin,我正在使用ruby-ldap,并在rails3应用程序中遇到了问题,你能否请看一下这个问题?http://stackoverflow.com/questions/11979920/ruby-ldap-gem-not-work-in-rails3-app-but-work-in-rails-console - Jinzhao Huo

1

Ruby的LDAP绑定相当不错--虽然不是非常美观,但它们工作得很好。当然,你也可以将ActiveDirectory作为LDAP服务器访问。我从未尝试过任何Ruby的ActiveDirectory绑定。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接